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;
98 const char * pszNeedle );
99 int CPL_DLL
CSLFindName(
char **papszStrList,
const char *pszName);
101 int CPL_DLL CSLFetchBoolean(
char **papszStrList,
const char *pszKey,
104 const char CPL_DLL *CPLSPrintf(
const char *fmt, ...) CPL_PRINT_FUNC_FORMAT(1, 2);
105 char CPL_DLL **CSLAppendPrintf(
char **papszStrList, const
char *fmt, ...) CPL_PRINT_FUNC_FORMAT(2, 3) CPL_WARN_UNUSED_RESULT;
106 int CPL_DLL CPLVASPrintf(
char **buf, const
char *fmt, va_list args );
111 CSLFetchNameValue(
char **papszStrList, const
char *pszName);
113 CSLFetchNameValueDef(
char **papszStrList, const
char *pszName,
114 const
char *pszDefault );
116 CSLFetchNameValueMultiple(
char **papszStrList, const
char *pszName);
118 CSLAddNameValue(
char **papszStrList,
119 const
char *pszName, const
char *pszValue) CPL_WARN_UNUSED_RESULT;
122 const
char *pszName, const
char *pszValue) CPL_WARN_UNUSED_RESULT;
124 const
char *pszSeparator );
126 #define CPLES_BackslashQuotable 0 131 #define CPLES_XML_BUT_QUOTES 5 134 int nScheme ) CPL_WARN_UNUSED_RESULT;
136 int nScheme ) CPL_WARN_UNUSED_RESULT;
138 char CPL_DLL *
CPLBinaryToHex(
int nBytes,
const GByte *pabyData ) CPL_WARN_UNUSED_RESULT;
139 GByte CPL_DLL *CPLHexToBinary(
const char *pszHex,
int *pnBytes ) CPL_WARN_UNUSED_RESULT;
141 char CPL_DLL *CPLBase64Encode(
int nBytes,
const GByte *pabyData ) CPL_WARN_UNUSED_RESULT;
142 int CPL_DLL CPLBase64DecodeInPlace(GByte* pszBase64);
153 size_t CPL_DLL
CPLStrlcpy(
char* pszDest,
const char* pszSrc,
size_t nDestSize);
154 size_t CPL_DLL
CPLStrlcat(
char* pszDest,
const char* pszSrc,
size_t nDestSize);
155 size_t CPL_DLL
CPLStrnlen (
const char *pszStr,
size_t nMaxLen);
160 #define CPL_ENC_LOCALE "" 161 #define CPL_ENC_UTF8 "UTF-8" 162 #define CPL_ENC_UTF16 "UTF-16" 163 #define CPL_ENC_UCS2 "UCS-2" 164 #define CPL_ENC_UCS4 "UCS-4" 165 #define CPL_ENC_ASCII "ASCII" 166 #define CPL_ENC_ISO8859_1 "ISO-8859-1" 169 void CPL_DLL CPLClearRecodeWarningFlags(
void );
170 char CPL_DLL *
CPLRecode(
const char *pszSource,
171 const char *pszSrcEncoding,
172 const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
174 const char *pszSrcEncoding,
175 const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
177 const char *pszSrcEncoding,
178 const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
179 int CPL_DLL
CPLIsUTF8(
const char* pabyData,
int nLen);
180 char CPL_DLL *
CPLForceToASCII(
const char* pabyData,
int nLen,
char chReplacementChar) CPL_WARN_UNUSED_RESULT;
189 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) 206 #if defined(_MSC_VER) 207 # if (_MSC_VER <= 1202) 208 # define MSVC_OLD_STUPID_BEHAVIOUR 213 #ifdef MSVC_OLD_STUPID_BEHAVIOUR 215 # define gdal_std_string string 217 # define gdal_std_string std::string 222 # pragma warning(disable:4251 4275 4786) 232 CPLString(
const std::string &oStr ) : gdal_std_string( oStr ) {}
233 CPLString(
const char *pszStr ) : gdal_std_string( pszStr ) {}
235 operator const char* (void)
const {
return c_str(); }
237 char& operator[](std::string::size_type i)
239 return gdal_std_string::operator[](i);
242 const char& operator[](std::string::size_type i)
const 244 return gdal_std_string::operator[](i);
247 char& operator[](
int i)
249 return gdal_std_string::operator[](static_cast<std::string::size_type>(i));
252 const char& operator[](
int i)
const 254 return gdal_std_string::operator[](static_cast<std::string::size_type>(i));
257 void Clear() { resize(0); }
260 void Seize(
char *pszValue)
262 if (pszValue == NULL )
272 CPLString &Printf(
const char *pszFormat, ... ) CPL_PRINT_FUNC_FORMAT (2, 3);
273 CPLString &vPrintf(
const char *pszFormat, va_list args );
274 CPLString &FormatC(
double dfValue,
const char *pszFormat = NULL );
276 CPLString &Recode(
const char *pszSrcEncoding,
const char *pszDstEncoding );
279 size_t ifind(
const std::string & str,
size_t pos = 0 )
const;
280 size_t ifind(
const char * s,
size_t pos = 0 )
const;
285 CPLString CPLOPrintf(
const char *pszFormat, ... ) CPL_PRINT_FUNC_FORMAT (1, 2);
286 CPLString CPLOvPrintf(
const char *pszFormat, va_list args);
293 const char* pszValue);
304 mutable int nAllocation;
309 void MakeOurOwnCopy();
310 void EnsureAllocation(
int nMaxLength );
311 int FindSortedInsertionPoint(
const char *pszLine );
321 int size()
const {
return Count(); }
328 {
return InsertStringDirectly( nInsertAtLineNo,
CPLStrdup(pszNewLine) ); }
329 CPLStringList &InsertStringDirectly(
int nInsertAtLineNo,
char *pszNewLine);
334 int FindString(
const char *pszTarget )
const 336 int PartialFindString(
const char *pszNeedle )
const 339 int FindName(
const char *pszName )
const;
340 int FetchBoolean(
const char *pszKey,
int bDefault )
const;
341 const char *FetchNameValue(
const char *pszKey )
const;
342 const char *FetchNameValueDef(
const char *pszKey,
const char *pszDefault )
const;
343 CPLStringList &AddNameValue(
const char *pszKey,
const char *pszValue );
344 CPLStringList &SetNameValue(
const char *pszKey,
const char *pszValue );
346 CPLStringList &Assign(
char **papszList,
int bTakeOwnership=TRUE );
347 CPLStringList &operator=(
char **papszListIn) {
return Assign( papszListIn, TRUE ); }
350 char * operator[](
int i);
351 char * operator[](
size_t i) {
return (*
this)[(int)i]; }
352 const char * operator[](
int i)
const;
353 const char * operator[](
size_t i)
const {
return (*
this)[(int)i]; }
355 char **List() {
return papszList; }
359 int IsSorted()
const {
return bIsSorted; }
361 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:2151
int CSLTestBoolean(const char *pszValue)
Definition: cpl_string.cpp:1039
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:1479
CPLString CPLURLGetValue(const char *pszURL, const char *pszKey)
Definition: cplstring.cpp:342
int CSLFindName(char **papszStrList, const char *pszName)
Definition: cpl_string.cpp:1149
Convenient string class based on std::string.
Definition: cpl_string.h:226
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:1675
size_t CPLStrlcpy(char *pszDest, const char *pszSrc, size_t nDestSize)
Definition: cpl_string.cpp:2097
int CSLPartialFindString(char **papszHaystack, const char *pszNeedle)
Definition: cpl_string.cpp:685
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:1406
char ** CSLTokenizeString2(const char *pszString, const char *pszDelimeter, int nCSLTFlags)
Definition: cpl_string.cpp:788
char ** CSLDuplicate(char **papszStrList)
Definition: cpl_string.cpp:204
char * CPLBinaryToHex(int nBytes, const GByte *pabyData)
Definition: cpl_string.cpp:1880
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:300
char ** CSLMerge(char **papszOrig, char **papszOverride)
Merge two lists.
Definition: cpl_string.cpp:247
CPLValueType CPLGetValueType(const char *pszValue)
Definition: cpl_string.cpp:1982
size_t CPLStrnlen(const char *pszStr, size_t nMaxLen)
Definition: cpl_string.cpp:2186
CPLStringList & InsertString(int nInsertAtLineNo, const char *pszNewLine)
Insert into the list at identified location.
Definition: cpl_string.h:327
CPLString CPLURLAddKVP(const char *pszURL, const char *pszKey, const char *pszValue)
Definition: cplstring.cpp:375
int CSLCount(char **papszStrList)
Definition: cpl_string.cpp:117
char ** CSLLoad2(const char *pszFname, int nMaxLines, int nMaxCols, char **papszOptions)
Definition: cpl_string.cpp:294
char ** CSLLoad(const char *pszFname)
Definition: cpl_string.cpp:373
char ** CSLSetNameValue(char **papszStrList, const char *pszName, const char *pszValue)
Definition: cpl_string.cpp:1323
const char * CPLParseNameValue(const char *pszNameValue, char **ppszKey)
Definition: cpl_string.cpp:1196
void CSLDestroy(char **papszStrList)
Definition: cpl_string.cpp:172
int CPLIsUTF8(const char *pabyData, int nLen)
Definition: cpl_recode.cpp:244
char * CPLStrdup(const char *)
Definition: cpl_conv.cpp:247
int CPLStrlenUTF8(const char *pszUTF8Str)
Definition: cpl_recode.cpp:355
int CSLFindString(char **, const char *)
Definition: cpl_string.cpp:651