32 #ifndef CPL_STRING_H_INCLUDED
33 #define CPL_STRING_H_INCLUDED
69 void CPL_DLL CPL_STDCALL
CSLDestroy(
char **papszStrList);
71 char CPL_DLL **
CSLMerge(
char **papszOrig,
76 const char *pszString,
const char *pszDelimiter,
int bHonourStrings,
79 const char *pszDelimiter,
83 #define CSLT_HONOURSTRINGS 0x0001
85 #define CSLT_ALLOWEMPTYTOKENS 0x0002
87 #define CSLT_PRESERVEQUOTES 0x0004
89 #define CSLT_PRESERVEESCAPES 0x0008
91 #define CSLT_STRIPLEADSPACES 0x0010
93 #define CSLT_STRIPENDSPACES 0x0020
98 const char *pszFname,
int nMaxLines,
int nMaxCols,
104 char CPL_DLL **
CSLInsertString(
char **papszStrList,
int nInsertAtLineNo,
107 char **papszStrList,
int nFirstLineToDelete,
111 const char *pszTarget );
113 const char *pszNeedle );
123 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
124 #ifdef DO_NOT_USE_DEBUG_BOOL
125 #define CPLTestBool(x) CPL_TO_BOOL(CPLTestBoolean(x))
126 #define CPLFetchBool(list,key,default) \
127 CPL_TO_BOOL(CSLFetchBoolean(list,key,default))
133 bool CPL_DLL CPLTestBool(
const char *pszValue );
134 bool CPL_DLL CPLFetchBool(
CSLConstList papszStrList,
const char *pszKey,
150 const char *pszDefault );
162 const char *pszSeparator );
167 #define CPLES_BackslashQuotable 0
177 #define CPLES_XML_BUT_QUOTES 5
179 #define CPLES_CSV_FORCE_QUOTING 6
207 size_t CPL_DLL
CPLStrlcpy(
char* pszDest,
const char* pszSrc,
size_t nDestSize);
208 size_t CPL_DLL
CPLStrlcat(
char* pszDest,
const char* pszSrc,
size_t nDestSize);
209 size_t CPL_DLL
CPLStrnlen(
const char *pszStr,
size_t nMaxLen);
214 int CPL_DLL CPLvsnprintf(
char *str,
size_t size,
221 #if defined(ALIAS_CPLSNPRINTF_AS_SNPRINTF)
222 #define CPLsnprintf snprintf
224 int CPL_DLL CPLsnprintf(
char *str,
size_t size,
230 #if defined(GDAL_COMPILATION) && !defined(DONT_DEPRECATE_SPRINTF)
233 CPL_WARN_DEPRECATED("Use CPLsnprintf instead");
245 int CPL_DLL CPLsscanf( const
char* str,
252 char CPL_DLL **CSLAppendPrintf(
char **papszStrList,
254 CPL_PRINT_FUNC_FORMAT(2, 3) CPL_WARN_UNUSED_RESULT;
255 int CPL_DLL CPLVASPrintf(
char **buf,
257 CPL_PRINT_FUNC_FORMAT(2, 0);
263 #define CPL_ENC_LOCALE ""
265 #define CPL_ENC_UTF8 "UTF-8"
267 #define CPL_ENC_UTF16 "UTF-16"
269 #define CPL_ENC_UCS2 "UCS-2"
271 #define CPL_ENC_UCS4 "UCS-4"
273 #define CPL_ENC_ASCII "ASCII"
275 #define CPL_ENC_ISO8859_1 "ISO-8859-1"
279 void CPL_DLL CPLClearRecodeWarningFlags(
void );
282 const char *pszSource,
const char *pszSrcEncoding,
285 const wchar_t *pwszSource,
const char *pszSrcEncoding,
288 const char *pszSource,
const char *pszSrcEncoding,
290 int CPL_DLL
CPLIsUTF8(
const char* pabyData,
int nLen );
292 const char* pabyData,
int nLen,
301 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
319 # define CPLSTRING_CLASS_DLL
320 # define CPLSTRING_METHOD_DLL CPL_DLL
323 # define CPLSTRING_CLASS_DLL CPL_DLL
324 # define CPLSTRING_METHOD_DLL
329 class CPLSTRING_CLASS_DLL CPLString :
public std::string
337 CPLString(
const std::string &oStr ) : std::string( oStr ) {}
340 CPLString(
const char *pszStr ) : std::string( pszStr ) {}
342 CPLString(
const char *pszStr,
size_t n ) : std::string( pszStr, n ) {}
345 operator const char* (void)
const {
return c_str(); }
348 char& operator[](std::string::size_type i)
350 return std::string::operator[](i);
354 const char& operator[](std::string::size_type i)
const
356 return std::string::operator[](i);
360 char& operator[](
int i)
362 return std::string::operator[](
363 static_cast<std::string::size_type>(i));
367 const char& operator[](
int i)
const
369 return std::string::operator[](
370 static_cast<std::string::size_type>(i));
374 void Clear() { resize(0); }
379 void Seize(
char *pszValue )
381 if (pszValue ==
nullptr )
392 CPLSTRING_METHOD_DLL CPLString &Printf(
394 CPL_PRINT_FUNC_FORMAT (2, 3);
395 CPLSTRING_METHOD_DLL CPLString &vPrintf(
397 CPL_PRINT_FUNC_FORMAT(2, 0);
398 CPLSTRING_METHOD_DLL CPLString &FormatC(
double dfValue, const
char *pszFormat =
nullptr );
399 CPLSTRING_METHOD_DLL CPLString &Trim();
400 CPLSTRING_METHOD_DLL CPLString &Recode( const
char *pszSrcEncoding, const
char *pszDstEncoding );
401 CPLSTRING_METHOD_DLL CPLString &replaceAll(
402 const std::
string &osBefore, const std::
string& osAfter );
403 CPLSTRING_METHOD_DLL CPLString &replaceAll( const std::
string &osBefore,
char chAfter );
404 CPLSTRING_METHOD_DLL CPLString &replaceAll(
char chBefore, const std::
string &osAfter );
405 CPLSTRING_METHOD_DLL CPLString &replaceAll(
char chBefore,
char chAfter );
408 CPLSTRING_METHOD_DLL
size_t ifind( const std::
string & str,
size_t pos = 0 ) const;
409 CPLSTRING_METHOD_DLL
size_t ifind( const
char * s,
size_t pos = 0 ) const;
410 CPLSTRING_METHOD_DLL CPLString &toupper(
void );
411 CPLSTRING_METHOD_DLL CPLString &tolower(
void );
413 CPLSTRING_METHOD_DLL
bool endsWith( const std::
string& osStr ) const;
416 #undef CPLSTRING_CLASS_DLL
417 #undef CPLSTRING_METHOD_DLL
420 CPL_PRINT_FUNC_FORMAT (1, 2);
421 CPLString CPL_DLL CPLOvPrintf(
423 CPL_PRINT_FUNC_FORMAT (1, 0);
424 CPLString CPL_DLL CPLQuotedSQLIdentifier(const
char *pszIdent);
429 CPLString CPL_DLL CPLURLGetValue(const
char* pszURL, const
char* pszKey);
430 CPLString CPL_DLL CPLURLAddKVP(const
char* pszURL, const
char* pszKey,
431 const
char* pszValue);
438 class CPL_DLL CPLStringList
440 char **papszList =
nullptr;
441 mutable int nCount = 0;
442 mutable int nAllocation = 0;
443 bool bOwnList =
false;
444 bool bIsSorted =
false;
446 void MakeOurOwnCopy();
447 void EnsureAllocation(
int nMaxLength );
448 int FindSortedInsertionPoint(
const char *pszLine );
452 explicit CPLStringList(
char **papszList,
int bTakeOwnership=TRUE );
454 CPLStringList(
const CPLStringList& oOther );
457 CPLStringList &Clear();
460 int size()
const {
return Count(); }
464 bool empty()
const {
return Count() == 0; }
466 CPLStringList &AddString(
const char *pszNewString );
467 CPLStringList &AddStringDirectly(
char *pszNewString );
469 CPLStringList &InsertString(
int nInsertAtLineNo,
const char *pszNewLine )
470 {
return InsertStringDirectly( nInsertAtLineNo,
CPLStrdup(pszNewLine) ); }
471 CPLStringList &InsertStringDirectly(
int nInsertAtLineNo,
char *pszNewLine);
477 int FindString(
const char *pszTarget )
const
480 int PartialFindString(
const char *pszNeedle )
const
483 int FindName(
const char *pszName )
const;
484 bool FetchBool(
const char *pszKey,
bool bDefault )
const;
486 int FetchBoolean(
const char *pszKey,
int bDefault )
const;
487 const char *FetchNameValue(
const char *pszKey )
const;
488 const char *FetchNameValueDef(
489 const char *pszKey,
const char *pszDefault )
const;
490 CPLStringList &AddNameValue(
const char *pszKey,
const char *pszValue );
491 CPLStringList &SetNameValue(
const char *pszKey,
const char *pszValue );
493 CPLStringList &Assign(
char **papszListIn,
int bTakeOwnership=TRUE );
495 CPLStringList &operator=(
char **papszListIn) {
496 return Assign( papszListIn, TRUE ); }
498 CPLStringList &operator=(
const CPLStringList& oOther);
503 char * operator[](
int i);
505 char * operator[](
size_t i) {
return (*
this)[
static_cast<int>(i)]; }
507 const char * operator[](
int i)
const;
509 const char * operator[](
size_t i)
const {
510 return (*
this)[
static_cast<int>(i)]; }
512 const char * operator[](
const char* pszKey)
const {
513 return FetchNameValue(pszKey); }
516 char** List() {
return papszList; }
521 CPLStringList &Sort();
523 int IsSorted()
const {
return bIsSorted; }
526 operator char**(void) {
return List(); }
531 #ifdef GDAL_COMPILATION
536 struct CPL_DLL CSLDestroyReleaser
538 void operator()(
char** papszStr)
const {
CSLDestroy(papszStr); }
543 using CSLUniquePtr = std::unique_ptr< char*, CSLDestroyReleaser>;
546 struct CPL_DLL CPLFreeReleaser
548 void operator()(
void* p)
const {
CPLFree(p); }
553 using CPLCharUniquePtr = std::unique_ptr<char, CPLFreeReleaser>;
char CPL_DLL * CPLBase64Encode(int nBytes, const GByte *pabyData) CPL_WARN_UNUSED_RESULT
Definition: cpl_base64.cpp:199
const char CPL_DLL * CSLGetField(CSLConstList, int)
Definition: cpl_string.cpp:173
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
int CPL_DLL CSLPrint(CSLConstList papszStrList, FILE *fpOut)
Definition: cpl_string.cpp:461
int CPL_DLL CSLSave(CSLConstList papszStrList, const char *pszFname)
Definition: cpl_string.cpp:412
size_t CPL_DLL CPLStrnlen(const char *pszStr, size_t nMaxLen)
Definition: cpl_string.cpp:2796
char CPL_DLL ** CSLInsertString(char **papszStrList, int nInsertAtLineNo, const char *pszNewLine) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:562
int CPL_DLL CPLTestBoolean(const char *pszValue)
Definition: cpl_string.cpp:1575
char CPL_DLL ** CSLDuplicate(CSLConstList papszStrList) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:228
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
int CPL_DLL CSLFindString(CSLConstList papszList, const char *pszTarget)
Definition: cpl_string.cpp:670
char CPL_DLL ** CSLSetNameValue(char **papszStrList, const char *pszName, const char *pszValue) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:1877
CPLValueType CPL_DLL CPLGetValueType(const char *pszValue)
Definition: cpl_string.cpp:2572
char CPL_DLL * CPLStrdup(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL
Definition: cpl_conv.cpp:293
const char CPL_DLL * CSLFetchNameValueDef(CSLConstList papszStrList, const char *pszName, const char *pszDefault)
Definition: cpl_string.cpp:1646
char CPL_DLL ** CSLFetchNameValueMultiple(CSLConstList papszStrList, const char *pszName)
Definition: cpl_string.cpp:1801
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:198
char CPL_DLL ** CSLTokenizeStringComplex(const char *pszString, const char *pszDelimiter, int bHonourStrings, int bAllowEmptyTokens) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:769
Definition: cpl_string.h:201
unsigned char GByte
Definition: cpl_port.h:215
char CPL_DLL * CPLEscapeString(const char *pszString, int nLength, int nScheme) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:2036
char CPL_DLL ** CSLInsertStrings(char **papszStrList, int nInsertAtLineNo, CSLConstList papszNewLines) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:497
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:914
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:2248
char CPL_DLL ** CSLParseCommandLine(const char *pszCommandLine)
Definition: cpl_string.cpp:2820
void CPL_DLL CPL_STDCALL CSLDestroy(char **papszStrList)
Definition: cpl_string.cpp:200
int CPL_DLL CSLFindName(CSLConstList papszStrList, const char *pszName)
Definition: cpl_string.cpp:1708
size_t CPL_DLL CPLStrlcpy(char *pszDest, const char *pszSrc, size_t nDestSize)
Definition: cpl_string.cpp:2704
size_t CPL_DLL CPLStrlcat(char *pszDest, const char *pszSrc, size_t nDestSize)
Definition: cpl_string.cpp:2761
int CPL_DLL CSLFetchBoolean(CSLConstList papszStrList, const char *pszKey, int bDefault)
Definition: cpl_string.cpp:1635
char CPL_DLL ** CSLLoad2(const char *pszFname, int nMaxLines, int nMaxCols, CSLConstList papszOptions) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:316
char ** CSLConstList
Definition: cpl_port.h:1194
int CPL_DLL CSLTestBoolean(const char *pszValue)
Definition: cpl_string.cpp:1553
char CPL_DLL ** CSLTokenizeString(const char *pszString) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:759
GByte CPL_DLL * CPLHexToBinary(const char *pszHex, int *pnBytes) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:2533
#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
const char CPL_DLL * CSLFetchNameValue(CSLConstList papszStrList, const char *pszName)
Definition: cpl_string.cpp:1674
int CPL_DLL CSLFindStringCaseSensitive(CSLConstList papszList, const char *pszTarget)
Definition: cpl_string.cpp:704
#define CPL_FORMAT_STRING(arg)
Definition: cpl_port.h:929
int CPL_DLL CSLPartialFindString(CSLConstList papszHaystack, const char *pszNeedle)
Definition: cpl_string.cpp:737
#define CPL_WARN_UNUSED_RESULT
Definition: cpl_port.h:939
Definition: cpl_string.h:200
#define CPL_RETURNS_NONNULL
Definition: cpl_port.h:972
int CPL_DLL CSLCount(CSLConstList papszStrList)
Definition: cpl_string.cpp:147
#define CPL_SCANF_FORMAT_STRING(arg)
Definition: cpl_port.h:931
const char CPL_DLL * CPLParseNameValue(const char *pszNameValue, char **ppszKey)
Definition: cpl_string.cpp:1754
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:836
char CPL_DLL ** CSLMerge(char **papszOrig, CSLConstList papszOverride) CPL_WARN_UNUSED_RESULT
Merge two lists.
Definition: cpl_string.cpp:268
char CPL_DLL ** CSLRemoveStrings(char **papszStrList, int nFirstLineToDelete, int nNumToRemove, char ***ppapszRetStrings) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:588
#define CPL_SCAN_FUNC_FORMAT(format_idx, arg_idx)
Definition: cpl_port.h:916
char CPL_DLL * CPLBinaryToHex(int nBytes, const GByte *pabyData) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:2475
void CPL_DLL CSLSetNameValueSeparator(char **papszStrList, const char *pszSeparator)
Definition: cpl_string.cpp:1957
char CPL_DLL * CPLRecodeFromWChar(const wchar_t *pwszSource, const char *pszSrcEncoding, const char *pszDstEncoding) CPL_WARN_UNUSED_RESULT
Definition: cpl_recode.cpp:149
int CPL_DLL CPLBase64DecodeInPlace(GByte *pszBase64) CPL_WARN_UNUSED_RESULT
Definition: cpl_base64.cpp:93
Definition: cpl_string.h:202
char CPL_DLL ** CSLAddNameValue(char **papszStrList, const char *pszName, const char *pszValue) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:1838