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);
102 char CPL_DLL **CSLLoad2(
103 const char *pszFname,
int nMaxLines,
int nMaxCols,
106 char CPL_DLL **CSLLoad2(
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,
120 int CPL_DLL CSLFindString(
const char *
const *papszList,
121 const char *pszTarget );
122 int CPL_DLL CSLFindStringCaseSensitive(
const char *
const *papszList,
123 const char *pszTarget );
124 int CPL_DLL CSLPartialFindString(
const char *
const *papszHaystack,
125 const char *pszNeedle );
129 int CPL_DLL CSLFindString(
char **papszList,
const char *pszTarget );
130 int CPL_DLL CSLFindStringCaseSensitive(
char *
const *papszList,
131 const char *pszTarget );
132 int CPL_DLL CSLPartialFindString(
char *
const *papszHaystack,
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))
154 bool CPL_DLL CPLTestBool(
const char *pszValue );
155 bool CPL_DLL CPLFetchBool(
const char *
const *papszStrList,
const char *pszKey,
168 CSLFetchNameValue(
const char *
const *papszStrList,
const char *pszName);
170 CSLFetchNameValueDef(
const char *
const *papszStrList,
172 const char *pszDefault );
175 CSLFetchNameValue(
char **papszStrList,
const char *pszName);
177 CSLFetchNameValueDef(
char **papszStrList,
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);
241 int CPL_DLL CPLvsnprintf(
char *str,
size_t size,
248 #if defined(ALIAS_CPLSNPRINTF_AS_SNPRINTF)
249 #define CPLsnprintf snprintf
251 int CPL_DLL CPLsnprintf(
char *str,
size_t size,
257 #if defined(GDAL_COMPILATION) && !defined(DONT_DEPRECATE_SPRINTF)
260 CPL_WARN_DEPRECATED("Use CPLsnprintf instead");
272 int CPL_DLL CPLsscanf( const
char* str,
279 char CPL_DLL **CSLAppendPrintf(
char **papszStrList,
281 CPL_PRINT_FUNC_FORMAT(2, 3) CPL_WARN_UNUSED_RESULT;
282 int CPL_DLL CPLVASPrintf(
char **buf,
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)
338 class CPL_DLL CPLString :
public std::string
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(); }
357 char& operator[](std::string::size_type i)
359 return std::string::operator[](i);
363 const char& operator[](std::string::size_type i)
const
365 return std::string::operator[](i);
369 char& operator[](
int i)
371 return std::string::operator[](
372 static_cast<std::string::size_type>(i));
376 const char& operator[](
int i)
const
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); }
391 void Clear() { resize(0); }
396 void Seize(
char *pszValue )
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 );
418 CPLString &replaceAll(
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;
427 CPLString &toupper(
void );
428 CPLString &tolower(
void );
432 CPL_PRINT_FUNC_FORMAT (1, 2);
433 CPLString CPL_DLL CPLOvPrintf(
435 CPL_PRINT_FUNC_FORMAT (1, 0);
440 CPLString CPL_DLL CPLURLGetValue(const
char* pszURL, const
char* pszKey);
441 CPLString CPL_DLL CPLURLAddKVP(const
char* pszURL, const
char* pszKey,
442 const
char* pszValue);
449 class CPL_DLL CPLStringList
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);
488 int FindString(
const char *pszTarget )
const
489 {
return CSLFindString( papszList, pszTarget ); }
491 int PartialFindString(
const char *pszNeedle )
const
492 {
return CSLPartialFindString( papszList, pszNeedle ); }
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 );
506 CPLStringList &operator=(
char **papszListIn) {
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;
518 const char * operator[](
size_t i)
const {
519 return (*
this)[
static_cast<int>(i)]; }
522 char **List() {
return papszList; }
525 CPLStringList &Sort();
527 int IsSorted()
const {
return bIsSorted; }
530 operator char**(void) {
return List(); }
char CPL_DLL * CPLBase64Encode(int nBytes, const GByte *pabyData) CPL_WARN_UNUSED_RESULT
Definition: cpl_base64.cpp:199
char CPL_DLL * CPLRecode(const char *pszSource, const char *pszSrcEncoding, const char *pszDstEncoding) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL
Definition: cpl_recode.cpp:81
size_t CPL_DLL CPLStrnlen(const char *pszStr, size_t nMaxLen)
Definition: cpl_string.cpp:2765
char CPL_DLL ** CSLInsertString(char **papszStrList, int nInsertAtLineNo, const char *pszNewLine) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:560
int CPL_DLL CPLTestBoolean(const char *pszValue)
Definition: cpl_string.cpp:1571
int CPL_DLL CPLStrlenUTF8(const char *pszUTF8Str)
Definition: cpl_recode.cpp:363
int CPL_DLL CPLIsUTF8(const char *pabyData, int nLen)
Definition: cpl_recode.cpp:251
char CPL_DLL ** CSLSetNameValue(char **papszStrList, const char *pszName, const char *pszValue) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:1873
CPLValueType CPL_DLL CPLGetValueType(const char *pszValue)
Definition: cpl_string.cpp:2541
char CPL_DLL * CPLStrdup(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL
Definition: cpl_conv.cpp:284
int CPL_DLL CSLFetchBoolean(char **papszStrList, const char *pszKey, int bDefault)
Definition: cpl_string.cpp:1631
wchar_t CPL_DLL * CPLRecodeToWChar(const char *pszSource, const char *pszSrcEncoding, const char *pszDstEncoding) CPL_WARN_UNUSED_RESULT
Definition: cpl_recode.cpp:208
CPLValueType
Definition: cpl_string.h:225
char CPL_DLL ** CSLTokenizeStringComplex(const char *pszString, const char *pszDelimiter, int bHonourStrings, int bAllowEmptyTokens) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:767
Definition: cpl_string.h:228
unsigned char GByte
Definition: cpl_port.h:207
char CPL_DLL ** CSLDuplicate(char **papszStrList) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:228
char CPL_DLL * CPLEscapeString(const char *pszString, int nLength, int nScheme) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:2018
char CPL_DLL ** CSLFetchNameValueMultiple(char **papszStrList, const char *pszName)
Definition: cpl_string.cpp:1797
CPL_C_START char CPL_DLL ** CSLAddString(char **papszStrList, const char *pszNewString) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:83
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Definition: cpl_port.h:967
int CPL_DLL CPLEncodingCharSize(const char *pszEncoding)
Definition: cpl_recode.cpp:318
char CPL_DLL * CPLUnescapeString(const char *pszString, int *pnLength, int nScheme) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:2227
char CPL_DLL ** CSLParseCommandLine(const char *pszCommandLine)
Definition: cpl_string.cpp:2789
void CPL_DLL CPL_STDCALL CSLDestroy(char **papszStrList)
Definition: cpl_string.cpp:200
size_t CPL_DLL CPLStrlcpy(char *pszDest, const char *pszSrc, size_t nDestSize)
Definition: cpl_string.cpp:2673
size_t CPL_DLL CPLStrlcat(char *pszDest, const char *pszSrc, size_t nDestSize)
Definition: cpl_string.cpp:2730
char CPL_DLL ** CSLMerge(char **papszOrig, char **papszOverride) CPL_WARN_UNUSED_RESULT
Merge two lists.
Definition: cpl_string.cpp:268
int CPL_DLL CSLTestBoolean(const char *pszValue)
Definition: cpl_string.cpp:1549
int CPL_DLL CPLBase64DecodeInPlace(GByte *pszBase64)
Definition: cpl_base64.cpp:93
char CPL_DLL ** CSLTokenizeString(const char *pszString) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:757
GByte CPL_DLL * CPLHexToBinary(const char *pszHex, int *pnBytes) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:2502
#define CPLFree
Definition: cpl_conv.h:81
char CPL_DLL * CPLForceToASCII(const char *pabyData, int nLen, char chReplacementChar) CPL_WARN_UNUSED_RESULT
Definition: cpl_recode.cpp:276
char CPL_DLL ** CSLLoad(const char *pszFname) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:397
#define CPL_FORMAT_STRING(arg)
Definition: cpl_port.h:989
#define CPL_WARN_UNUSED_RESULT
Definition: cpl_port.h:999
Definition: cpl_string.h:227
#define CPL_RETURNS_NONNULL
Definition: cpl_port.h:1032
#define CPL_SCANF_FORMAT_STRING(arg)
Definition: cpl_port.h:991
const char CPL_DLL * CPLParseNameValue(const char *pszNameValue, char **ppszKey)
Definition: cpl_string.cpp:1750
char CPL_DLL ** CSLAddStringMayFail(char **papszStrList, const char *pszNewString) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:92
char CPL_DLL ** CSLTokenizeString2(const char *pszString, const char *pszDelimiter, int nCSLTFlags) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:834
char CPL_DLL ** CSLRemoveStrings(char **papszStrList, int nFirstLineToDelete, int nNumToRemove, char ***ppapszRetStrings) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:586
int CPL_DLL CSLPrint(char **papszStrList, FILE *fpOut)
Definition: cpl_string.cpp:461
int CPL_DLL CSLSave(char **papszStrList, const char *pszFname)
Definition: cpl_string.cpp:412
const char CPL_DLL * CSLGetField(char **, int)
Definition: cpl_string.cpp:173
#define CPL_SCAN_FUNC_FORMAT(format_idx, arg_idx)
Definition: cpl_port.h:969
char CPL_DLL * CPLBinaryToHex(int nBytes, const GByte *pabyData) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:2444
int CPL_DLL CSLFindName(char **papszStrList, const char *pszName)
Definition: cpl_string.cpp:1704
char CPL_DLL ** CSLInsertStrings(char **papszStrList, int nInsertAtLineNo, char **papszNewLines) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:497
void CPL_DLL CSLSetNameValueSeparator(char **papszStrList, const char *pszSeparator)
Definition: cpl_string.cpp:1946
char CPL_DLL * CPLRecodeFromWChar(const wchar_t *pwszSource, const char *pszSrcEncoding, const char *pszDstEncoding) CPL_WARN_UNUSED_RESULT
Definition: cpl_recode.cpp:149
Definition: cpl_string.h:229
char CPL_DLL ** CSLAddNameValue(char **papszStrList, const char *pszName, const char *pszValue) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:1834