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)) 126 bool CPL_DLL CPLTestBool(
const char *pszValue );
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);
196 int CPL_DLL CPLsnprintf(
char *str,
size_t size,
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 283 class CPL_DLL CPLString :
public gdal_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;
342 CPLString &toupper(
void );
343 CPLString &tolower(
void );
346 CPLString CPLOPrintf(const
char *pszFormat, ... ) CPL_PRINT_FUNC_FORMAT (1, 2);
347 CPLString CPLOvPrintf(
348 const
char *pszFormat, va_list args) CPL_PRINT_FUNC_FORMAT (1, 0);
353 CPLString CPL_DLL CPLURLGetValue(const
char* pszURL, const
char* pszKey);
354 CPLString CPL_DLL CPLURLAddKVP(const
char* pszURL, const
char* pszKey,
355 const
char* pszValue);
362 class CPL_DLL CPLStringList
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 CPL_DLL * CPLRecode(const char *pszSource, const char *pszSrcEncoding, const char *pszDstEncoding) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL
Definition: cpl_recode.cpp:74
size_t CPL_DLL CPLStrnlen(const char *pszStr, size_t nMaxLen)
Definition: cpl_string.cpp:2734
int CPL_DLL CPLTestBoolean(const char *pszValue)
Definition: cpl_string.cpp:1537
int CPL_DLL CPLStrlenUTF8(const char *pszUTF8Str)
Definition: cpl_recode.cpp:355
int CPL_DLL CPLIsUTF8(const char *pabyData, int nLen)
Definition: cpl_recode.cpp:243
char CPL_DLL ** CSLLoad2(const char *pszFname, int nMaxLines, int nMaxCols, char **papszOptions) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:299
char CPL_DLL ** CSLSetNameValue(char **papszStrList, const char *pszName, const char *pszValue) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:1831
CPLValueType CPL_DLL CPLGetValueType(const char *pszValue)
Definition: cpl_string.cpp:2511
char CPL_DLL * CPLStrdup(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL
Definition: cpl_conv.cpp:261
wchar_t CPL_DLL * CPLRecodeToWChar(const char *pszSource, const char *pszSrcEncoding, const char *pszDstEncoding) CPL_WARN_UNUSED_RESULT
Definition: cpl_recode.cpp:200
char CPL_DLL ** CSLDuplicate(char **papszStrList) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:214
char CPL_DLL * CPLEscapeString(const char *pszString, int nLength, int nScheme) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:1982
int CPL_DLL CPLEncodingCharSize(const char *pszEncoding)
Definition: cpl_recode.cpp:309
int CPL_DLL CSLFindStringCaseSensitive(char **, const char *)
Definition: cpl_string.cpp:684
char CPL_DLL * CPLUnescapeString(const char *pszString, int *pnLength, int nScheme) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:2198
char CPL_DLL ** CSLParseCommandLine(const char *pszCommandLine)
Definition: cpl_string.cpp:2758
void CPL_DLL CPL_STDCALL CSLDestroy(char **papszStrList)
Definition: cpl_string.cpp:186
int CPL_DLL CSLFindString(char **, const char *)
Definition: cpl_string.cpp:650
size_t CPL_DLL CPLStrlcpy(char *pszDest, const char *pszSrc, size_t nDestSize)
Definition: cpl_string.cpp:2642
size_t CPL_DLL CPLStrlcat(char *pszDest, const char *pszSrc, size_t nDestSize)
Definition: cpl_string.cpp:2699
char CPL_DLL ** CSLMerge(char **papszOrig, char **papszOverride) CPL_WARN_UNUSED_RESULT
Merge two lists.
Definition: cpl_string.cpp:254
int CPL_DLL CSLPartialFindString(char **papszHaystack, const char *pszNeedle)
Definition: cpl_string.cpp:716
int CPL_DLL CSLTestBoolean(const char *pszValue)
Definition: cpl_string.cpp:1515
char CPL_DLL * CPLForceToASCII(const char *pabyData, int nLen, char chReplacementChar) CPL_WARN_UNUSED_RESULT
Definition: cpl_recode.cpp:267
char CPL_DLL ** CSLLoad(const char *pszFname) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:379
const char CPL_DLL * CPLParseNameValue(const char *pszNameValue, char **ppszKey)
Definition: cpl_string.cpp:1712
char CPL_DLL ** CSLTokenizeString2(const char *pszString, const char *pszDelimiter, int nCSLTFlags) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:814
char CPL_DLL * CPLBinaryToHex(int nBytes, const GByte *pabyData) CPL_WARN_UNUSED_RESULT
Definition: cpl_string.cpp:2414
int CPL_DLL CSLFindName(char **papszStrList, const char *pszName)
Definition: cpl_string.cpp:1666
void CPL_DLL CSLSetNameValueSeparator(char **papszStrList, const char *pszSeparator)
Definition: cpl_string.cpp:1910
char CPL_DLL * CPLRecodeFromWChar(const wchar_t *pwszSource, const char *pszSrcEncoding, const char *pszDstEncoding) CPL_WARN_UNUSED_RESULT
Definition: cpl_recode.cpp:142