31 #ifndef _CPL_STRING_H_INCLUDED
32 #define _CPL_STRING_H_INCLUDED
62 char CPL_DLL **CSLAddString(
char **papszStrList,
const char *pszNewString) CPL_WARN_UNUSED_RESULT;
63 int CPL_DLL CSLCount(
char **papszStrList);
64 const char CPL_DLL *CSLGetField(
char **,
int );
65 void CPL_DLL CPL_STDCALL CSLDestroy(
char **papszStrList);
66 char CPL_DLL **CSLDuplicate(
char **papszStrList) CPL_WARN_UNUSED_RESULT;
67 char CPL_DLL **CSLMerge(
char **papszOrig,
char **papszOverride ) CPL_WARN_UNUSED_RESULT;
69 char CPL_DLL **CSLTokenizeString(
const char *pszString ) CPL_WARN_UNUSED_RESULT;
70 char CPL_DLL **CSLTokenizeStringComplex(
const char *pszString,
71 const char *pszDelimiter,
72 int bHonourStrings,
int bAllowEmptyTokens ) CPL_WARN_UNUSED_RESULT;
73 char CPL_DLL **CSLTokenizeString2(
const char *pszString,
74 const char *pszDelimeter,
75 int nCSLTFlags ) CPL_WARN_UNUSED_RESULT;
77 #define CSLT_HONOURSTRINGS 0x0001
78 #define CSLT_ALLOWEMPTYTOKENS 0x0002
79 #define CSLT_PRESERVEQUOTES 0x0004
80 #define CSLT_PRESERVEESCAPES 0x0008
81 #define CSLT_STRIPLEADSPACES 0x0010
82 #define CSLT_STRIPENDSPACES 0x0020
84 int CPL_DLL CSLPrint(
char **papszStrList, FILE *fpOut);
85 char CPL_DLL **CSLLoad(
const char *pszFname) CPL_WARN_UNUSED_RESULT;
86 char CPL_DLL **CSLLoad2(
const char *pszFname,
int nMaxLines,
int nMaxCols,
char** papszOptions) CPL_WARN_UNUSED_RESULT;
87 int CPL_DLL CSLSave(
char **papszStrList,
const char *pszFname);
89 char CPL_DLL **CSLInsertStrings(
char **papszStrList,
int nInsertAtLineNo,
90 char **papszNewLines) CPL_WARN_UNUSED_RESULT;
91 char CPL_DLL **CSLInsertString(
char **papszStrList,
int nInsertAtLineNo,
92 const char *pszNewLine) CPL_WARN_UNUSED_RESULT;
93 char CPL_DLL **CSLRemoveStrings(
char **papszStrList,
int nFirstLineToDelete,
94 int nNumToRemove,
char ***ppapszRetStrings) CPL_WARN_UNUSED_RESULT;
95 int CPL_DLL CSLFindString(
char **,
const char * );
96 int CPL_DLL CSLPartialFindString(
char **papszHaystack,
97 const char * pszNeedle );
98 int CPL_DLL CSLFindName(
char **papszStrList,
const char *pszName);
99 int CPL_DLL CSLTestBoolean(
const char *pszValue );
100 int CPL_DLL CSLFetchBoolean(
char **papszStrList,
const char *pszKey,
103 const char CPL_DLL *CPLSPrintf(
const char *fmt, ...) CPL_PRINT_FUNC_FORMAT(1, 2);
104 char CPL_DLL **CSLAppendPrintf(
char **papszStrList, const
char *fmt, ...) CPL_PRINT_FUNC_FORMAT(2, 3) CPL_WARN_UNUSED_RESULT;
105 int CPL_DLL CPLVASPrintf(
char **buf, const
char *fmt, va_list args );
108 CPLParseNameValue(const
char *pszNameValue,
char **ppszKey );
110 CSLFetchNameValue(
char **papszStrList, const
char *pszName);
112 CSLFetchNameValueDef(
char **papszStrList, const
char *pszName,
113 const
char *pszDefault );
115 CSLFetchNameValueMultiple(
char **papszStrList, const
char *pszName);
117 CSLAddNameValue(
char **papszStrList,
118 const
char *pszName, const
char *pszValue) CPL_WARN_UNUSED_RESULT;
120 CSLSetNameValue(
char **papszStrList,
121 const
char *pszName, const
char *pszValue) CPL_WARN_UNUSED_RESULT;
122 void CPL_DLL CSLSetNameValueSeparator(
char ** papszStrList,
123 const
char *pszSeparator );
125 #define CPLES_BackslashQuotable 0
131 char CPL_DLL *CPLEscapeString(
const char *pszString,
int nLength,
132 int nScheme ) CPL_WARN_UNUSED_RESULT;
133 char CPL_DLL *CPLUnescapeString(
const char *pszString,
int *pnLength,
134 int nScheme ) CPL_WARN_UNUSED_RESULT;
136 char CPL_DLL *CPLBinaryToHex(
int nBytes,
const GByte *pabyData ) CPL_WARN_UNUSED_RESULT;
137 GByte CPL_DLL *CPLHexToBinary(
const char *pszHex,
int *pnBytes ) CPL_WARN_UNUSED_RESULT;
139 char CPL_DLL *CPLBase64Encode(
int nBytes,
const GByte *pabyData ) CPL_WARN_UNUSED_RESULT;
140 int CPL_DLL CPLBase64DecodeInPlace(GByte* pszBase64);
149 CPLValueType CPL_DLL CPLGetValueType(
const char* pszValue);
151 size_t CPL_DLL CPLStrlcpy(
char* pszDest,
const char* pszSrc,
size_t nDestSize);
152 size_t CPL_DLL CPLStrlcat(
char* pszDest,
const char* pszSrc,
size_t nDestSize);
153 size_t CPL_DLL CPLStrnlen (
const char *pszStr,
size_t nMaxLen);
158 #define CPL_ENC_LOCALE ""
159 #define CPL_ENC_UTF8 "UTF-8"
160 #define CPL_ENC_UTF16 "UTF-16"
161 #define CPL_ENC_UCS2 "UCS-2"
162 #define CPL_ENC_UCS4 "UCS-4"
163 #define CPL_ENC_ASCII "ASCII"
164 #define CPL_ENC_ISO8859_1 "ISO-8859-1"
166 int CPL_DLL CPLEncodingCharSize(
const char *pszEncoding );
167 void CPL_DLL CPLClearRecodeWarningFlags();
168 char CPL_DLL *CPLRecode(
const char *pszSource,
169 const char *pszSrcEncoding,
170 const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
171 char CPL_DLL *CPLRecodeFromWChar(
const wchar_t *pwszSource,
172 const char *pszSrcEncoding,
173 const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
174 wchar_t CPL_DLL *CPLRecodeToWChar(
const char *pszSource,
175 const char *pszSrcEncoding,
176 const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
177 int CPL_DLL CPLIsUTF8(
const char* pabyData,
int nLen);
178 char CPL_DLL *CPLForceToASCII(
const char* pabyData,
int nLen,
char chReplacementChar) CPL_WARN_UNUSED_RESULT;
186 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
203 #if defined(_MSC_VER)
204 # if (_MSC_VER <= 1202)
205 # define MSVC_OLD_STUPID_BEHAVIOUR
210 #ifdef MSVC_OLD_STUPID_BEHAVIOUR
212 # define gdal_std_string string
214 # define gdal_std_string std::string
219 # pragma warning(disable:4251 4275 4786)
223 class CPL_DLL CPLString :
public gdal_std_string
229 CPLString(
const std::string &oStr ) : gdal_std_string( oStr ) {}
230 CPLString(
const char *pszStr ) : gdal_std_string( pszStr ) {}
232 operator const char* (void)
const {
return c_str(); }
234 char& operator[](std::string::size_type i)
236 return gdal_std_string::operator[](i);
239 const char& operator[](std::string::size_type i)
const
241 return gdal_std_string::operator[](i);
244 char& operator[](
int i)
246 return gdal_std_string::operator[](static_cast<std::string::size_type>(i));
249 const char& operator[](
int i)
const
251 return gdal_std_string::operator[](static_cast<std::string::size_type>(i));
254 void Clear() { resize(0); }
257 CPLString &Printf(
const char *pszFormat, ... ) CPL_PRINT_FUNC_FORMAT (2, 3);
258 CPLString &vPrintf( const
char *pszFormat, va_list args );
259 CPLString &FormatC(
double dfValue, const
char *pszFormat = NULL );
261 CPLString &Recode( const
char *pszSrcEncoding, const
char *pszDstEncoding );
264 size_t ifind( const std::
string & str,
size_t pos = 0 ) const;
265 size_t ifind( const
char * s,
size_t pos = 0 ) const;
266 CPLString &toupper(
void );
267 CPLString &tolower(
void );
273 CPLString CPL_DLL CPLURLGetValue(const
char* pszURL, const
char* pszKey);
274 CPLString CPL_DLL CPLURLAddKVP(const
char* pszURL, const
char* pszKey,
275 const
char* pszValue);
282 class CPL_DLL CPLStringList
286 mutable int nAllocation;
291 void MakeOurOwnCopy();
292 void EnsureAllocation(
int nMaxLength );
293 int FindSortedInsertionPoint(
const char *pszLine );
297 CPLStringList(
char **papszList,
int bTakeOwnership=TRUE );
298 CPLStringList(
const CPLStringList& oOther );
301 CPLStringList &Clear();
303 int size()
const {
return Count(); }
306 CPLStringList &AddString(
const char *pszNewString );
307 CPLStringList &AddStringDirectly(
char *pszNewString );
309 CPLStringList &InsertString(
int nInsertAtLineNo,
const char *pszNewLine )
310 {
return InsertStringDirectly( nInsertAtLineNo, CPLStrdup(pszNewLine) ); }
311 CPLStringList &InsertStringDirectly(
int nInsertAtLineNo,
char *pszNewLine);
316 int FindString(
const char *pszTarget )
const
317 {
return CSLFindString( papszList, pszTarget ); }
318 int PartialFindString(
const char *pszNeedle )
const
319 {
return CSLPartialFindString( papszList, pszNeedle ); }
321 int FindName(
const char *pszName )
const;
322 int FetchBoolean(
const char *pszKey,
int bDefault )
const;
323 const char *FetchNameValue(
const char *pszKey )
const;
324 const char *FetchNameValueDef(
const char *pszKey,
const char *pszDefault )
const;
325 CPLStringList &AddNameValue(
const char *pszKey,
const char *pszValue );
326 CPLStringList &SetNameValue(
const char *pszKey,
const char *pszValue );
328 CPLStringList &Assign(
char **papszList,
int bTakeOwnership=TRUE );
329 CPLStringList &operator=(
char **papszListIn) {
return Assign( papszListIn, TRUE ); }
330 CPLStringList &operator=(
const CPLStringList& oOther);
332 char * operator[](
int i);
333 char * operator[](
size_t i) {
return (*
this)[(int)i]; }
334 const char * operator[](
int i)
const;
335 const char * operator[](
size_t i)
const {
return (*
this)[(int)i]; }
337 char **List() {
return papszList; }
340 CPLStringList &Sort();
341 int IsSorted()
const {
return bIsSorted; }
343 operator char**(void) {
return List(); }