32 #ifndef CPL_STRING_H_INCLUDED
33 #define CPL_STRING_H_INCLUDED
68 int CPL_DLL
CSLCount(
const char *
const *papszStrList);
70 int CPL_DLL
CSLCount(
char **papszStrList);
73 void CPL_DLL CPL_STDCALL
CSLDestroy(
char **papszStrList);
75 char CPL_DLL **
CSLMerge(
char **papszOrig,
80 const char *pszString,
const char *pszDelimiter,
int bHonourStrings,
83 const char *pszDelimiter,
87 #define CSLT_HONOURSTRINGS 0x0001
89 #define CSLT_ALLOWEMPTYTOKENS 0x0002
91 #define CSLT_PRESERVEQUOTES 0x0004
93 #define CSLT_PRESERVEESCAPES 0x0008
95 #define CSLT_STRIPLEADSPACES 0x0010
97 #define CSLT_STRIPENDSPACES 0x0020
99 int CPL_DLL
CSLPrint(
char **papszStrList, FILE *fpOut);
103 const char *pszFname,
int nMaxLines,
int nMaxCols,
107 const char *pszFname,
int nMaxLines,
int nMaxCols,
110 int CPL_DLL
CSLSave(
char **papszStrList,
const char *pszFname);
114 char CPL_DLL **
CSLInsertString(
char **papszStrList,
int nInsertAtLineNo,
117 char **papszStrList,
int nFirstLineToDelete,
121 const char *pszTarget );
123 const char *pszTarget );
125 const char *pszNeedle );
129 int CPL_DLL
CSLFindString(
char **papszList,
const char *pszTarget );
131 const char *pszTarget );
133 const char *pszNeedle );
135 int CPL_DLL
CSLFindName(
char **papszStrList,
const char *pszName);
145 #ifdef DO_NOT_USE_DEBUG_BOOL
146 #define CPLTestBool(x) CPL_TO_BOOL(CPLTestBoolean(x))
147 #define CPLFetchBool(list,key,default) \
148 CPL_TO_BOOL(CSLFetchBoolean(list,key,default))
155 bool CPL_DLL
CPLFetchBool(
const char *
const *papszStrList,
const char *pszKey,
172 const char *pszDefault );
179 const char *pszDefault );
193 const char *pszSeparator );
198 #define CPLES_BackslashQuotable 0
208 #define CPLES_XML_BUT_QUOTES 5
234 size_t CPL_DLL
CPLStrlcpy(
char* pszDest,
const char* pszSrc,
size_t nDestSize);
235 size_t CPL_DLL
CPLStrlcat(
char* pszDest,
const char* pszSrc,
size_t nDestSize);
236 size_t CPL_DLL
CPLStrnlen(
const char *pszStr,
size_t nMaxLen);
248 #if defined(ALIAS_CPLSNPRINTF_AS_SNPRINTF)
249 #define CPLsnprintf snprintf
257 #if defined(GDAL_COMPILATION) && !defined(DONT_DEPRECATE_SPRINTF)
272 int CPL_DLL CPLsscanf( const
char* str,
281 CPL_PRINT_FUNC_FORMAT(2, 3) CPL_WARN_UNUSED_RESULT;
284 CPL_PRINT_FUNC_FORMAT(2, 0);
290 #define CPL_ENC_LOCALE ""
292 #define CPL_ENC_UTF8 "UTF-8"
294 #define CPL_ENC_UTF16 "UTF-16"
296 #define CPL_ENC_UCS2 "UCS-2"
298 #define CPL_ENC_UCS4 "UCS-4"
300 #define CPL_ENC_ASCII "ASCII"
302 #define CPL_ENC_ISO8859_1 "ISO-8859-1"
306 void CPL_DLL CPLClearRecodeWarningFlags(
void );
309 const char *pszSource,
const char *pszSrcEncoding,
312 const wchar_t *pwszSource,
const char *pszSrcEncoding,
315 const char *pszSource,
const char *pszSrcEncoding,
317 int CPL_DLL
CPLIsUTF8(
const char* pabyData,
int nLen );
319 const char* pabyData,
int nLen,
329 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
346 CPLString(
const std::string &oStr ) : std::string( oStr ) {}
349 CPLString(
const char *pszStr ) : std::string( pszStr ) {}
351 CPLString(
const char *pszStr,
size_t n ) : std::string( pszStr, n ) {}
354 operator const char* (void)
const {
return c_str(); }
359 return std::string::operator[](i);
365 return std::string::operator[](i);
371 return std::string::operator[](
372 static_cast<std::string::size_type>(i));
378 return std::string::operator[](
379 static_cast<std::string::size_type>(i));
385 const char&
back()
const {
return operator[](size()-1); }
387 char&
back() {
return operator[](size()-1); }
398 if (pszValue == NULL )
411 CPL_PRINT_FUNC_FORMAT (2, 3);
414 CPL_PRINT_FUNC_FORMAT(2, 0);
415 CPLString &FormatC(
double dfValue, const
char *pszFormat = NULL );
417 CPLString &Recode( const
char *pszSrcEncoding, const
char *pszDstEncoding );
419 const std::
string &osBefore, const std::
string& osAfter );
420 CPLString &replaceAll( const std::
string &osBefore,
char chAfter );
421 CPLString &replaceAll(
char chBefore, const std::
string &osAfter );
422 CPLString &replaceAll(
char chBefore,
char chAfter );
425 size_t ifind( const std::
string & str,
size_t pos = 0 ) const;
426 size_t ifind( const
char * s,
size_t pos = 0 ) const;
432 CPL_PRINT_FUNC_FORMAT (1, 2);
435 CPL_PRINT_FUNC_FORMAT (1, 0);
442 const
char* pszValue);
453 mutable int nAllocation;
458 void MakeOurOwnCopy();
459 void EnsureAllocation(
int nMaxLength );
460 int FindSortedInsertionPoint(
const char *pszLine );
464 CPLStringList(
char **papszList,
int bTakeOwnership=TRUE );
465 CPLStringList(
const CPLStringList& oOther );
468 CPLStringList &Clear();
471 int size()
const {
return Count(); }
475 bool empty()
const {
return Count() == 0; }
477 CPLStringList &AddString(
const char *pszNewString );
478 CPLStringList &AddStringDirectly(
char *pszNewString );
480 CPLStringList &
InsertString(
int nInsertAtLineNo,
const char *pszNewLine )
481 {
return InsertStringDirectly( nInsertAtLineNo,
CPLStrdup(pszNewLine) ); }
482 CPLStringList &InsertStringDirectly(
int nInsertAtLineNo,
char *pszNewLine);
494 int FindName(
const char *pszName )
const;
495 bool FetchBool(
const char *pszKey,
bool bDefault )
const;
497 int FetchBoolean(
const char *pszKey,
int bDefault )
const;
498 const char *FetchNameValue(
const char *pszKey )
const;
499 const char *FetchNameValueDef(
500 const char *pszKey,
const char *pszDefault )
const;
501 CPLStringList &AddNameValue(
const char *pszKey,
const char *pszValue );
502 CPLStringList &SetNameValue(
const char *pszKey,
const char *pszValue );
504 CPLStringList &Assign(
char **papszListIn,
int bTakeOwnership=TRUE );
507 return Assign( papszListIn, TRUE ); }
509 CPLStringList &operator=(
const CPLStringList& oOther);
512 char * operator[](
int i);
514 char *
operator[](
size_t i) {
return (*
this)[
static_cast<int>(i)]; }
516 const char * operator[](
int i)
const;
519 return (*
this)[
static_cast<int>(i)]; }
522 char **
List() {
return papszList; }
525 CPLStringList &Sort();
530 operator char**(void) {
return List(); }
CPLString(void)
Constructor.
Definition: cpl_string.h:343
char ** CSLDuplicate(char **papszStrList) CPL_WARN_UNUSED_RESULT
Clone a string list.
Definition: cpl_string.cpp:224
int CPLEncodingCharSize(const char *pszEncoding)
Return bytes per character for encoding.
Definition: cpl_recode.cpp:318
char * CPLBase64Encode(int nBytes, const GByte *pabyData) CPL_WARN_UNUSED_RESULT
Base64 encode a buffer.
Definition: cpl_base64.cpp:199
size_t CPLStrlcat(char *pszDest, const char *pszSrc, size_t nDestSize)
Appends a source string to a destination buffer.
Definition: cpl_string.cpp:2726
char ** CSLTokenizeString(const char *pszString) CPL_WARN_UNUSED_RESULT
Tokenizes a string and returns a StringList with one string for each token.
Definition: cpl_string.cpp:753
int CSLTestBoolean(const char *pszValue)
Test what boolean value contained in the string.
Definition: cpl_string.cpp:1545
bool empty() const
Return whether the list is empty.
Definition: cpl_string.h:475
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:352
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:276
void Clear()
Clear the string.
Definition: cpl_string.h:391
GByte * CPLHexToBinary(const char *pszHex, int *pnBytes) CPL_WARN_UNUSED_RESULT
Hexadecimal to binary translation.
Definition: cpl_string.cpp:2498
int CSLPartialFindString(const char *const *papszHaystack, const char *pszNeedle)
Find a substring within a string list.
Definition: cpl_string.cpp:731
char & back()
Return last character (undefined behaviour if string is empty)
Definition: cpl_string.h:387
CPLString CPLOPrintf(const char *pszFormat,...)
Return a CPLString with the content of sprintf()
Definition: cplstring.cpp:484
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:81
char ** CSLLoad2(const char *pszFname, int nMaxLines, int nMaxCols, const char *const *papszOptions) CPL_WARN_UNUSED_RESULT
Load a text file into a string list.
Definition: cpl_string.cpp:312
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:401
const char * CPLSPrintf(const char *fmt,...) CPL_WARN_UNUSED_RESULT
CPLSPrintf() that works with 10 static buffer.
Definition: cpl_string.cpp:971
char ** CSLAppendPrintf(char **papszStrList, const char *fmt,...) CPL_WARN_UNUSED_RESULT
Use CPLSPrintf() to append a new line at the end of a StringList.
Definition: cpl_string.cpp:1023
CPLValueType
Type of value.
Definition: cpl_string.h:225
Real number.
Definition: cpl_string.h:228
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:207
char ** CSLSetNameValue(char **papszStrList, const char *pszName, const char *pszValue) CPL_WARN_UNUSED_RESULT
Assign value to name in StringList.
Definition: cpl_string.cpp:1869
int CSLFindName(char **papszStrList, const char *pszName)
Find StringList entry with given key name.
Definition: cpl_string.cpp:1700
int FindString(const char *pszTarget) const
Return index of pszTarget in the list, or -1.
Definition: cpl_string.h:488
char ** CSLAddString(char **papszStrList, const char *pszNewString) CPL_WARN_UNUSED_RESULT
Append a string to a StringList and return a pointer to the modified StringList.
Definition: cpl_string.cpp:79
char ** CSLInsertString(char **papszStrList, int nInsertAtLineNo, const char *pszNewLine) CPL_WARN_UNUSED_RESULT
Insert a string at a given line number inside a StringList.
Definition: cpl_string.cpp:556
char & operator[](int i)
Return character at specified index.
Definition: cpl_string.h:369
int PartialFindString(const char *pszNeedle) const
Return index of pszTarget in the list (using partial search), or -1.
Definition: cpl_string.h:491
Convenient string class based on std::string.
Definition: cpl_string.h:338
char ** CSLAddNameValue(char **papszStrList, const char *pszName, const char *pszValue) CPL_WARN_UNUSED_RESULT
Add a new entry to a StringList of "Name=Value" pairs, ("Name:Value" pairs are also supported for bac...
Definition: cpl_string.cpp:1830
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition: cpl_port.h:967
size_t CPLStrlcpy(char *pszDest, const char *pszSrc, size_t nDestSize)
Copy source string to a destination buffer.
Definition: cpl_string.cpp:2669
char * CPLStrdup(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL
Safe version of strdup() function.
Definition: cpl_conv.cpp:284
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:2014
int IsSorted() const
Returns whether the list is sorted.
Definition: cpl_string.h:527
int CSLFindString(const char *const *papszList, const char *pszTarget)
Find a string within a string list (case insensitive).
Definition: cpl_string.cpp:664
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:1942
CPL error handling services.
int CPLprintf(const char *fmt,...)
printf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1385
CPLStringList & operator=(char **papszListIn)
Assignment operator.
Definition: cpl_string.h:506
void Seize(char *pszValue)
Assign specified string and take ownership of it (assumed to be allocated with CPLMalloc()).
Definition: cpl_string.h:396
char ** CSLLoad(const char *pszFname) CPL_WARN_UNUSED_RESULT
Load a text file into a string list.
Definition: cpl_string.cpp:393
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:449
char * CPLBinaryToHex(int nBytes, const GByte *pabyData) CPL_WARN_UNUSED_RESULT
Binary to hexadecimal translation.
Definition: cpl_string.cpp:2440
int CSLSave(char **papszStrList, const char *pszFname)
Write a StringList to a text file.
Definition: cpl_string.cpp:408
char ** CSLAddStringMayFail(char **papszStrList, const char *pszNewString) CPL_WARN_UNUSED_RESULT
Same as CSLAddString() but may return NULL in case of (memory) failure.
Definition: cpl_string.cpp:88
int CSLFindStringCaseSensitive(const char *const *papszList, const char *pszTarget)
Find a string within a string list(case sensitive)
Definition: cpl_string.cpp:698
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:149
#define CPLFree
Alias of VSIFree()
Definition: cpl_conv.h:81
int size() const
Return size of list.
Definition: cpl_string.h:471
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:2537
Various convenience functions for CPL.
const char * CSLFetchNameValueDef(const char *const *papszStrList, const char *pszName, const char *pszDefault)
Same as CSLFetchNameValue() but return pszDefault in case of no match.
Definition: cpl_string.cpp:1638
int CSLPrint(char **papszStrList, FILE *fpOut)
Print a StringList to fpOut.
Definition: cpl_string.cpp:457
int CPLsnprintf(char *str, size_t size, const char *fmt,...)
snprintf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1329
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:1133
int CPLTestBoolean(const char *pszValue)
Test what boolean value contained in the string.
Definition: cpl_string.cpp:1567
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:2761
char ** CSLMerge(char **papszOrig, char **papszOverride) CPL_WARN_UNUSED_RESULT
Merge two lists.
Definition: cpl_string.cpp:264
const char * operator[](size_t i) const
Return string at specified index.
Definition: cpl_string.h:518
int CPLVASPrintf(char **buf, const char *fmt, va_list args)
This is intended to serve as an easy to use C callable vasprintf() alternative.
Definition: cpl_string.cpp:1042
int CSLFetchBoolean(char **papszStrList, const char *pszKey, int bDefault)
DEPRECATED.
Definition: cpl_string.cpp:1627
#define CPL_FORMAT_STRING(arg)
Macro into which to wrap the format argument of a printf-like function.
Definition: cpl_port.h:989
CPLStringList & InsertString(int nInsertAtLineNo, const char *pszNewLine)
Insert into the list at identified location.
Definition: cpl_string.h:480
CPLString CPLURLAddKVP(const char *pszURL, const char *pszKey, const char *pszValue)
Return a new URL with a new key=value pair.
Definition: cplstring.cpp:434
String.
Definition: cpl_string.h:227
char & operator[](std::string::size_type i)
Return character at specified index.
Definition: cpl_string.h:357
#define CPL_RETURNS_NONNULL
Qualifier for a function that does not return NULL.
Definition: cpl_port.h:1032
#define CPL_SCANF_FORMAT_STRING(arg)
Macro into which to wrap the format argument of a sscanf-like function.
Definition: cpl_port.h:991
char ** CSLFetchNameValueMultiple(char **papszStrList, const char *pszName)
In a StringList of "Name=Value" pairs, look for all the values with the specified name...
Definition: cpl_string.cpp:1793
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:354
const char * CSLGetField(char **, int)
Fetches the indicated field, being careful not to crash if the field doesn't exist within this string...
Definition: cpl_string.cpp:169
char ** CSLInsertStrings(char **papszStrList, int nInsertAtLineNo, char **papszNewLines) CPL_WARN_UNUSED_RESULT
Copies the contents of a StringList inside another StringList before the specified line...
Definition: cpl_string.cpp:493
CPLString(const char *pszStr)
Constructor.
Definition: cpl_string.h:349
const char & operator[](std::string::size_type i) const
Return character at specified index.
Definition: cpl_string.h:363
char ** List()
Return list.
Definition: cpl_string.h:522
char ** CSLTokenizeString2(const char *pszString, const char *pszDelimiter, int nCSLTFlags) CPL_WARN_UNUSED_RESULT
Tokenize a string.
Definition: cpl_string.cpp:830
#define CPL_SCAN_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have scanf() formatting.
Definition: cpl_port.h:969
bool CPLTestBool(const char *pszValue)
Test what boolean value contained in the string.
Definition: cpl_string.cpp:1518
bool CPLFetchBool(const char *const *papszStrList, const char *pszKey, bool bDefault)
Check for boolean key value.
Definition: cpl_string.cpp:1592
const char * CPLParseNameValue(const char *pszNameValue, char **ppszKey)
Parse NAME=VALUE string into name and value components.
Definition: cpl_string.cpp:1746
int CSLCount(const char *const *papszStrList)
Return number of items in a string list.
Definition: cpl_string.cpp:143
const char & back() const
Return last character (undefined behaviour if string is empty)
Definition: cpl_string.h:385
CPLString CPLOvPrintf(const char *pszFormat, va_list args)
Return a CPLString with the content of vsprintf()
Definition: cplstring.cpp:503
CPLString(const char *pszStr, size_t n)
Constructor.
Definition: cpl_string.h:351
const char & operator[](int i) const
Return character at specified index.
Definition: cpl_string.h:376
void CSLDestroy(char **papszStrList)
Free string list.
Definition: cpl_string.cpp:196
int CPLIsUTF8(const char *pabyData, int nLen)
Test if a string is encoded as UTF-8.
Definition: cpl_recode.cpp:251
char * CPLUnescapeString(const char *pszString, int *pnLength, int nScheme) CPL_WARN_UNUSED_RESULT
Unescape a string.
Definition: cpl_string.cpp:2223
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:208
char ** CSLParseCommandLine(const char *pszCommandLine)
Tokenize command line arguments in a list of strings.
Definition: cpl_string.cpp:2785
int CPLStrlenUTF8(const char *pszUTF8Str)
Return the number of UTF-8 characters of a nul-terminated string.
Definition: cpl_recode.cpp:363
char * operator[](size_t i)
Return string at specified index.
Definition: cpl_string.h:514
char ** CSLTokenizeStringComplex(const char *pszString, const char *pszDelimiter, int bHonourStrings, int bAllowEmptyTokens) CPL_WARN_UNUSED_RESULT
Obsolete tokenizing api.
Definition: cpl_string.cpp:763
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition: cpl_port.h:999
Integer.
Definition: cpl_string.h:229
const char * CSLFetchNameValue(const char *const *papszStrList, const char *pszName)
In a StringList of "Name=Value" pairs, look for the first value associated with the specified name...
Definition: cpl_string.cpp:1666
CPLString(const std::string &oStr)
Constructor.
Definition: cpl_string.h:346
int CPLBase64DecodeInPlace(GByte *pszBase64)
Decode base64 string "pszBase64" (null terminated) in place.
Definition: cpl_base64.cpp:93
char ** CSLRemoveStrings(char **papszStrList, int nFirstLineToDelete, int nNumToRemove, char ***ppapszRetStrings) CPL_WARN_UNUSED_RESULT
Remove strings inside a StringList.
Definition: cpl_string.cpp:582