32 #ifndef _CPL_STRING_H_INCLUDED
33 #define _CPL_STRING_H_INCLUDED
63 char CPL_DLL **CSLAddString(
char **papszStrList,
const char *pszNewString) CPL_WARN_UNUSED_RESULT;
64 int CPL_DLL
CSLCount(
char **papszStrList);
65 const char CPL_DLL *CSLGetField(
char **,
int );
66 void CPL_DLL CPL_STDCALL
CSLDestroy(
char **papszStrList);
67 char CPL_DLL **
CSLDuplicate(
char **papszStrList) CPL_WARN_UNUSED_RESULT;
68 char CPL_DLL **
CSLMerge(
char **papszOrig,
char **papszOverride ) CPL_WARN_UNUSED_RESULT;
70 char CPL_DLL **CSLTokenizeString(
const char *pszString ) CPL_WARN_UNUSED_RESULT;
71 char CPL_DLL **CSLTokenizeStringComplex(
const char *pszString,
72 const char *pszDelimiter,
73 int bHonourStrings,
int bAllowEmptyTokens ) CPL_WARN_UNUSED_RESULT;
75 const char *pszDelimeter,
76 int nCSLTFlags ) CPL_WARN_UNUSED_RESULT;
78 #define CSLT_HONOURSTRINGS 0x0001
79 #define CSLT_ALLOWEMPTYTOKENS 0x0002
80 #define CSLT_PRESERVEQUOTES 0x0004
81 #define CSLT_PRESERVEESCAPES 0x0008
82 #define CSLT_STRIPLEADSPACES 0x0010
83 #define CSLT_STRIPENDSPACES 0x0020
85 int CPL_DLL CSLPrint(
char **papszStrList, FILE *fpOut);
86 char CPL_DLL **
CSLLoad(
const char *pszFname) CPL_WARN_UNUSED_RESULT;
87 char CPL_DLL **
CSLLoad2(
const char *pszFname,
int nMaxLines,
int nMaxCols,
char** papszOptions) CPL_WARN_UNUSED_RESULT;
88 int CPL_DLL CSLSave(
char **papszStrList,
const char *pszFname);
90 char CPL_DLL **CSLInsertStrings(
char **papszStrList,
int nInsertAtLineNo,
91 char **papszNewLines) CPL_WARN_UNUSED_RESULT;
92 char CPL_DLL **CSLInsertString(
char **papszStrList,
int nInsertAtLineNo,
93 const char *pszNewLine) CPL_WARN_UNUSED_RESULT;
94 char CPL_DLL **CSLRemoveStrings(
char **papszStrList,
int nFirstLineToDelete,
95 int nNumToRemove,
char ***ppapszRetStrings) CPL_WARN_UNUSED_RESULT;
99 const char * pszNeedle );
100 int CPL_DLL
CSLFindName(
char **papszStrList,
const char *pszName);
102 int CPL_DLL CSLFetchBoolean(
char **papszStrList,
const char *pszKey,
108 CSLFetchNameValue(
char **papszStrList,
const char *pszName);
110 CSLFetchNameValueDef(
char **papszStrList,
const char *pszName,
111 const char *pszDefault );
113 CSLFetchNameValueMultiple(
char **papszStrList,
const char *pszName);
115 CSLAddNameValue(
char **papszStrList,
116 const char *pszName,
const char *pszValue) CPL_WARN_UNUSED_RESULT;
119 const char *pszName,
const char *pszValue) CPL_WARN_UNUSED_RESULT;
121 const char *pszSeparator );
123 #define CPLES_BackslashQuotable 0
128 #define CPLES_XML_BUT_QUOTES 5
131 int nScheme ) CPL_WARN_UNUSED_RESULT;
133 int nScheme ) CPL_WARN_UNUSED_RESULT;
135 char CPL_DLL *
CPLBinaryToHex(
int nBytes,
const GByte *pabyData ) CPL_WARN_UNUSED_RESULT;
136 GByte CPL_DLL *CPLHexToBinary(
const char *pszHex,
int *pnBytes ) CPL_WARN_UNUSED_RESULT;
138 char CPL_DLL *CPLBase64Encode(
int nBytes,
const GByte *pabyData ) CPL_WARN_UNUSED_RESULT;
139 int CPL_DLL CPLBase64DecodeInPlace(GByte* pszBase64);
150 size_t CPL_DLL
CPLStrlcpy(
char* pszDest,
const char* pszSrc,
size_t nDestSize);
151 size_t CPL_DLL
CPLStrlcat(
char* pszDest,
const char* pszSrc,
size_t nDestSize);
152 size_t CPL_DLL
CPLStrnlen (
const char *pszStr,
size_t nMaxLen);
157 int CPL_DLL
CPLvsnprintf(
char *str,
size_t size,
const char* fmt, va_list args);
158 int CPL_DLL
CPLsnprintf(
char *str,
size_t size,
const char* fmt, ...) CPL_PRINT_FUNC_FORMAT(3,4);
159 int CPL_DLL
CPLsprintf(
char *str, const
char* fmt, ...) CPL_PRINT_FUNC_FORMAT(2, 3);
160 int CPL_DLL
CPLprintf(const
char* fmt, ...) CPL_PRINT_FUNC_FORMAT(1, 2);
161 int CPL_DLL
CPLsscanf(const
char* str, const
char* fmt, ...);
163 const
char CPL_DLL *CPLSPrintf(const
char *fmt, ...) CPL_PRINT_FUNC_FORMAT(1, 2);
164 char CPL_DLL **CSLAppendPrintf(
char **papszStrList, const
char *fmt, ...) CPL_PRINT_FUNC_FORMAT(2, 3) CPL_WARN_UNUSED_RESULT;
165 int CPL_DLL CPLVASPrintf(
char **buf, const
char *fmt, va_list args );
170 #define CPL_ENC_LOCALE ""
171 #define CPL_ENC_UTF8 "UTF-8"
172 #define CPL_ENC_UTF16 "UTF-16"
173 #define CPL_ENC_UCS2 "UCS-2"
174 #define CPL_ENC_UCS4 "UCS-4"
175 #define CPL_ENC_ASCII "ASCII"
176 #define CPL_ENC_ISO8859_1 "ISO-8859-1"
179 void CPL_DLL CPLClearRecodeWarningFlags(
void );
180 char CPL_DLL *
CPLRecode(
const char *pszSource,
181 const char *pszSrcEncoding,
182 const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
184 const char *pszSrcEncoding,
185 const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
187 const char *pszSrcEncoding,
188 const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
189 int CPL_DLL
CPLIsUTF8(
const char* pabyData,
int nLen);
190 char CPL_DLL *
CPLForceToASCII(
const char* pabyData,
int nLen,
char chReplacementChar) CPL_WARN_UNUSED_RESULT;
199 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
216 #if defined(_MSC_VER)
217 # if (_MSC_VER <= 1202)
218 # define MSVC_OLD_STUPID_BEHAVIOUR
223 #ifdef MSVC_OLD_STUPID_BEHAVIOUR
225 # define gdal_std_string string
227 # define gdal_std_string std::string
232 # pragma warning(disable:4251 4275 4786)
242 CPLString(
const std::string &oStr ) : gdal_std_string( oStr ) {}
243 CPLString(
const char *pszStr ) : gdal_std_string( pszStr ) {}
245 operator const char* (void)
const {
return c_str(); }
247 char& operator[](std::string::size_type i)
249 return gdal_std_string::operator[](i);
252 const char& operator[](std::string::size_type i)
const
254 return gdal_std_string::operator[](i);
257 char& operator[](
int i)
259 return gdal_std_string::operator[](static_cast<std::string::size_type>(i));
262 const char& operator[](
int i)
const
264 return gdal_std_string::operator[](static_cast<std::string::size_type>(i));
267 void Clear() { resize(0); }
270 void Seize(
char *pszValue)
272 if (pszValue == NULL )
282 CPLString &Printf(
const char *pszFormat, ... ) CPL_PRINT_FUNC_FORMAT (2, 3);
283 CPLString &vPrintf(
const char *pszFormat, va_list args );
284 CPLString &FormatC(
double dfValue,
const char *pszFormat = NULL );
286 CPLString &Recode(
const char *pszSrcEncoding,
const char *pszDstEncoding );
289 size_t ifind(
const std::string & str,
size_t pos = 0 )
const;
290 size_t ifind(
const char * s,
size_t pos = 0 )
const;
295 CPLString CPLOPrintf(
const char *pszFormat, ... ) CPL_PRINT_FUNC_FORMAT (1, 2);
296 CPLString CPLOvPrintf(const
char *pszFormat, va_list args);
303 const
char* pszValue);
314 mutable int nAllocation;
319 void MakeOurOwnCopy();
320 void EnsureAllocation(
int nMaxLength );
321 int FindSortedInsertionPoint(
const char *pszLine );
325 CPLStringList(
char **papszList,
int bTakeOwnership=TRUE );
326 CPLStringList(
const CPLStringList& oOther );
329 CPLStringList &Clear();
331 int size()
const {
return Count(); }
334 CPLStringList &AddString(
const char *pszNewString );
335 CPLStringList &AddStringDirectly(
char *pszNewString );
337 CPLStringList &
InsertString(
int nInsertAtLineNo,
const char *pszNewLine )
338 {
return InsertStringDirectly( nInsertAtLineNo,
CPLStrdup(pszNewLine) ); }
339 CPLStringList &InsertStringDirectly(
int nInsertAtLineNo,
char *pszNewLine);
344 int FindString(
const char *pszTarget )
const
346 int PartialFindString(
const char *pszNeedle )
const
349 int FindName(
const char *pszName )
const;
350 int FetchBoolean(
const char *pszKey,
int bDefault )
const;
351 const char *FetchNameValue(
const char *pszKey )
const;
352 const char *FetchNameValueDef(
const char *pszKey,
const char *pszDefault )
const;
353 CPLStringList &AddNameValue(
const char *pszKey,
const char *pszValue );
354 CPLStringList &SetNameValue(
const char *pszKey,
const char *pszValue );
356 CPLStringList &Assign(
char **papszListIn,
int bTakeOwnership=TRUE );
357 CPLStringList &operator=(
char **papszListIn) {
return Assign( papszListIn, TRUE ); }
358 CPLStringList &operator=(
const CPLStringList& oOther);
360 char * operator[](
int i);
361 char * operator[](
size_t i) {
return (*
this)[(int)i]; }
362 const char * operator[](
int i)
const;
363 const char * operator[](
size_t i)
const {
return (*
this)[(int)i]; }
365 char **List() {
return papszList; }
368 CPLStringList &Sort();
369 int IsSorted()
const {
return bIsSorted; }
371 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:2612
int CSLTestBoolean(const char *pszValue)
Definition: cpl_string.cpp:1485
char * CPLForceToASCII(const char *pabyData, int nLen, char chReplacementChar)
Definition: cpl_recode.cpp:268
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:1925
CPLString CPLURLGetValue(const char *pszURL, const char *pszKey)
Definition: cplstring.cpp:339
int CSLFindName(char **papszStrList, const char *pszName)
Definition: cpl_string.cpp:1595
Convenient string class based on std::string.
Definition: cpl_string.h:236
wchar_t * CPLRecodeToWChar(const char *pszSource, const char *pszSrcEncoding, const char *pszDstEncoding)
Definition: cpl_recode.cpp:201
char * CPLUnescapeString(const char *pszString, int *pnLength, int nScheme)
Definition: cpl_string.cpp:2137
size_t CPLStrlcpy(char *pszDest, const char *pszSrc, size_t nDestSize)
Definition: cpl_string.cpp:2558
int CSLPartialFindString(char **papszHaystack, const char *pszNeedle)
Definition: cpl_string.cpp:723
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:1852
char ** CSLTokenizeString2(const char *pszString, const char *pszDelimeter, int nCSLTFlags)
Definition: cpl_string.cpp:826
char ** CSLDuplicate(char **papszStrList)
Definition: cpl_string.cpp:206
int CPLprintf(const char *fmt,...)
Definition: cpl_string.cpp:1369
char * CPLBinaryToHex(int nBytes, const GByte *pabyData)
Definition: cpl_string.cpp:2342
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:310
int CPLsprintf(char *str, const char *fmt,...)
Definition: cpl_string.cpp:1343
char ** CSLMerge(char **papszOrig, char **papszOverride)
Merge two lists.
Definition: cpl_string.cpp:249
CPLValueType CPLGetValueType(const char *pszValue)
Definition: cpl_string.cpp:2443
int CPLsnprintf(char *str, size_t size, const char *fmt,...)
Definition: cpl_string.cpp:1316
int CPLvsnprintf(char *str, size_t size, const char *fmt, va_list args)
Definition: cpl_string.cpp:1140
size_t CPLStrnlen(const char *pszStr, size_t nMaxLen)
Definition: cpl_string.cpp:2647
int CSLFindStringCaseSensitive(char **, const char *)
Definition: cpl_string.cpp:689
int CPLsscanf(const char *str, const char *fmt,...)
Definition: cpl_string.cpp:1422
CPLStringList & InsertString(int nInsertAtLineNo, const char *pszNewLine)
Insert into the list at identified location.
Definition: cpl_string.h:337
CPLString CPLURLAddKVP(const char *pszURL, const char *pszKey, const char *pszValue)
Definition: cplstring.cpp:372
int CSLCount(char **papszStrList)
Definition: cpl_string.cpp:119
char ** CSLLoad2(const char *pszFname, int nMaxLines, int nMaxCols, char **papszOptions)
Definition: cpl_string.cpp:296
char ** CSLLoad(const char *pszFname)
Definition: cpl_string.cpp:375
char ** CSLSetNameValue(char **papszStrList, const char *pszName, const char *pszValue)
Definition: cpl_string.cpp:1769
const char * CPLParseNameValue(const char *pszNameValue, char **ppszKey)
Definition: cpl_string.cpp:1642
void CSLDestroy(char **papszStrList)
Definition: cpl_string.cpp:174
int CPLIsUTF8(const char *pabyData, int nLen)
Definition: cpl_recode.cpp:244
char * CPLStrdup(const char *)
Definition: cpl_conv.cpp:248
int CPLStrlenUTF8(const char *pszUTF8Str)
Definition: cpl_recode.cpp:355
int CSLFindString(char **, const char *)
Definition: cpl_string.cpp:653