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;
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;
97 const char * pszNeedle );
98 int CPL_DLL
CSLFindName(
char **papszStrList,
const char *pszName);
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 );
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;
121 const
char *pszName, const
char *pszValue) CPL_WARN_UNUSED_RESULT;
123 const
char *pszSeparator );
125 #define CPLES_BackslashQuotable 0
130 #define CPLES_XML_BUT_QUOTES 5
133 int nScheme ) CPL_WARN_UNUSED_RESULT;
135 int nScheme ) CPL_WARN_UNUSED_RESULT;
137 char CPL_DLL *
CPLBinaryToHex(
int nBytes,
const GByte *pabyData ) CPL_WARN_UNUSED_RESULT;
138 GByte CPL_DLL *
CPLHexToBinary(
const char *pszHex,
int *pnBytes ) CPL_WARN_UNUSED_RESULT;
140 char CPL_DLL *CPLBase64Encode(
int nBytes,
const GByte *pabyData ) CPL_WARN_UNUSED_RESULT;
141 int CPL_DLL CPLBase64DecodeInPlace(GByte* pszBase64);
152 size_t CPL_DLL
CPLStrlcpy(
char* pszDest,
const char* pszSrc,
size_t nDestSize);
153 size_t CPL_DLL
CPLStrlcat(
char* pszDest,
const char* pszSrc,
size_t nDestSize);
154 size_t CPL_DLL
CPLStrnlen (
const char *pszStr,
size_t nMaxLen);
159 #define CPL_ENC_LOCALE ""
160 #define CPL_ENC_UTF8 "UTF-8"
161 #define CPL_ENC_UTF16 "UTF-16"
162 #define CPL_ENC_UCS2 "UCS-2"
163 #define CPL_ENC_UCS4 "UCS-4"
164 #define CPL_ENC_ASCII "ASCII"
165 #define CPL_ENC_ISO8859_1 "ISO-8859-1"
168 void CPL_DLL CPLClearRecodeWarningFlags();
169 char CPL_DLL *
CPLRecode(
const char *pszSource,
170 const char *pszSrcEncoding,
171 const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
173 const char *pszSrcEncoding,
174 const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
176 const char *pszSrcEncoding,
177 const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
178 int CPL_DLL
CPLIsUTF8(
const char* pabyData,
int nLen);
179 char CPL_DLL *
CPLForceToASCII(
const char* pabyData,
int nLen,
char chReplacementChar) CPL_WARN_UNUSED_RESULT;
187 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
204 #if defined(_MSC_VER)
205 # if (_MSC_VER <= 1202)
206 # define MSVC_OLD_STUPID_BEHAVIOUR
211 #ifdef MSVC_OLD_STUPID_BEHAVIOUR
213 # define gdal_std_string string
215 # define gdal_std_string std::string
220 # pragma warning(disable:4251 4275 4786)
230 CPLString(
const std::string &oStr ) : gdal_std_string( oStr ) {}
231 CPLString(
const char *pszStr ) : gdal_std_string( pszStr ) {}
233 operator const char* (void)
const {
return c_str(); }
235 char& operator[](std::string::size_type i)
237 return gdal_std_string::operator[](i);
240 const char& operator[](std::string::size_type i)
const
242 return gdal_std_string::operator[](i);
245 char& operator[](
int i)
247 return gdal_std_string::operator[](static_cast<std::string::size_type>(i));
250 const char& operator[](
int i)
const
252 return gdal_std_string::operator[](static_cast<std::string::size_type>(i));
255 void Clear() { resize(0); }
258 void Seize(
char *pszValue)
260 if (pszValue == NULL )
270 CPLString &Printf(
const char *pszFormat, ... ) CPL_PRINT_FUNC_FORMAT (2, 3);
271 CPLString &vPrintf(
const char *pszFormat, va_list args );
272 CPLString &FormatC(
double dfValue,
const char *pszFormat = NULL );
274 CPLString &Recode(
const char *pszSrcEncoding,
const char *pszDstEncoding );
277 size_t ifind(
const std::string & str,
size_t pos = 0 )
const;
278 size_t ifind(
const char * s,
size_t pos = 0 )
const;
288 const char* pszValue);
299 mutable int nAllocation;
304 void MakeOurOwnCopy();
305 void EnsureAllocation(
int nMaxLength );
306 int FindSortedInsertionPoint(
const char *pszLine );
316 int size()
const {
return Count(); }
323 {
return InsertStringDirectly( nInsertAtLineNo,
CPLStrdup(pszNewLine) ); }
324 CPLStringList &InsertStringDirectly(
int nInsertAtLineNo,
char *pszNewLine);
329 int FindString(
const char *pszTarget )
const
331 int PartialFindString(
const char *pszNeedle )
const
334 int FindName(
const char *pszName )
const;
335 int FetchBoolean(
const char *pszKey,
int bDefault )
const;
336 const char *FetchNameValue(
const char *pszKey )
const;
337 const char *FetchNameValueDef(
const char *pszKey,
const char *pszDefault )
const;
338 CPLStringList &AddNameValue(
const char *pszKey,
const char *pszValue );
339 CPLStringList &SetNameValue(
const char *pszKey,
const char *pszValue );
341 CPLStringList &Assign(
char **papszList,
int bTakeOwnership=TRUE );
342 CPLStringList &operator=(
char **papszListIn) {
return Assign( papszListIn, TRUE ); }
345 char * operator[](
int i);
346 char * operator[](
size_t i) {
return (*
this)[(int)i]; }
347 const char * operator[](
int i)
const;
348 const char * operator[](
size_t i)
const {
return (*
this)[(int)i]; }
350 char **List() {
return papszList; }
354 int IsSorted()
const {
return bIsSorted; }
356 operator char**(void) {
return List(); }
char ** CSLDuplicate(char **papszStrList) CPL_WARN_UNUSED_RESULT
Clone a string list.
Definition: cpl_string.cpp:203
int CPLEncodingCharSize(const char *pszEncoding)
Return bytes per character for encoding.
Definition: cpl_recode.cpp:308
size_t CPLStrlcat(char *pszDest, const char *pszSrc, size_t nDestSize)
Appends a source string to a destination buffer.
Definition: cpl_string.cpp:2147
char * CPLStrdup(const char *) CPL_WARN_UNUSED_RESULT
Safe version of strdup() function.
Definition: cpl_conv.cpp:243
int CSLTestBoolean(const char *pszValue)
Test what boolean value contained in the string.
Definition: cpl_string.cpp:1038
char * CPLForceToASCII(const char *pabyData, int nLen, char chReplacementChar) CPL_WARN_UNUSED_RESULT
Return a new string that is made only of ASCII characters.
Definition: cpl_recode.cpp:267
GByte * CPLHexToBinary(const char *pszHex, int *pnBytes) CPL_WARN_UNUSED_RESULT
Hexadecimal to binary translation.
Definition: cpl_string.cpp:1914
CPLString CPLURLGetValue(const char *pszURL, const char *pszKey)
Return the value matching a key from a key=value pair in a URL.
Definition: cplstring.cpp:341
char ** CSLSetNameValue(char **papszStrList, const char *pszName, const char *pszValue) CPL_WARN_UNUSED_RESULT
Assign value to name in StringList.
Definition: cpl_string.cpp:1322
int CSLFindName(char **papszStrList, const char *pszName)
Find StringList entry with given key name.
Definition: cpl_string.cpp:1148
Convenient string class based on std::string.
Definition: cpl_string.h:224
char * CPLRecode(const char *pszSource, const char *pszSrcEncoding, const char *pszDstEncoding) CPL_WARN_UNUSED_RESULT
Convert a string from a source encoding to a destination encoding.
Definition: cpl_recode.cpp:73
size_t CPLStrlcpy(char *pszDest, const char *pszSrc, size_t nDestSize)
Copy source string to a destination buffer.
Definition: cpl_string.cpp:2093
char * CPLEscapeString(const char *pszString, int nLength, int nScheme) CPL_WARN_UNUSED_RESULT
Apply escaping to string to preserve special characters.
Definition: cpl_string.cpp:1478
int CSLPartialFindString(char **papszHaystack, const char *pszNeedle)
Find a substring within a string list.
Definition: cpl_string.cpp:684
char ** CSLTokenizeString2(const char *pszString, const char *pszDelimeter, int nCSLTFlags) CPL_WARN_UNUSED_RESULT
Tokenize a string.
Definition: cpl_string.cpp:787
void CSLSetNameValueSeparator(char **papszStrList, const char *pszSeparator)
Replace the default separator (":" or "=") with the passed separator in the given name/value list...
Definition: cpl_string.cpp:1405
char ** CSLLoad2(const char *pszFname, int nMaxLines, int nMaxCols, char **papszOptions) CPL_WARN_UNUSED_RESULT
Load a text file into a string list.
Definition: cpl_string.cpp:293
CPL error handling services.
char ** CSLLoad(const char *pszFname) CPL_WARN_UNUSED_RESULT
Load a text file into a string list.
Definition: cpl_string.cpp:372
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:295
char * CPLBinaryToHex(int nBytes, const GByte *pabyData) CPL_WARN_UNUSED_RESULT
Binary to hexadecimal translation.
Definition: cpl_string.cpp:1879
char * CPLRecodeFromWChar(const wchar_t *pwszSource, const char *pszSrcEncoding, const char *pszDstEncoding) CPL_WARN_UNUSED_RESULT
Convert wchar_t string to UTF-8.
Definition: cpl_recode.cpp:141
CPLValueType CPLGetValueType(const char *pszValue)
Detect the type of the value contained in a string, whether it is a real, an integer or a string Lead...
Definition: cpl_string.cpp:1978
Various convenience functions for CPL.
size_t CPLStrnlen(const char *pszStr, size_t nMaxLen)
Returns the length of a NUL terminated string by reading at most the specified number of bytes...
Definition: cpl_string.cpp:2182
char ** CSLMerge(char **papszOrig, char **papszOverride) CPL_WARN_UNUSED_RESULT
Merge two lists.
Definition: cpl_string.cpp:246
CPLStringList & InsertString(int nInsertAtLineNo, const char *pszNewLine)
Insert into the list at identified location.
Definition: cpl_string.h:322
CPLString CPLURLAddKVP(const char *pszURL, const char *pszKey, const char *pszValue)
Return a new URL with a new key=value pair.
Definition: cplstring.cpp:374
int CSLCount(char **papszStrList)
Return number of items in a string list.
Definition: cpl_string.cpp:116
const char * CPLParseNameValue(const char *pszNameValue, char **ppszKey)
Parse NAME=VALUE string into name and value components.
Definition: cpl_string.cpp:1195
void CSLDestroy(char **papszStrList)
Free string list.
Definition: cpl_string.cpp:171
int CPLIsUTF8(const char *pabyData, int nLen)
Test if a string is encoded as UTF-8.
Definition: cpl_recode.cpp:243
char * CPLUnescapeString(const char *pszString, int *pnLength, int nScheme) CPL_WARN_UNUSED_RESULT
Unescape a string.
Definition: cpl_string.cpp:1674
wchar_t * CPLRecodeToWChar(const char *pszSource, const char *pszSrcEncoding, const char *pszDstEncoding) CPL_WARN_UNUSED_RESULT
Convert UTF-8 string to a wchar_t string.
Definition: cpl_recode.cpp:200
int CSLFindString(char **, const char *)
Find a string within a string list.
Definition: cpl_string.cpp:650