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 );
383 int size()
const {
return Count(); }
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 );
413 return Assign( papszListIn, TRUE ); }
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; }
426 int IsSorted()
const {
return bIsSorted; }
428 operator char**(void) {
return List(); }
int CPLEncodingCharSize(const char *pszEncoding)
Definition: cpl_recode.cpp:309
size_t CPLStrlcat(char *pszDest, const char *pszSrc, size_t nDestSize)
Definition: cpl_string.cpp:2698
int CSLTestBoolean(const char *pszValue)
Definition: cpl_string.cpp:1515
char * CPLForceToASCII(const char *pabyData, int nLen, char chReplacementChar)
Definition: cpl_recode.cpp:267
char * CPLRecodeFromWChar(const wchar_t *pwszSource, const char *pszSrcEncoding, const char *pszDstEncoding)
Definition: cpl_recode.cpp:142
char * CPLEscapeString(const char *pszString, int nLength, int nScheme)
Definition: cpl_string.cpp:1982
CPLString CPLURLGetValue(const char *pszURL, const char *pszKey)
Definition: cplstring.cpp:336
int CSLFindName(char **papszStrList, const char *pszName)
Definition: cpl_string.cpp:1666
Convenient string class based on std::string.
Definition: cpl_string.h:283
wchar_t * CPLRecodeToWChar(const char *pszSource, const char *pszSrcEncoding, const char *pszDstEncoding)
Definition: cpl_recode.cpp:200
char * CPLUnescapeString(const char *pszString, int *pnLength, int nScheme)
Definition: cpl_string.cpp:2198
size_t CPLStrlcpy(char *pszDest, const char *pszSrc, size_t nDestSize)
Definition: cpl_string.cpp:2641
int CSLPartialFindString(char **papszHaystack, const char *pszNeedle)
Definition: cpl_string.cpp:716
char ** CSLTokenizeString2(const char *pszString, const char *pszDelimiter, int nCSLTFlags)
Definition: cpl_string.cpp:814
char * CPLRecode(const char *pszSource, const char *pszSrcEncoding, const char *pszDstEncoding)
Definition: cpl_recode.cpp:74
void CSLSetNameValueSeparator(char **papszStrList, const char *pszSeparator)
Definition: cpl_string.cpp:1910
char ** CSLDuplicate(char **papszStrList)
Definition: cpl_string.cpp:214
int CPLprintf(const char *fmt,...)
Definition: cpl_string.cpp:1358
char * CPLBinaryToHex(int nBytes, const GByte *pabyData)
Definition: cpl_string.cpp:2414
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:362
int CPLsprintf(char *str, const char *fmt,...)
Definition: cpl_string.cpp:1332
char ** CSLMerge(char **papszOrig, char **papszOverride)
Merge two lists.
Definition: cpl_string.cpp:254
CPLValueType CPLGetValueType(const char *pszValue)
Definition: cpl_string.cpp:2510
int CPLsnprintf(char *str, size_t size, const char *fmt,...)
Definition: cpl_string.cpp:1305
int CPLvsnprintf(char *str, size_t size, const char *fmt, va_list args)
Definition: cpl_string.cpp:1124
int CPLTestBoolean(const char *pszValue)
Definition: cpl_string.cpp:1537
size_t CPLStrnlen(const char *pszStr, size_t nMaxLen)
Definition: cpl_string.cpp:2733
int CSLFindStringCaseSensitive(char **, const char *)
Definition: cpl_string.cpp:684
int CPLsscanf(const char *str, const char *fmt,...)
Definition: cpl_string.cpp:1420
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)
Definition: cplstring.cpp:369
char ** CSLLoad2(const char *pszFname, int nMaxLines, int nMaxCols, char **papszOptions)
Definition: cpl_string.cpp:299
char ** CSLLoad(const char *pszFname)
Definition: cpl_string.cpp:379
char ** CSLSetNameValue(char **papszStrList, const char *pszName, const char *pszValue)
Definition: cpl_string.cpp:1831
bool CPLTestBool(const char *pszValue)
Definition: cpl_string.cpp:1488
const char * CPLParseNameValue(const char *pszNameValue, char **ppszKey)
Definition: cpl_string.cpp:1712
int CSLCount(const char *const *papszStrList)
Definition: cpl_string.cpp:134
void CSLDestroy(char **papszStrList)
Definition: cpl_string.cpp:186
int CPLIsUTF8(const char *pabyData, int nLen)
Definition: cpl_recode.cpp:243
char ** CSLParseCommandLine(const char *pszCommandLine)
Definition: cpl_string.cpp:2757
char * CPLStrdup(const char *)
Definition: cpl_conv.cpp:261
int CPLStrlenUTF8(const char *pszUTF8Str)
Definition: cpl_recode.cpp:355
int CSLFindString(char **, const char *)
Definition: cpl_string.cpp:650