32 #ifndef CPL_STRING_H_INCLUDED
33 #define CPL_STRING_H_INCLUDED
63 char CPL_DLL **CSLAddString(
char **papszStrList,
64 const char *pszNewString) CPL_WARN_UNUSED_RESULT;
65 char CPL_DLL **CSLAddStringMayFail(
66 char **papszStrList,
const char *pszNewString) CPL_WARN_UNUSED_RESULT;
68 int CPL_DLL
CSLCount(
const char *
const *papszStrList);
70 int CPL_DLL
CSLCount(
char **papszStrList);
72 const char CPL_DLL *CSLGetField(
char **,
int );
73 void CPL_DLL CPL_STDCALL
CSLDestroy(
char **papszStrList);
74 char CPL_DLL **
CSLDuplicate(
char **papszStrList) CPL_WARN_UNUSED_RESULT;
75 char CPL_DLL **
CSLMerge(
char **papszOrig,
76 char **papszOverride ) CPL_WARN_UNUSED_RESULT;
78 char CPL_DLL **CSLTokenizeString(
const char *pszString ) CPL_WARN_UNUSED_RESULT;
79 char CPL_DLL **CSLTokenizeStringComplex(
80 const char *pszString,
const char *pszDelimiter,
int bHonourStrings,
81 int bAllowEmptyTokens ) CPL_WARN_UNUSED_RESULT;
83 const char *pszDelimiter,
84 int nCSLTFlags ) CPL_WARN_UNUSED_RESULT;
86 #define CSLT_HONOURSTRINGS 0x0001
87 #define CSLT_ALLOWEMPTYTOKENS 0x0002
88 #define CSLT_PRESERVEQUOTES 0x0004
89 #define CSLT_PRESERVEESCAPES 0x0008
90 #define CSLT_STRIPLEADSPACES 0x0010
91 #define CSLT_STRIPENDSPACES 0x0020
93 int CPL_DLL CSLPrint(
char **papszStrList, FILE *fpOut);
94 char CPL_DLL **
CSLLoad(
const char *pszFname) CPL_WARN_UNUSED_RESULT;
95 char CPL_DLL **
CSLLoad2(
const char *pszFname,
int nMaxLines,
int nMaxCols,
96 char** papszOptions) CPL_WARN_UNUSED_RESULT;
97 int CPL_DLL CSLSave(
char **papszStrList,
const char *pszFname);
99 char CPL_DLL **CSLInsertStrings(
char **papszStrList,
int nInsertAtLineNo,
100 char **papszNewLines) CPL_WARN_UNUSED_RESULT;
101 char CPL_DLL **CSLInsertString(
char **papszStrList,
int nInsertAtLineNo,
102 const char *pszNewLine) CPL_WARN_UNUSED_RESULT;
103 char CPL_DLL **CSLRemoveStrings(
104 char **papszStrList,
int nFirstLineToDelete,
105 int nNumToRemove,
char ***ppapszRetStrings) CPL_WARN_UNUSED_RESULT;
109 const char * pszNeedle );
110 int CPL_DLL
CSLFindName(
char **papszStrList,
const char *pszName);
111 int CPL_DLL CSLFetchBoolean(
char **papszStrList,
const char *pszKey,
119 #ifdef DO_NOT_USE_DEBUG_BOOL
120 #define CPLTestBool(x) CPL_TO_BOOL(CPLTestBoolean(x))
131 bool CPL_DLL CPLFetchBool(
const char **papszStrList,
const char *pszKey,
138 CSLFetchNameValue(
char **papszStrList,
const char *pszName);
140 CSLFetchNameValueDef(
char **papszStrList,
const char *pszName,
141 const char *pszDefault );
143 CSLFetchNameValueMultiple(
char **papszStrList,
const char *pszName);
145 CSLAddNameValue(
char **papszStrList,
147 const char *pszValue) CPL_WARN_UNUSED_RESULT;
151 const char *pszValue) CPL_WARN_UNUSED_RESULT;
153 const char *pszSeparator );
157 #define CPLES_BackslashQuotable 0
162 #define CPLES_XML_BUT_QUOTES 5
165 int nScheme ) CPL_WARN_UNUSED_RESULT;
167 int nScheme ) CPL_WARN_UNUSED_RESULT;
170 const GByte *pabyData ) CPL_WARN_UNUSED_RESULT;
171 GByte CPL_DLL *CPLHexToBinary(
const char *pszHex,
172 int *pnBytes ) CPL_WARN_UNUSED_RESULT;
174 char CPL_DLL *CPLBase64Encode(
int nBytes,
175 const GByte *pabyData ) CPL_WARN_UNUSED_RESULT;
176 int CPL_DLL CPLBase64DecodeInPlace( GByte* pszBase64 );
187 size_t CPL_DLL
CPLStrlcpy(
char* pszDest,
const char* pszSrc,
size_t nDestSize);
188 size_t CPL_DLL
CPLStrlcat(
char* pszDest,
const char* pszSrc,
size_t nDestSize);
189 size_t CPL_DLL
CPLStrnlen(
const char *pszStr,
size_t nMaxLen);
194 int CPL_DLL
CPLvsnprintf(
char *str,
size_t size,
const char* fmt,
195 va_list args) CPL_PRINT_FUNC_FORMAT (3, 0);
197 const char* fmt, ...) CPL_PRINT_FUNC_FORMAT(3,4);
198 #if defined(GDAL_COMPILATION) && !defined(DONT_DEPRECATE_SPRINTF)
199 int CPL_DLL
CPLsprintf(
char *str,
const char* fmt, ...)
200 CPL_PRINT_FUNC_FORMAT(2, 3) CPL_WARN_DEPRECATED("Use
CPLsnprintf instead");
202 int CPL_DLL
CPLsprintf(
char *str,
const char* fmt, ...)
203 CPL_PRINT_FUNC_FORMAT(2, 3);
205 int CPL_DLL
CPLprintf(
const char* fmt, ...) CPL_PRINT_FUNC_FORMAT(1, 2);
207 int CPL_DLL CPLsscanf(const
char* str, const
char* fmt, ...)
208 CPL_SCAN_FUNC_FORMAT(2, 3);
210 const
char CPL_DLL *CPLSPrintf(const
char *fmt, ...)
211 CPL_PRINT_FUNC_FORMAT(1, 2) CPL_WARN_UNUSED_RESULT;
212 char CPL_DLL **CSLAppendPrintf(
char **papszStrList, const
char *fmt, ...)
213 CPL_PRINT_FUNC_FORMAT(2, 3) CPL_WARN_UNUSED_RESULT;
214 int CPL_DLL CPLVASPrintf(
char **buf, const
char *fmt, va_list args )
215 CPL_PRINT_FUNC_FORMAT(2, 0);
220 #define CPL_ENC_LOCALE ""
221 #define CPL_ENC_UTF8 "UTF-8"
222 #define CPL_ENC_UTF16 "UTF-16"
223 #define CPL_ENC_UCS2 "UCS-2"
224 #define CPL_ENC_UCS4 "UCS-4"
225 #define CPL_ENC_ASCII "ASCII"
226 #define CPL_ENC_ISO8859_1 "ISO-8859-1"
229 void CPL_DLL CPLClearRecodeWarningFlags(
void );
231 const char *pszSource,
const char *pszSrcEncoding,
232 const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
234 const wchar_t *pwszSource,
const char *pszSrcEncoding,
235 const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
237 const char *pszSource,
const char *pszSrcEncoding,
238 const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
239 int CPL_DLL
CPLIsUTF8(
const char* pabyData,
int nLen);
241 const char* pabyData,
int nLen,
242 char chReplacementChar) CPL_WARN_UNUSED_RESULT;
251 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
268 #if defined(_MSC_VER)
269 # if (_MSC_VER <= 1202)
270 # define MSVC_OLD_STUPID_BEHAVIOUR
275 #ifdef MSVC_OLD_STUPID_BEHAVIOUR
277 # define gdal_std_string string
279 # define gdal_std_string std::string
288 CPLString(
const std::string &oStr ) : gdal_std_string( oStr ) {}
289 CPLString(
const char *pszStr ) : gdal_std_string( pszStr ) {}
291 operator const char* (void)
const {
return c_str(); }
293 char& operator[](std::string::size_type i)
295 return gdal_std_string::operator[](i);
298 const char& operator[](std::string::size_type i)
const
300 return gdal_std_string::operator[](i);
303 char& operator[](
int i)
305 return gdal_std_string::operator[](
306 static_cast<std::string::size_type>(i));
309 const char& operator[](
int i)
const
311 return gdal_std_string::operator[](
312 static_cast<std::string::size_type>(i));
315 void Clear() { resize(0); }
318 void Seize(
char *pszValue)
320 if (pszValue == NULL )
332 const char *pszFormat, ... ) CPL_PRINT_FUNC_FORMAT (2, 3);
334 const char *pszFormat, va_list args ) CPL_PRINT_FUNC_FORMAT(2, 0);
335 CPLString &FormatC(
double dfValue,
const char *pszFormat = NULL );
337 CPLString &Recode(
const char *pszSrcEncoding,
const char *pszDstEncoding );
340 size_t ifind(
const std::string & str,
size_t pos = 0 )
const;
341 size_t ifind(
const char * s,
size_t pos = 0 )
const;
346 CPLString CPLOPrintf(
const char *pszFormat, ... ) CPL_PRINT_FUNC_FORMAT (1, 2);
348 const
char *pszFormat, va_list args) CPL_PRINT_FUNC_FORMAT (1, 0);
355 const
char* pszValue);
366 mutable int nAllocation;
371 void MakeOurOwnCopy();
372 void EnsureAllocation(
int nMaxLength );
373 int FindSortedInsertionPoint(
const char *pszLine );
377 CPLStringList(
char **papszList,
int bTakeOwnership=TRUE );
378 CPLStringList(
const CPLStringList& oOther );
381 CPLStringList &Clear();
383 int size()
const {
return Count(); }
386 CPLStringList &AddString(
const char *pszNewString );
387 CPLStringList &AddStringDirectly(
char *pszNewString );
389 CPLStringList &
InsertString(
int nInsertAtLineNo,
const char *pszNewLine )
390 {
return InsertStringDirectly( nInsertAtLineNo,
CPLStrdup(pszNewLine) ); }
391 CPLStringList &InsertStringDirectly(
int nInsertAtLineNo,
char *pszNewLine);
396 int FindString(
const char *pszTarget )
const
398 int PartialFindString(
const char *pszNeedle )
const
401 int FindName(
const char *pszName )
const;
402 bool FetchBool(
const char *pszKey,
bool bDefault )
const;
404 int FetchBoolean(
const char *pszKey,
int bDefault )
const;
405 const char *FetchNameValue(
const char *pszKey )
const;
406 const char *FetchNameValueDef(
407 const char *pszKey,
const char *pszDefault )
const;
408 CPLStringList &AddNameValue(
const char *pszKey,
const char *pszValue );
409 CPLStringList &SetNameValue(
const char *pszKey,
const char *pszValue );
411 CPLStringList &Assign(
char **papszListIn,
int bTakeOwnership=TRUE );
412 CPLStringList &operator=(
char **papszListIn) {
413 return Assign( papszListIn, TRUE ); }
414 CPLStringList &operator=(
const CPLStringList& oOther);
416 char * operator[](
int i);
417 char * operator[](
size_t i) {
return (*
this)[
static_cast<int>(i)]; }
418 const char * operator[](
int i)
const;
419 const char * operator[](
size_t i)
const {
420 return (*
this)[
static_cast<int>(i)]; }
422 char **List() {
return papszList; }
425 CPLStringList &Sort();
426 int IsSorted()
const {
return bIsSorted; }
428 operator char**(void) {
return List(); }
char ** CSLDuplicate(char **papszStrList) CPL_WARN_UNUSED_RESULT
Clone a string list.
Definition: cpl_string.cpp:214
int CPLEncodingCharSize(const char *pszEncoding)
Return bytes per character for encoding.
Definition: cpl_recode.cpp:309
size_t CPLStrlcat(char *pszDest, const char *pszSrc, size_t nDestSize)
Appends a source string to a destination buffer.
Definition: cpl_string.cpp:2698
int CSLTestBoolean(const char *pszValue)
Test what boolean value contained in the string.
Definition: cpl_string.cpp:1515
char * CPLForceToASCII(const char *pabyData, int nLen, char chReplacementChar) CPL_WARN_UNUSED_RESULT
Return a new string that is made only of ASCII characters.
Definition: cpl_recode.cpp:267
char * CPLRecode(const char *pszSource, const char *pszSrcEncoding, const char *pszDstEncoding) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL
Convert a string from a source encoding to a destination encoding.
Definition: cpl_recode.cpp:74
CPLString CPLURLGetValue(const char *pszURL, const char *pszKey)
Return the value matching a key from a key=value pair in a URL.
Definition: cplstring.cpp:336
char ** CSLSetNameValue(char **papszStrList, const char *pszName, const char *pszValue) CPL_WARN_UNUSED_RESULT
Assign value to name in StringList.
Definition: cpl_string.cpp:1831
int CSLFindName(char **papszStrList, const char *pszName)
Find StringList entry with given key name.
Definition: cpl_string.cpp:1666
Convenient string class based on std::string.
Definition: cpl_string.h:283
size_t CPLStrlcpy(char *pszDest, const char *pszSrc, size_t nDestSize)
Copy source string to a destination buffer.
Definition: cpl_string.cpp:2641
char * CPLStrdup(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL
Safe version of strdup() function.
Definition: cpl_conv.cpp:261
char * CPLEscapeString(const char *pszString, int nLength, int nScheme) CPL_WARN_UNUSED_RESULT
Apply escaping to string to preserve special characters.
Definition: cpl_string.cpp:1982
int CSLPartialFindString(char **papszHaystack, const char *pszNeedle)
Find a substring within a string list.
Definition: cpl_string.cpp:716
void CSLSetNameValueSeparator(char **papszStrList, const char *pszSeparator)
Replace the default separator (":" or "=") with the passed separator in the given name/value list...
Definition: cpl_string.cpp:1910
char ** CSLLoad2(const char *pszFname, int nMaxLines, int nMaxCols, char **papszOptions) CPL_WARN_UNUSED_RESULT
Load a text file into a string list.
Definition: cpl_string.cpp:299
CPL error handling services.
int CPLprintf(const char *fmt,...)
printf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1358
char ** CSLLoad(const char *pszFname) CPL_WARN_UNUSED_RESULT
Load a text file into a string list.
Definition: cpl_string.cpp:379
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:362
char * CPLBinaryToHex(int nBytes, const GByte *pabyData) CPL_WARN_UNUSED_RESULT
Binary to hexadecimal translation.
Definition: cpl_string.cpp:2414
char * CPLRecodeFromWChar(const wchar_t *pwszSource, const char *pszSrcEncoding, const char *pszDstEncoding) CPL_WARN_UNUSED_RESULT
Convert wchar_t string to UTF-8.
Definition: cpl_recode.cpp:142
int CPLsprintf(char *str, const char *fmt,...)
sprintf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1332
CPLValueType CPLGetValueType(const char *pszValue)
Detect the type of the value contained in a string, whether it is a real, an integer or a string Lead...
Definition: cpl_string.cpp:2510
Various convenience functions for CPL.
int CPLsnprintf(char *str, size_t size, const char *fmt,...)
snprintf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1305
int CPLvsnprintf(char *str, size_t size, const char *fmt, va_list args)
vsnprintf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1124
int CPLTestBoolean(const char *pszValue)
Test what boolean value contained in the string.
Definition: cpl_string.cpp:1537
size_t CPLStrnlen(const char *pszStr, size_t nMaxLen)
Returns the length of a NUL terminated string by reading at most the specified number of bytes...
Definition: cpl_string.cpp:2733
int CSLFindStringCaseSensitive(char **, const char *)
Find a string within a string list(case sensitive)
Definition: cpl_string.cpp:684
char ** CSLMerge(char **papszOrig, char **papszOverride) CPL_WARN_UNUSED_RESULT
Merge two lists.
Definition: cpl_string.cpp:254
CPLStringList & InsertString(int nInsertAtLineNo, const char *pszNewLine)
Insert into the list at identified location.
Definition: cpl_string.h:389
CPLString CPLURLAddKVP(const char *pszURL, const char *pszKey, const char *pszValue)
Return a new URL with a new key=value pair.
Definition: cplstring.cpp:369
char ** CSLTokenizeString2(const char *pszString, const char *pszDelimiter, int nCSLTFlags) CPL_WARN_UNUSED_RESULT
Tokenize a string.
Definition: cpl_string.cpp:814
bool CPLTestBool(const char *pszValue)
Test what boolean value contained in the string.
Definition: cpl_string.cpp:1488
const char * CPLParseNameValue(const char *pszNameValue, char **ppszKey)
Parse NAME=VALUE string into name and value components.
Definition: cpl_string.cpp:1712
int CSLCount(const char *const *papszStrList)
Return number of items in a string list.
Definition: cpl_string.cpp:134
void CSLDestroy(char **papszStrList)
Free string list.
Definition: cpl_string.cpp:186
int CPLIsUTF8(const char *pabyData, int nLen)
Test if a string is encoded as UTF-8.
Definition: cpl_recode.cpp:243
char * CPLUnescapeString(const char *pszString, int *pnLength, int nScheme) CPL_WARN_UNUSED_RESULT
Unescape a string.
Definition: cpl_string.cpp:2198
wchar_t * CPLRecodeToWChar(const char *pszSource, const char *pszSrcEncoding, const char *pszDstEncoding) CPL_WARN_UNUSED_RESULT
Convert UTF-8 string to a wchar_t string.
Definition: cpl_recode.cpp:200
char ** CSLParseCommandLine(const char *pszCommandLine)
Tokenize command line arguments in a list of strings.
Definition: cpl_string.cpp:2757
int CPLStrlenUTF8(const char *pszUTF8Str)
Return the number of UTF-8 characters of a nul-terminated string.
Definition: cpl_recode.cpp:355
int CSLFindString(char **, const char *)
Find a string within a string list (case insensitive).
Definition: cpl_string.cpp:650