GDAL
cpl_string.h
Go to the documentation of this file.
1 /**********************************************************************
2  * $Id: cpl_string.h 37142 2017-01-14 15:26:34Z goatbar $
3  *
4  * Name: cpl_string.h
5  * Project: CPL - Common Portability Library
6  * Purpose: String and StringList functions.
7  * Author: Daniel Morissette, dmorissette@mapgears.com
8  *
9  **********************************************************************
10  * Copyright (c) 1998, Daniel Morissette
11  * Copyright (c) 2008-2014, Even Rouault <even dot rouault at mines-paris dot org>
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a
14  * copy of this software and associated documentation files (the "Software"),
15  * to deal in the Software without restriction, including without limitation
16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  * and/or sell copies of the Software, and to permit persons to whom the
18  * Software is furnished to do so, subject to the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be included
21  * in all copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29  * DEALINGS IN THE SOFTWARE.
30  ****************************************************************************/
31 
32 #ifndef CPL_STRING_H_INCLUDED
33 #define CPL_STRING_H_INCLUDED
34 
35 #include "cpl_error.h"
36 #include "cpl_conv.h"
37 #include "cpl_vsi.h"
38 
62 
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;
67 #ifdef __cplusplus
68  int CPL_DLL CSLCount(const char * const *papszStrList);
69 #else
70  int CPL_DLL CSLCount(char **papszStrList);
71 #endif
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;
77 
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;
82 char CPL_DLL **CSLTokenizeString2( const char *pszString,
83  const char *pszDelimiter,
84  int nCSLTFlags ) CPL_WARN_UNUSED_RESULT;
85 
87 #define CSLT_HONOURSTRINGS 0x0001
88 
89 #define CSLT_ALLOWEMPTYTOKENS 0x0002
90 
91 #define CSLT_PRESERVEQUOTES 0x0004
92 
93 #define CSLT_PRESERVEESCAPES 0x0008
94 
95 #define CSLT_STRIPLEADSPACES 0x0010
96 
97 #define CSLT_STRIPENDSPACES 0x0020
98 
99 int CPL_DLL CSLPrint(char **papszStrList, FILE *fpOut);
100 char CPL_DLL **CSLLoad(const char *pszFname) CPL_WARN_UNUSED_RESULT;
101 #ifdef __cplusplus
102 char CPL_DLL **CSLLoad2(
103  const char *pszFname, int nMaxLines, int nMaxCols,
104  const char * const * papszOptions) CPL_WARN_UNUSED_RESULT;
105 #else
106 char CPL_DLL **CSLLoad2(
107  const char *pszFname, int nMaxLines, int nMaxCols,
108  char **papszOptions) CPL_WARN_UNUSED_RESULT;
109 #endif
110 int CPL_DLL CSLSave(char **papszStrList, const char *pszFname);
111 
112 char CPL_DLL **CSLInsertStrings(char **papszStrList, int nInsertAtLineNo,
113  char **papszNewLines) CPL_WARN_UNUSED_RESULT;
114 char CPL_DLL **CSLInsertString(char **papszStrList, int nInsertAtLineNo,
115  const char *pszNewLine) CPL_WARN_UNUSED_RESULT;
116 char CPL_DLL **CSLRemoveStrings(
117  char **papszStrList, int nFirstLineToDelete,
118  int nNumToRemove, char ***ppapszRetStrings) CPL_WARN_UNUSED_RESULT;
119 #ifdef __cplusplus
120 int CPL_DLL CSLFindString( const char * const *papszList,
121  const char *pszTarget );
122 int CPL_DLL CSLFindStringCaseSensitive( const char * const *papszList,
123  const char *pszTarget );
124 int CPL_DLL CSLPartialFindString( const char * const *papszHaystack,
125  const char *pszNeedle );
126 #else
127 // Present non-const to C code that does not like passing non-const to const.
128 // Should be ABI compatible with the const versions.
129 int CPL_DLL CSLFindString( char **papszList, const char *pszTarget );
130 int CPL_DLL CSLFindStringCaseSensitive( char * const *papszList,
131  const char *pszTarget );
132 int CPL_DLL CSLPartialFindString( char * const *papszHaystack,
133  const char *pszNeedle );
134 #endif
135 int CPL_DLL CSLFindName(char **papszStrList, const char *pszName);
136 int CPL_DLL CSLFetchBoolean( char **papszStrList, const char *pszKey,
137  int bDefault );
138 
139 /* TODO: Deprecate CSLTestBoolean. Remove in GDAL 3.x. */
140 int CPL_DLL CSLTestBoolean( const char *pszValue );
141 /* Do not use CPLTestBoolean in C++ code. Use CPLTestBool. */
142 int CPL_DLL CPLTestBoolean( const char *pszValue );
143 
144 #ifdef __cplusplus
145 #ifdef DO_NOT_USE_DEBUG_BOOL
146 #define CPLTestBool(x) CPL_TO_BOOL(CPLTestBoolean(x))
147 #define CPLFetchBool(list,key,default) \
148  CPL_TO_BOOL(CSLFetchBoolean(list,key,default))
149 #else /* DO_NOT_USE_DEBUG_BOOL */
150 /* Prefer these for C++ code. */
151 #ifdef DEBUG_BOOL
152 extern "C++" {
153 #endif
154 bool CPL_DLL CPLTestBool( const char *pszValue );
155 bool CPL_DLL CPLFetchBool( const char * const *papszStrList, const char *pszKey,
156  bool bDefault );
157 #ifdef DEBUG_BOOL
158 }
159 #endif
160 #endif
161 #endif /* __cplusplus */
162 
163 const char CPL_DLL *
164  CPLParseNameValue( const char *pszNameValue, char **ppszKey );
165 
166 #ifdef __cplusplus
167 const char CPL_DLL *
168  CSLFetchNameValue( const char * const *papszStrList, const char *pszName);
169 const char CPL_DLL *
170  CSLFetchNameValueDef( const char * const *papszStrList,
171  const char *pszName,
172  const char *pszDefault );
173 #else
174 const char CPL_DLL *
175  CSLFetchNameValue( char **papszStrList, const char *pszName);
176 const char CPL_DLL *
177  CSLFetchNameValueDef( char **papszStrList,
178  const char *pszName,
179  const char *pszDefault );
180 #endif
181 
182 char CPL_DLL **
183  CSLFetchNameValueMultiple(char **papszStrList, const char *pszName);
184 char CPL_DLL **
185  CSLAddNameValue(char **papszStrList,
186  const char *pszName,
187  const char *pszValue) CPL_WARN_UNUSED_RESULT;
188 char CPL_DLL **
189  CSLSetNameValue(char **papszStrList,
190  const char *pszName,
191  const char *pszValue) CPL_WARN_UNUSED_RESULT;
192 void CPL_DLL CSLSetNameValueSeparator( char ** papszStrList,
193  const char *pszSeparator );
194 
195 char CPL_DLL ** CSLParseCommandLine(const char* pszCommandLine);
196 
198 #define CPLES_BackslashQuotable 0
199 
200 #define CPLES_XML 1
201 
202 #define CPLES_URL 2
203 
204 #define CPLES_SQL 3
205 
206 #define CPLES_CSV 4
207 
208 #define CPLES_XML_BUT_QUOTES 5
209 
210 char CPL_DLL *CPLEscapeString( const char *pszString, int nLength,
211  int nScheme ) CPL_WARN_UNUSED_RESULT;
212 char CPL_DLL *CPLUnescapeString( const char *pszString, int *pnLength,
213  int nScheme ) CPL_WARN_UNUSED_RESULT;
214 
215 char CPL_DLL *CPLBinaryToHex( int nBytes,
216  const GByte *pabyData ) CPL_WARN_UNUSED_RESULT;
217 GByte CPL_DLL *CPLHexToBinary( const char *pszHex,
218  int *pnBytes ) CPL_WARN_UNUSED_RESULT;
219 
220 char CPL_DLL *CPLBase64Encode( int nBytes,
221  const GByte *pabyData ) CPL_WARN_UNUSED_RESULT;
222 int CPL_DLL CPLBase64DecodeInPlace( GByte* pszBase64 );
223 
225 typedef enum
226 {
230 } CPLValueType;
231 
232 CPLValueType CPL_DLL CPLGetValueType(const char* pszValue);
233 
234 size_t CPL_DLL CPLStrlcpy(char* pszDest, const char* pszSrc, size_t nDestSize);
235 size_t CPL_DLL CPLStrlcat(char* pszDest, const char* pszSrc, size_t nDestSize);
236 size_t CPL_DLL CPLStrnlen(const char *pszStr, size_t nMaxLen);
237 
238 /* -------------------------------------------------------------------- */
239 /* Locale independent formatting functions. */
240 /* -------------------------------------------------------------------- */
241 int CPL_DLL CPLvsnprintf( char *str, size_t size,
242  CPL_FORMAT_STRING(const char* fmt),
243  va_list args )
244  CPL_PRINT_FUNC_FORMAT(3, 0 );
245 int CPL_DLL CPLsnprintf( char *str, size_t size,
246  CPL_FORMAT_STRING(const char* fmt), ... )
247  CPL_PRINT_FUNC_FORMAT(3, 4);
249 #if defined(GDAL_COMPILATION) && !defined(DONT_DEPRECATE_SPRINTF)
250 int CPL_DLL CPLsprintf( char *str, CPL_FORMAT_STRING(const char* fmt), ... )
252  CPL_WARN_DEPRECATED("Use CPLsnprintf instead");
253 #else
254 int CPL_DLL CPLsprintf( char *str, CPL_FORMAT_STRING(const char* fmt), ... )
255  CPL_PRINT_FUNC_FORMAT(2, 3);
256 #endif
257 
258 int CPL_DLL CPLprintf( CPL_FORMAT_STRING(const char* fmt), ... )
259  CPL_PRINT_FUNC_FORMAT(1, 2);
260 
261 /* For some reason Doxygen_Suppress is needed to avoid warning. Not sure why */
263 /* caution: only works with limited number of formats */
264 int CPL_DLL CPLsscanf( const char* str,
265  CPL_SCANF_FORMAT_STRING(const char* fmt), ... )
266  CPL_SCAN_FUNC_FORMAT(2, 3);
269 const char CPL_DLL *CPLSPrintf( CPL_FORMAT_STRING(const char *fmt), ... )
271 char CPL_DLL **CSLAppendPrintf( char **papszStrList,
272  CPL_FORMAT_STRING(const char *fmt), ... )
273  CPL_PRINT_FUNC_FORMAT(2, 3) CPL_WARN_UNUSED_RESULT;
274 int CPL_DLL CPLVASPrintf( char **buf,
275  CPL_FORMAT_STRING(const char *fmt), va_list args )
276  CPL_PRINT_FUNC_FORMAT(2, 0);
277 
278 /* -------------------------------------------------------------------- */
279 /* RFC 23 character set conversion/recoding API (cpl_recode.cpp). */
280 /* -------------------------------------------------------------------- */
282 #define CPL_ENC_LOCALE ""
283 
284 #define CPL_ENC_UTF8 "UTF-8"
285 
286 #define CPL_ENC_UTF16 "UTF-16"
287 
288 #define CPL_ENC_UCS2 "UCS-2"
289 
290 #define CPL_ENC_UCS4 "UCS-4"
291 
292 #define CPL_ENC_ASCII "ASCII"
293 
294 #define CPL_ENC_ISO8859_1 "ISO-8859-1"
295 
296 int CPL_DLL CPLEncodingCharSize( const char *pszEncoding );
298 void CPL_DLL CPLClearRecodeWarningFlags( void );
300 char CPL_DLL *CPLRecode(
301  const char *pszSource, const char *pszSrcEncoding,
302  const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
303 char CPL_DLL *CPLRecodeFromWChar(
304  const wchar_t *pwszSource, const char *pszSrcEncoding,
305  const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
306 wchar_t CPL_DLL *CPLRecodeToWChar(
307  const char *pszSource, const char *pszSrcEncoding,
308  const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
309 int CPL_DLL CPLIsUTF8( const char* pabyData, int nLen );
310 char CPL_DLL *CPLForceToASCII(
311  const char* pabyData, int nLen,
312  char chReplacementChar ) CPL_WARN_UNUSED_RESULT;
313 int CPL_DLL CPLStrlenUTF8( const char *pszUTF8Str );
314 
315 CPL_C_END
316 
317 /************************************************************************/
318 /* CPLString */
319 /************************************************************************/
320 
321 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
322 
323 #include <string>
324 
325 /*
326  * Simple trick to avoid "using" declaration in header for new compilers
327  * but make it still working with old compilers which throw C2614 errors.
328  *
329  * Define MSVC_OLD_STUPID_BEHAVIOUR
330  * for old compilers: VC++ 5 and 6 as well as eVC++ 3 and 4.
331  */
332 
333 /*
334  * Detect old MSVC++ compiler <= 6.0
335  * 1200 - VC++ 6.0
336  * 1200-1202 - eVC++ 4.0
337  */
338 #if defined(_MSC_VER)
339 # if (_MSC_VER <= 1202)
340 # define MSVC_OLD_STUPID_BEHAVIOUR
341 # endif
342 #endif
343 
344 /* Avoid C2614 errors */
345 #ifdef MSVC_OLD_STUPID_BEHAVIOUR
346  using std::string;
347 # define gdal_std_string string
348 #else
349 
350 # define gdal_std_string std::string
351 
352 #endif
353 
355 class CPL_DLL CPLString : public gdal_std_string
356 {
357 public:
358 
360  CPLString(void) {}
362  // cppcheck-suppress noExplicitConstructor
363  CPLString( const std::string &oStr ) : gdal_std_string( oStr ) {}
365  // cppcheck-suppress noExplicitConstructor
366  CPLString( const char *pszStr ) : gdal_std_string( pszStr ) {}
367 
369  operator const char* (void) const { return c_str(); }
370 
372  char& operator[](std::string::size_type i)
373  {
374  return gdal_std_string::operator[](i);
375  }
376 
378  const char& operator[](std::string::size_type i) const
379  {
380  return gdal_std_string::operator[](i);
381  }
382 
384  char& operator[](int i)
385  {
386  return gdal_std_string::operator[](
387  static_cast<std::string::size_type>(i));
388  }
389 
391  const char& operator[](int i) const
392  {
393  return gdal_std_string::operator[](
394  static_cast<std::string::size_type>(i));
395  }
396 
397  // Note: This is standard in C++11.
398 #ifndef HAVE_CXX11
399 
400  const char& back() const { return operator[](size()-1); }
402  char& back() { return operator[](size()-1); }
403 #endif
404 
406  void Clear() { resize(0); }
407 
411  void Seize( char *pszValue )
412  {
413  if (pszValue == NULL )
414  Clear();
415  else
416  {
417  *this = pszValue;
418  CPLFree(pszValue);
419  }
420  }
421 
422  /* There seems to be a bug in the way the compiler count indices...
423  * Should be CPL_PRINT_FUNC_FORMAT (1, 2) */
424  CPLString &Printf(
425  CPL_FORMAT_STRING(const char *pszFormat), ... )
426  CPL_PRINT_FUNC_FORMAT (2, 3);
427  CPLString &vPrintf(
428  CPL_FORMAT_STRING(const char *pszFormat), va_list args )
429  CPL_PRINT_FUNC_FORMAT(2, 0);
430  CPLString &FormatC( double dfValue, const char *pszFormat = NULL );
431  CPLString &Trim();
432  CPLString &Recode( const char *pszSrcEncoding, const char *pszDstEncoding );
433  CPLString &replaceAll(
434  const std::string &osBefore, const std::string& osAfter );
435  CPLString &replaceAll( const std::string &osBefore, char chAfter );
436  CPLString &replaceAll( char chBefore, const std::string &osAfter );
437  CPLString &replaceAll( char chBefore, char chAfter );
438 
439  /* case insensitive find alternates */
440  size_t ifind( const std::string & str, size_t pos = 0 ) const;
441  size_t ifind( const char * s, size_t pos = 0 ) const;
442  CPLString &toupper( void );
443  CPLString &tolower( void );
444 };
445 
446 CPLString CPL_DLL CPLOPrintf(CPL_FORMAT_STRING(const char *pszFormat), ... )
447  CPL_PRINT_FUNC_FORMAT (1, 2);
448 CPLString CPL_DLL CPLOvPrintf(
449  CPL_FORMAT_STRING(const char *pszFormat), va_list args)
450  CPL_PRINT_FUNC_FORMAT (1, 0);
451 
452 /* -------------------------------------------------------------------- */
453 /* URL processing functions, here since they depend on CPLString. */
454 /* -------------------------------------------------------------------- */
455 CPLString CPL_DLL CPLURLGetValue(const char* pszURL, const char* pszKey);
456 CPLString CPL_DLL CPLURLAddKVP(const char* pszURL, const char* pszKey,
457  const char* pszValue);
458 
459 /************************************************************************/
460 /* CPLStringList */
461 /************************************************************************/
462 
464 class CPL_DLL CPLStringList
465 {
466  char **papszList;
467  mutable int nCount;
468  mutable int nAllocation;
469  bool bOwnList;
470  bool bIsSorted;
471 
472  void Initialize();
473  void MakeOurOwnCopy();
474  void EnsureAllocation( int nMaxLength );
475  int FindSortedInsertionPoint( const char *pszLine );
476 
477  public:
478  CPLStringList();
479  CPLStringList( char **papszList, int bTakeOwnership=TRUE );
480  CPLStringList( const CPLStringList& oOther );
481  ~CPLStringList();
482 
483  CPLStringList &Clear();
484 
486  int size() const { return Count(); }
487  int Count() const;
488 
490  bool empty() const { return Count() == 0; }
491 
492  CPLStringList &AddString( const char *pszNewString );
493  CPLStringList &AddStringDirectly( char *pszNewString );
494 
495  CPLStringList &InsertString( int nInsertAtLineNo, const char *pszNewLine )
496  { return InsertStringDirectly( nInsertAtLineNo, CPLStrdup(pszNewLine) ); }
497  CPLStringList &InsertStringDirectly( int nInsertAtLineNo, char *pszNewLine);
498 
499  // CPLStringList &InsertStrings( int nInsertAtLineNo, char **papszNewLines );
500  // CPLStringList &RemoveStrings( int nFirstLineToDelete, int nNumToRemove=1 );
501 
503  int FindString( const char *pszTarget ) const
504  { return CSLFindString( papszList, pszTarget ); }
506  int PartialFindString( const char *pszNeedle ) const
507  { return CSLPartialFindString( papszList, pszNeedle ); }
508 
509  int FindName( const char *pszName ) const;
510  bool FetchBool( const char *pszKey, bool bDefault ) const;
511  // Deprecated.
512  int FetchBoolean( const char *pszKey, int bDefault ) const;
513  const char *FetchNameValue( const char *pszKey ) const;
514  const char *FetchNameValueDef(
515  const char *pszKey, const char *pszDefault ) const;
516  CPLStringList &AddNameValue( const char *pszKey, const char *pszValue );
517  CPLStringList &SetNameValue( const char *pszKey, const char *pszValue );
518 
519  CPLStringList &Assign( char **papszListIn, int bTakeOwnership=TRUE );
521  CPLStringList &operator=(char **papszListIn) {
522  return Assign( papszListIn, TRUE ); }
524  CPLStringList &operator=(const CPLStringList& oOther);
525 
527  char * operator[](int i);
529  char * operator[](size_t i) { return (*this)[static_cast<int>(i)]; }
531  const char * operator[](int i) const;
533  const char * operator[](size_t i) const {
534  return (*this)[static_cast<int>(i)]; }
535 
537  char **List() { return papszList; }
538  char **StealList();
539 
540  CPLStringList &Sort();
542  int IsSorted() const { return bIsSorted; }
543 
545  operator char**(void) { return List(); }
546 };
547 
548 #endif /* def __cplusplus && !CPL_SUPRESS_CPLUSPLUS */
549 
550 #endif /* CPL_STRING_H_INCLUDED */
CPLString(void)
Constructor.
Definition: cpl_string.h:360
char ** CSLDuplicate(char **papszStrList) CPL_WARN_UNUSED_RESULT
Clone a string list.
Definition: cpl_string.cpp:224
int CPLEncodingCharSize(const char *pszEncoding)
Return bytes per character for encoding.
Definition: cpl_recode.cpp:318
char * CPLBase64Encode(int nBytes, const GByte *pabyData) CPL_WARN_UNUSED_RESULT
Base64 encode a buffer.
Definition: cpl_base64.cpp:199
size_t CPLStrlcat(char *pszDest, const char *pszSrc, size_t nDestSize)
Appends a source string to a destination buffer.
Definition: cpl_string.cpp:2721
Standard C Covers.
char ** CSLTokenizeString(const char *pszString) CPL_WARN_UNUSED_RESULT
Tokenizes a string and returns a StringList with one string for each token.
Definition: cpl_string.cpp:753
int CSLTestBoolean(const char *pszValue)
Test what boolean value contained in the string.
Definition: cpl_string.cpp:1541
bool empty() const
Return whether the list is empty.
Definition: cpl_string.h:490
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:352
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:276
void Clear()
Clear the string.
Definition: cpl_string.h:406
GByte * CPLHexToBinary(const char *pszHex, int *pnBytes) CPL_WARN_UNUSED_RESULT
Hexadecimal to binary translation.
Definition: cpl_string.cpp:2494
int CSLPartialFindString(const char *const *papszHaystack, const char *pszNeedle)
Find a substring within a string list.
Definition: cpl_string.cpp:731
char & back()
Return last character (undefined behaviour if string is empty)
Definition: cpl_string.h:402
CPLString CPLOPrintf(const char *pszFormat,...)
Return a CPLString with the content of sprintf()
Definition: cplstring.cpp:484
char * CPLRecode(const char *pszSource, const char *pszSrcEncoding, const char *pszDstEncoding) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL
Convert a string from a source encoding to a destination encoding.
Definition: cpl_recode.cpp:81
char ** CSLLoad2(const char *pszFname, int nMaxLines, int nMaxCols, const char *const *papszOptions) CPL_WARN_UNUSED_RESULT
Load a text file into a string list.
Definition: cpl_string.cpp:312
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:401
const char * CPLSPrintf(const char *fmt,...) CPL_WARN_UNUSED_RESULT
CPLSPrintf() that works with 10 static buffer.
Definition: cpl_string.cpp:971
char ** CSLAppendPrintf(char **papszStrList, const char *fmt,...) CPL_WARN_UNUSED_RESULT
Use CPLSPrintf() to append a new line at the end of a StringList.
Definition: cpl_string.cpp:1023
CPLValueType
Type of value.
Definition: cpl_string.h:225
Real number.
Definition: cpl_string.h:228
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:207
char ** CSLSetNameValue(char **papszStrList, const char *pszName, const char *pszValue) CPL_WARN_UNUSED_RESULT
Assign value to name in StringList.
Definition: cpl_string.cpp:1865
int CSLFindName(char **papszStrList, const char *pszName)
Find StringList entry with given key name.
Definition: cpl_string.cpp:1696
int FindString(const char *pszTarget) const
Return index of pszTarget in the list, or -1.
Definition: cpl_string.h:503
char ** CSLAddString(char **papszStrList, const char *pszNewString) CPL_WARN_UNUSED_RESULT
Append a string to a StringList and return a pointer to the modified StringList.
Definition: cpl_string.cpp:79
char ** CSLInsertString(char **papszStrList, int nInsertAtLineNo, const char *pszNewLine) CPL_WARN_UNUSED_RESULT
Insert a string at a given line number inside a StringList.
Definition: cpl_string.cpp:556
char & operator[](int i)
Return character at specified index.
Definition: cpl_string.h:384
int PartialFindString(const char *pszNeedle) const
Return index of pszTarget in the list (using partial search), or -1.
Definition: cpl_string.h:506
Convenient string class based on std::string.
Definition: cpl_string.h:355
char ** CSLAddNameValue(char **papszStrList, const char *pszName, const char *pszValue) CPL_WARN_UNUSED_RESULT
Add a new entry to a StringList of "Name=Value" pairs, ("Name:Value" pairs are also supported for bac...
Definition: cpl_string.cpp:1826
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition: cpl_port.h:960
size_t CPLStrlcpy(char *pszDest, const char *pszSrc, size_t nDestSize)
Copy source string to a destination buffer.
Definition: cpl_string.cpp:2664
char * CPLStrdup(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL
Safe version of strdup() function.
Definition: cpl_conv.cpp:286
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:2010
int IsSorted() const
Returns whether the list is sorted.
Definition: cpl_string.h:542
int CSLFindString(const char *const *papszList, const char *pszTarget)
Find a string within a string list (case insensitive).
Definition: cpl_string.cpp:664
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:1938
CPL error handling services.
int CPLprintf(const char *fmt,...)
printf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1381
CPLStringList & operator=(char **papszListIn)
Assignment operator.
Definition: cpl_string.h:521
void Seize(char *pszValue)
Assign specified string and take ownership of it (assumed to be allocated with CPLMalloc()).
Definition: cpl_string.h:411
char ** CSLLoad(const char *pszFname) CPL_WARN_UNUSED_RESULT
Load a text file into a string list.
Definition: cpl_string.cpp:393
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:464
char * CPLBinaryToHex(int nBytes, const GByte *pabyData) CPL_WARN_UNUSED_RESULT
Binary to hexadecimal translation.
Definition: cpl_string.cpp:2436
int CSLSave(char **papszStrList, const char *pszFname)
Write a StringList to a text file.
Definition: cpl_string.cpp:408
char ** CSLAddStringMayFail(char **papszStrList, const char *pszNewString) CPL_WARN_UNUSED_RESULT
Same as CSLAddString() but may return NULL in case of (memory) failure.
Definition: cpl_string.cpp:88
int CSLFindStringCaseSensitive(const char *const *papszList, const char *pszTarget)
Find a string within a string list(case sensitive)
Definition: cpl_string.cpp:698
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:149
#define CPLFree
Alias of VSIFree()
Definition: cpl_conv.h:77
int size() const
Return size of list.
Definition: cpl_string.h:486
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:2532
Various convenience functions for CPL.
const char * CSLFetchNameValueDef(const char *const *papszStrList, const char *pszName, const char *pszDefault)
Same as CSLFetchNameValue() but return pszDefault in case of no match.
Definition: cpl_string.cpp:1634
int CSLPrint(char **papszStrList, FILE *fpOut)
Print a StringList to fpOut.
Definition: cpl_string.cpp:457
int CPLsnprintf(char *str, size_t size, const char *fmt,...)
snprintf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1327
int CPLvsnprintf(char *str, size_t size, const char *fmt, va_list args)
vsnprintf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1133
int CPLTestBoolean(const char *pszValue)
Test what boolean value contained in the string.
Definition: cpl_string.cpp:1563
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:2756
char ** CSLMerge(char **papszOrig, char **papszOverride) CPL_WARN_UNUSED_RESULT
Merge two lists.
Definition: cpl_string.cpp:264
const char * operator[](size_t i) const
Return string at specified index.
Definition: cpl_string.h:533
int CPLVASPrintf(char **buf, const char *fmt, va_list args)
This is intended to serve as an easy to use C callable vasprintf() alternative.
Definition: cpl_string.cpp:1042
int CSLFetchBoolean(char **papszStrList, const char *pszKey, int bDefault)
DEPRECATED.
Definition: cpl_string.cpp:1623
#define CPL_FORMAT_STRING(arg)
Macro into which to wrap the format argument of a printf-like function.
Definition: cpl_port.h:982
CPLStringList & InsertString(int nInsertAtLineNo, const char *pszNewLine)
Insert into the list at identified location.
Definition: cpl_string.h:495
CPLString CPLURLAddKVP(const char *pszURL, const char *pszKey, const char *pszValue)
Return a new URL with a new key=value pair.
Definition: cplstring.cpp:434
String.
Definition: cpl_string.h:227
char & operator[](std::string::size_type i)
Return character at specified index.
Definition: cpl_string.h:372
#define CPL_RETURNS_NONNULL
Qualifier for a function that does not return NULL.
Definition: cpl_port.h:1025
#define CPL_SCANF_FORMAT_STRING(arg)
Macro into which to wrap the format argument of a sscanf-like function.
Definition: cpl_port.h:984
char ** CSLFetchNameValueMultiple(char **papszStrList, const char *pszName)
In a StringList of "Name=Value" pairs, look for all the values with the specified name...
Definition: cpl_string.cpp:1789
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:354
const char * CSLGetField(char **, int)
Fetches the indicated field, being careful not to crash if the field doesn't exist within this string...
Definition: cpl_string.cpp:169
char ** CSLInsertStrings(char **papszStrList, int nInsertAtLineNo, char **papszNewLines) CPL_WARN_UNUSED_RESULT
Copies the contents of a StringList inside another StringList before the specified line...
Definition: cpl_string.cpp:493
CPLString(const char *pszStr)
Constructor.
Definition: cpl_string.h:366
const char & operator[](std::string::size_type i) const
Return character at specified index.
Definition: cpl_string.h:378
char ** List()
Return list.
Definition: cpl_string.h:537
char ** CSLTokenizeString2(const char *pszString, const char *pszDelimiter, int nCSLTFlags) CPL_WARN_UNUSED_RESULT
Tokenize a string.
Definition: cpl_string.cpp:830
#define CPL_SCAN_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have scanf() formatting.
Definition: cpl_port.h:962
bool CPLTestBool(const char *pszValue)
Test what boolean value contained in the string.
Definition: cpl_string.cpp:1514
bool CPLFetchBool(const char *const *papszStrList, const char *pszKey, bool bDefault)
Check for boolean key value.
Definition: cpl_string.cpp:1588
const char * CPLParseNameValue(const char *pszNameValue, char **ppszKey)
Parse NAME=VALUE string into name and value components.
Definition: cpl_string.cpp:1742
int CSLCount(const char *const *papszStrList)
Return number of items in a string list.
Definition: cpl_string.cpp:143
const char & back() const
Return last character (undefined behaviour if string is empty)
Definition: cpl_string.h:400
CPLString CPLOvPrintf(const char *pszFormat, va_list args)
Return a CPLString with the content of vsprintf()
Definition: cplstring.cpp:503
const char & operator[](int i) const
Return character at specified index.
Definition: cpl_string.h:391
void CSLDestroy(char **papszStrList)
Free string list.
Definition: cpl_string.cpp:196
int CPLIsUTF8(const char *pabyData, int nLen)
Test if a string is encoded as UTF-8.
Definition: cpl_recode.cpp:251
char * CPLUnescapeString(const char *pszString, int *pnLength, int nScheme) CPL_WARN_UNUSED_RESULT
Unescape a string.
Definition: cpl_string.cpp:2219
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:208
char ** CSLParseCommandLine(const char *pszCommandLine)
Tokenize command line arguments in a list of strings.
Definition: cpl_string.cpp:2780
int CPLStrlenUTF8(const char *pszUTF8Str)
Return the number of UTF-8 characters of a nul-terminated string.
Definition: cpl_recode.cpp:363
char * operator[](size_t i)
Return string at specified index.
Definition: cpl_string.h:529
char ** CSLTokenizeStringComplex(const char *pszString, const char *pszDelimiter, int bHonourStrings, int bAllowEmptyTokens) CPL_WARN_UNUSED_RESULT
Obsolete tokenizing api.
Definition: cpl_string.cpp:763
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition: cpl_port.h:992
Integer.
Definition: cpl_string.h:229
const char * CSLFetchNameValue(const char *const *papszStrList, const char *pszName)
In a StringList of "Name=Value" pairs, look for the first value associated with the specified name...
Definition: cpl_string.cpp:1662
CPLString(const std::string &oStr)
Constructor.
Definition: cpl_string.h:363
int CPLBase64DecodeInPlace(GByte *pszBase64)
Decode base64 string "pszBase64" (null terminated) in place.
Definition: cpl_base64.cpp:93
char ** CSLRemoveStrings(char **papszStrList, int nFirstLineToDelete, int nNumToRemove, char ***ppapszRetStrings) CPL_WARN_UNUSED_RESULT
Remove strings inside a StringList.
Definition: cpl_string.cpp:582

Generated for GDAL by doxygen 1.8.8.