GDAL
cpl_string.h
Go to the documentation of this file.
1 /**********************************************************************
2  * $Id$
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 int CPL_DLL CSLCount(CSLConstList papszStrList);
68 const char CPL_DLL *CSLGetField( CSLConstList, int );
69 void CPL_DLL CPL_STDCALL CSLDestroy(char **papszStrList);
70 char CPL_DLL **CSLDuplicate(CSLConstList papszStrList) CPL_WARN_UNUSED_RESULT;
71 char CPL_DLL **CSLMerge( char **papszOrig,
72  CSLConstList papszOverride ) CPL_WARN_UNUSED_RESULT;
73 
74 char CPL_DLL **CSLTokenizeString(const char *pszString ) CPL_WARN_UNUSED_RESULT;
75 char CPL_DLL **CSLTokenizeStringComplex(
76  const char *pszString, const char *pszDelimiter, int bHonourStrings,
77  int bAllowEmptyTokens ) CPL_WARN_UNUSED_RESULT;
78 char CPL_DLL **CSLTokenizeString2( const char *pszString,
79  const char *pszDelimiter,
80  int nCSLTFlags ) CPL_WARN_UNUSED_RESULT;
81 
83 #define CSLT_HONOURSTRINGS 0x0001
84 
85 #define CSLT_ALLOWEMPTYTOKENS 0x0002
86 
87 #define CSLT_PRESERVEQUOTES 0x0004
88 
89 #define CSLT_PRESERVEESCAPES 0x0008
90 
91 #define CSLT_STRIPLEADSPACES 0x0010
92 
93 #define CSLT_STRIPENDSPACES 0x0020
94 
95 int CPL_DLL CSLPrint(CSLConstList papszStrList, FILE *fpOut);
96 char CPL_DLL **CSLLoad(const char *pszFname) CPL_WARN_UNUSED_RESULT;
97 char CPL_DLL **CSLLoad2(
98  const char *pszFname, int nMaxLines, int nMaxCols,
100 int CPL_DLL CSLSave(CSLConstList papszStrList, const char *pszFname);
101 
102 char CPL_DLL **CSLInsertStrings(char **papszStrList, int nInsertAtLineNo,
103  CSLConstList papszNewLines) CPL_WARN_UNUSED_RESULT;
104 char CPL_DLL **CSLInsertString(char **papszStrList, int nInsertAtLineNo,
105  const char *pszNewLine) CPL_WARN_UNUSED_RESULT;
106 char CPL_DLL **CSLRemoveStrings(
107  char **papszStrList, int nFirstLineToDelete,
108  int nNumToRemove, char ***ppapszRetStrings) CPL_WARN_UNUSED_RESULT;
109 int CPL_DLL CSLFindString( CSLConstList papszList, const char *pszTarget );
110 int CPL_DLL CSLFindStringCaseSensitive( CSLConstList papszList,
111  const char *pszTarget );
112 int CPL_DLL CSLPartialFindString( CSLConstList papszHaystack,
113  const char *pszNeedle );
114 int CPL_DLL CSLFindName(CSLConstList papszStrList, const char *pszName);
115 int CPL_DLL CSLFetchBoolean( CSLConstList papszStrList, const char *pszKey,
116  int bDefault );
117 
118 /* TODO: Deprecate CSLTestBoolean. Remove in GDAL 3.x. */
119 int CPL_DLL CSLTestBoolean( const char *pszValue );
120 /* Do not use CPLTestBoolean in C++ code. Use CPLTestBool. */
121 int CPL_DLL CPLTestBoolean( const char *pszValue );
122 
123 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
124 #ifdef DO_NOT_USE_DEBUG_BOOL
125 #define CPLTestBool(x) CPL_TO_BOOL(CPLTestBoolean(x))
126 #define CPLFetchBool(list,key,default) \
127  CPL_TO_BOOL(CSLFetchBoolean(list,key,default))
128 #else /* DO_NOT_USE_DEBUG_BOOL */
129 /* Prefer these for C++ code. */
130 #ifdef DEBUG_BOOL
131 extern "C++" {
132 #endif
133 bool CPL_DLL CPLTestBool( const char *pszValue );
134 bool CPL_DLL CPLFetchBool( CSLConstList papszStrList, const char *pszKey,
135  bool bDefault );
136 #ifdef DEBUG_BOOL
137 }
138 #endif
139 #endif
140 #endif /* __cplusplus */
141 
142 const char CPL_DLL *
143  CPLParseNameValue( const char *pszNameValue, char **ppszKey );
144 
145 const char CPL_DLL *
146  CSLFetchNameValue( CSLConstList papszStrList, const char *pszName);
147 const char CPL_DLL *
148  CSLFetchNameValueDef( CSLConstList papszStrList,
149  const char *pszName,
150  const char *pszDefault );
151 char CPL_DLL **
152  CSLFetchNameValueMultiple(CSLConstList papszStrList, const char *pszName);
153 char CPL_DLL **
154  CSLAddNameValue(char **papszStrList,
155  const char *pszName,
156  const char *pszValue) CPL_WARN_UNUSED_RESULT;
157 char CPL_DLL **
158  CSLSetNameValue(char **papszStrList,
159  const char *pszName,
160  const char *pszValue) CPL_WARN_UNUSED_RESULT;
161 void CPL_DLL CSLSetNameValueSeparator( char ** papszStrList,
162  const char *pszSeparator );
163 
164 char CPL_DLL ** CSLParseCommandLine(const char* pszCommandLine);
165 
167 #define CPLES_BackslashQuotable 0
168 
169 #define CPLES_XML 1
170 
171 #define CPLES_URL 2
172 
173 #define CPLES_SQL 3
174 
175 #define CPLES_CSV 4
176 
177 #define CPLES_XML_BUT_QUOTES 5
178 
179 char CPL_DLL *CPLEscapeString( const char *pszString, int nLength,
180  int nScheme ) CPL_WARN_UNUSED_RESULT;
181 char CPL_DLL *CPLUnescapeString( const char *pszString, int *pnLength,
182  int nScheme ) CPL_WARN_UNUSED_RESULT;
183 
184 char CPL_DLL *CPLBinaryToHex( int nBytes,
185  const GByte *pabyData ) CPL_WARN_UNUSED_RESULT;
186 GByte CPL_DLL *CPLHexToBinary( const char *pszHex,
187  int *pnBytes ) CPL_WARN_UNUSED_RESULT;
188 
189 char CPL_DLL *CPLBase64Encode( int nBytes,
190  const GByte *pabyData ) CPL_WARN_UNUSED_RESULT;
191 int CPL_DLL CPLBase64DecodeInPlace( GByte* pszBase64 ) CPL_WARN_UNUSED_RESULT;
192 
194 typedef enum
195 {
199 } CPLValueType;
200 
201 CPLValueType CPL_DLL CPLGetValueType(const char* pszValue);
202 
203 size_t CPL_DLL CPLStrlcpy(char* pszDest, const char* pszSrc, size_t nDestSize);
204 size_t CPL_DLL CPLStrlcat(char* pszDest, const char* pszSrc, size_t nDestSize);
205 size_t CPL_DLL CPLStrnlen(const char *pszStr, size_t nMaxLen);
206 
207 /* -------------------------------------------------------------------- */
208 /* Locale independent formatting functions. */
209 /* -------------------------------------------------------------------- */
210 int CPL_DLL CPLvsnprintf( char *str, size_t size,
211  CPL_FORMAT_STRING(const char* fmt),
212  va_list args )
213  CPL_PRINT_FUNC_FORMAT(3, 0 );
214 
215 /* ALIAS_CPLSNPRINTF_AS_SNPRINTF might be defined to enable GCC 7 */
216 /* -Wformat-truncation= warnings, but shouldn't be set for normal use */
217 #if defined(ALIAS_CPLSNPRINTF_AS_SNPRINTF)
218 #define CPLsnprintf snprintf
219 #else
220 int CPL_DLL CPLsnprintf( char *str, size_t size,
221  CPL_FORMAT_STRING(const char* fmt), ... )
222  CPL_PRINT_FUNC_FORMAT(3, 4);
223 #endif
224 
226 #if defined(GDAL_COMPILATION) && !defined(DONT_DEPRECATE_SPRINTF)
227 int CPL_DLL CPLsprintf( char *str, CPL_FORMAT_STRING(const char* fmt), ... )
229  CPL_WARN_DEPRECATED("Use CPLsnprintf instead");
230 #else
231 int CPL_DLL CPLsprintf( char *str, CPL_FORMAT_STRING(const char* fmt), ... )
232  CPL_PRINT_FUNC_FORMAT(2, 3);
233 #endif
234 
235 int CPL_DLL CPLprintf( CPL_FORMAT_STRING(const char* fmt), ... )
236  CPL_PRINT_FUNC_FORMAT(1, 2);
237 
238 /* For some reason Doxygen_Suppress is needed to avoid warning. Not sure why */
240 /* caution: only works with limited number of formats */
241 int CPL_DLL CPLsscanf( const char* str,
242  CPL_SCANF_FORMAT_STRING(const char* fmt), ... )
243  CPL_SCAN_FUNC_FORMAT(2, 3);
246 const char CPL_DLL *CPLSPrintf( CPL_FORMAT_STRING(const char *fmt), ... )
248 char CPL_DLL **CSLAppendPrintf( char **papszStrList,
249  CPL_FORMAT_STRING(const char *fmt), ... )
250  CPL_PRINT_FUNC_FORMAT(2, 3) CPL_WARN_UNUSED_RESULT;
251 int CPL_DLL CPLVASPrintf( char **buf,
252  CPL_FORMAT_STRING(const char *fmt), va_list args )
253  CPL_PRINT_FUNC_FORMAT(2, 0);
254 
255 /* -------------------------------------------------------------------- */
256 /* RFC 23 character set conversion/recoding API (cpl_recode.cpp). */
257 /* -------------------------------------------------------------------- */
259 #define CPL_ENC_LOCALE ""
260 
261 #define CPL_ENC_UTF8 "UTF-8"
262 
263 #define CPL_ENC_UTF16 "UTF-16"
264 
265 #define CPL_ENC_UCS2 "UCS-2"
266 
267 #define CPL_ENC_UCS4 "UCS-4"
268 
269 #define CPL_ENC_ASCII "ASCII"
270 
271 #define CPL_ENC_ISO8859_1 "ISO-8859-1"
272 
273 int CPL_DLL CPLEncodingCharSize( const char *pszEncoding );
275 void CPL_DLL CPLClearRecodeWarningFlags( void );
277 char CPL_DLL *CPLRecode(
278  const char *pszSource, const char *pszSrcEncoding,
279  const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
280 char CPL_DLL *CPLRecodeFromWChar(
281  const wchar_t *pwszSource, const char *pszSrcEncoding,
282  const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
283 wchar_t CPL_DLL *CPLRecodeToWChar(
284  const char *pszSource, const char *pszSrcEncoding,
285  const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
286 int CPL_DLL CPLIsUTF8( const char* pabyData, int nLen );
287 char CPL_DLL *CPLForceToASCII(
288  const char* pabyData, int nLen,
289  char chReplacementChar ) CPL_WARN_UNUSED_RESULT;
290 int CPL_DLL CPLStrlenUTF8( const char *pszUTF8Str );
291 CPL_C_END
292 
293 /************************************************************************/
294 /* CPLString */
295 /************************************************************************/
296 
297 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
298 
299 extern "C++"
300 {
301 #ifndef DOXYGEN_SKIP
302 #include <string>
303 #endif
304 
305 // VC++ implicitly applies __declspec(dllexport) to template base
306 // classes of classes marked with __declspec(dllexport).
307 // Hence, VC++ would export symbols for the specialization of std::basic_string<char>,
308 // since it is a base class of CPLString, which is marked with CPL_DLL.
309 // As a result, if an application linked both gdal.dll and a static library that
310 // (implicitly) instantiates std::string (almost all do!), then the linker would
311 // emit an error concerning duplicate symbols for std::string.
312 // The least intrusive solution is to turn CPLString into a template class
313 // (that is not marked with CPL_DLL), make CPLString a typedef for a specialization
314 // of that template class, and mark only the few non-inline member functions of
315 // CPLStringT with CPL_DLL.
316 #ifdef _MSC_VER
317 
318 # define CPLSTRING_DLL CPL_DLL
319 
320 template< class Dummy = void > class CPLStringT;
321 typedef CPLStringT<> CPLString;
322 
323 template< class Dummy >
324 class CPLStringT : public std::string
325 
326 #else
327 
329 # define CPLSTRING_DLL
330 # define CPLStringT CPLString
331 
333 class CPL_DLL CPLString : public std::string
335 
336 #endif
337 {
338 public:
339 
341  CPLStringT(void) {}
343  // cppcheck-suppress noExplicitConstructor
344  CPLStringT( const std::string &oStr ) : std::string( oStr ) {}
346  // cppcheck-suppress noExplicitConstructor
347  CPLStringT( const char *pszStr ) : std::string( pszStr ) {}
349  CPLStringT( const char *pszStr, size_t n ) : std::string( pszStr, n ) {}
350 
352  operator const char* (void) const { return c_str(); }
353 
355  char& operator[](std::string::size_type i)
356  {
357  return std::string::operator[](i);
358  }
359 
361  const char& operator[](std::string::size_type i) const
362  {
363  return std::string::operator[](i);
364  }
365 
367  char& operator[](int i)
368  {
369  return std::string::operator[](
370  static_cast<std::string::size_type>(i));
371  }
372 
374  const char& operator[](int i) const
375  {
376  return std::string::operator[](
377  static_cast<std::string::size_type>(i));
378  }
379 
381  void Clear() { resize(0); }
382 
386  void Seize( char *pszValue )
387  {
388  if (pszValue == nullptr )
389  Clear();
390  else
391  {
392  *this = pszValue;
393  CPLFree(pszValue);
394  }
395  }
396 
397  /* There seems to be a bug in the way the compiler count indices...
398  * Should be CPL_PRINT_FUNC_FORMAT (1, 2) */
399  CPLSTRING_DLL CPLString &Printf(
400  CPL_FORMAT_STRING(const char *pszFormat), ... )
401  CPL_PRINT_FUNC_FORMAT (2, 3);
402  CPLSTRING_DLL CPLString &vPrintf(
403  CPL_FORMAT_STRING(const char *pszFormat), va_list args )
404  CPL_PRINT_FUNC_FORMAT(2, 0);
405  CPLSTRING_DLL CPLString &FormatC( double dfValue, const char *pszFormat = nullptr );
406  CPLSTRING_DLL CPLString &Trim();
407  CPLSTRING_DLL CPLString &Recode( const char *pszSrcEncoding, const char *pszDstEncoding );
408  CPLSTRING_DLL CPLString &replaceAll(
409  const std::string &osBefore, const std::string& osAfter );
410  CPLSTRING_DLL CPLString &replaceAll( const std::string &osBefore, char chAfter );
411  CPLSTRING_DLL CPLString &replaceAll( char chBefore, const std::string &osAfter );
412  CPLSTRING_DLL CPLString &replaceAll( char chBefore, char chAfter );
413 
414  /* case insensitive find alternates */
415  CPLSTRING_DLL size_t ifind( const std::string & str, size_t pos = 0 ) const;
416  CPLSTRING_DLL size_t ifind( const char * s, size_t pos = 0 ) const;
417  CPLSTRING_DLL CPLString &toupper( void );
418  CPLSTRING_DLL CPLString &tolower( void );
419 
420  CPLSTRING_DLL bool endsWith( const std::string& osStr ) const;
421 };
422 
423 #ifndef _MSC_VER
424 # undef CPLStringT
425 #endif
426 
427 CPLString CPL_DLL CPLOPrintf(CPL_FORMAT_STRING(const char *pszFormat), ... )
428  CPL_PRINT_FUNC_FORMAT (1, 2);
429 CPLString CPL_DLL CPLOvPrintf(
430  CPL_FORMAT_STRING(const char *pszFormat), va_list args)
431  CPL_PRINT_FUNC_FORMAT (1, 0);
432 
433 /* -------------------------------------------------------------------- */
434 /* URL processing functions, here since they depend on CPLString. */
435 /* -------------------------------------------------------------------- */
436 CPLString CPL_DLL CPLURLGetValue(const char* pszURL, const char* pszKey);
437 CPLString CPL_DLL CPLURLAddKVP(const char* pszURL, const char* pszKey,
438  const char* pszValue);
439 
440 /************************************************************************/
441 /* CPLStringList */
442 /************************************************************************/
443 
445 class CPL_DLL CPLStringList
446 {
447  char **papszList;
448  mutable int nCount;
449  mutable int nAllocation;
450  bool bOwnList;
451  bool bIsSorted;
452 
453  void Initialize();
454  void MakeOurOwnCopy();
455  void EnsureAllocation( int nMaxLength );
456  int FindSortedInsertionPoint( const char *pszLine );
457 
458  public:
459  CPLStringList();
460  CPLStringList( char **papszList, int bTakeOwnership=TRUE );
461  // cppcheck-suppress noExplicitConstructor
462  CPLStringList( CSLConstList papszList );
463  CPLStringList( const CPLStringList& oOther );
464  ~CPLStringList();
465 
466  CPLStringList &Clear();
467 
469  int size() const { return Count(); }
470  int Count() const;
471 
473  bool empty() const { return Count() == 0; }
474 
475  CPLStringList &AddString( const char *pszNewString );
476  CPLStringList &AddStringDirectly( char *pszNewString );
477 
478  CPLStringList &InsertString( int nInsertAtLineNo, const char *pszNewLine )
479  { return InsertStringDirectly( nInsertAtLineNo, CPLStrdup(pszNewLine) ); }
480  CPLStringList &InsertStringDirectly( int nInsertAtLineNo, char *pszNewLine);
481 
482  // CPLStringList &InsertStrings( int nInsertAtLineNo, char **papszNewLines );
483  // CPLStringList &RemoveStrings( int nFirstLineToDelete, int nNumToRemove=1 );
484 
486  int FindString( const char *pszTarget ) const
487  { return CSLFindString( papszList, pszTarget ); }
489  int PartialFindString( const char *pszNeedle ) const
490  { return CSLPartialFindString( papszList, pszNeedle ); }
491 
492  int FindName( const char *pszName ) const;
493  bool FetchBool( const char *pszKey, bool bDefault ) const;
494  // Deprecated.
495  int FetchBoolean( const char *pszKey, int bDefault ) const;
496  const char *FetchNameValue( const char *pszKey ) const;
497  const char *FetchNameValueDef(
498  const char *pszKey, const char *pszDefault ) const;
499  CPLStringList &AddNameValue( const char *pszKey, const char *pszValue );
500  CPLStringList &SetNameValue( const char *pszKey, const char *pszValue );
501 
502  CPLStringList &Assign( char **papszListIn, int bTakeOwnership=TRUE );
504  CPLStringList &operator=(char **papszListIn) {
505  return Assign( papszListIn, TRUE ); }
507  CPLStringList &operator=(const CPLStringList& oOther);
509  CPLStringList &operator=(CSLConstList papszListIn);
510 
512  char * operator[](int i);
514  char * operator[](size_t i) { return (*this)[static_cast<int>(i)]; }
516  const char * operator[](int i) const;
518  const char * operator[](size_t i) const {
519  return (*this)[static_cast<int>(i)]; }
521  const char * operator[](const char* pszKey) const {
522  return FetchNameValue(pszKey); }
523 
525  char** List() { return papszList; }
527  CSLConstList List() const { return papszList; }
528  char **StealList();
529 
530  CPLStringList &Sort();
532  int IsSorted() const { return bIsSorted; }
533 
535  operator char**(void) { return List(); }
537  operator CSLConstList(void) const { return List(); }
538 };
539 
540 #ifdef GDAL_COMPILATION
541 
542 #include <memory>
543 
545 struct CSLDestroyReleaser
546 {
547  void operator()(char** papszStr) const { CSLDestroy(papszStr); }
548 };
552 using CSLUniquePtr = std::unique_ptr< char*, CSLDestroyReleaser>;
553 
554 #endif
555 
556 } // extern "C++"
557 
558 #endif /* def __cplusplus && !CPL_SUPRESS_CPLUSPLUS */
559 
560 #endif /* CPL_STRING_H_INCLUDED */
int CPLEncodingCharSize(const char *pszEncoding)
Return bytes per character for encoding.
Definition: cpl_recode.cpp:318
int CSLFindName(CSLConstList papszStrList, const char *pszName)
Find StringList entry with given key name.
Definition: cpl_string.cpp:1708
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:2754
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:759
int CSLTestBoolean(const char *pszValue)
Test what boolean value contained in the string.
Definition: cpl_string.cpp:1553
bool empty() const
Return whether the list is empty.
Definition: cpl_string.h:473
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:341
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:381
GByte * CPLHexToBinary(const char *pszHex, int *pnBytes) CPL_WARN_UNUSED_RESULT
Hexadecimal to binary translation.
Definition: cpl_string.cpp:2526
char ** CSLLoad2(const char *pszFname, int nMaxLines, int nMaxCols, CSLConstList papszOptions) CPL_WARN_UNUSED_RESULT
Load a text file into a string list.
Definition: cpl_string.cpp:316
int CSLCount(CSLConstList papszStrList)
Return number of items in a string list.
Definition: cpl_string.cpp:147
int CPLBase64DecodeInPlace(GByte *pszBase64) CPL_WARN_UNUSED_RESULT
Decode base64 string "pszBase64" (null terminated) in place.
Definition: cpl_base64.cpp:93
CPLString CPLOPrintf(const char *pszFormat,...)
Return a CPLString with the content of sprintf()
Definition: cplstring.cpp:526
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
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:443
const char * CPLSPrintf(const char *fmt,...) CPL_WARN_UNUSED_RESULT
CPLSPrintf() that works with 10 static buffer.
Definition: cpl_string.cpp:977
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:1029
CPLValueType
Type of value.
Definition: cpl_string.h:194
const char * CSLFetchNameValueDef(CSLConstList papszStrList, const char *pszName, const char *pszDefault)
Same as CSLFetchNameValue() but return pszDefault in case of no match.
Definition: cpl_string.cpp:1646
Real number.
Definition: cpl_string.h:197
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:213
char ** CSLSetNameValue(char **papszStrList, const char *pszName, const char *pszValue) CPL_WARN_UNUSED_RESULT
Assign value to name in StringList.
Definition: cpl_string.cpp:1877
int FindString(const char *pszTarget) const
Return index of pszTarget in the list, or -1.
Definition: cpl_string.h:486
const char * CSLGetField(CSLConstList, int)
Fetches the indicated field, being careful not to crash if the field doesn't exist within this string...
Definition: cpl_string.cpp:173
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:83
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:562
char & operator[](int i)
Return character at specified index.
Definition: cpl_string.h:367
int PartialFindString(const char *pszNeedle) const
Return index of pszTarget in the list (using partial search), or -1.
Definition: cpl_string.h:489
Convenient string class based on std::string.
Definition: cpl_string.h:334
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:1838
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition: cpl_port.h:910
size_t CPLStrlcpy(char *pszDest, const char *pszSrc, size_t nDestSize)
Copy source string to a destination buffer.
Definition: cpl_string.cpp:2697
char * CPLStrdup(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL
Safe version of strdup() function.
Definition: cpl_conv.cpp:292
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:2032
int IsSorted() const
Returns whether the list is sorted.
Definition: cpl_string.h:532
char ** CSLFetchNameValueMultiple(CSLConstList papszStrList, const char *pszName)
In a StringList of "Name=Value" pairs, look for all the values with the specified name...
Definition: cpl_string.cpp:1801
int CSLPrint(CSLConstList papszStrList, FILE *fpOut)
Print a StringList to fpOut.
Definition: cpl_string.cpp:461
int CSLPartialFindString(CSLConstList papszHaystack, const char *pszNeedle)
Find a substring within a string list.
Definition: cpl_string.cpp:737
CPLStringT(const char *pszStr)
Constructor.
Definition: cpl_string.h:347
char ** CSLInsertStrings(char **papszStrList, int nInsertAtLineNo, CSLConstList papszNewLines) CPL_WARN_UNUSED_RESULT
Copies the contents of a StringList inside another StringList before the specified line...
Definition: cpl_string.cpp:497
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:1957
CPLStringList & operator=(char **papszListIn)
Assignment operator.
Definition: cpl_string.h:504
const char * operator[](const char *pszKey) const
Return value corresponding to pszKey, or nullptr.
Definition: cpl_string.h:521
CPL error handling services.
int CPLprintf(const char *fmt,...)
printf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1393
void Seize(char *pszValue)
Assign specified string and take ownership of it (assumed to be allocated with CPLMalloc()).
Definition: cpl_string.h:386
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1190
char ** CSLLoad(const char *pszFname) CPL_WARN_UNUSED_RESULT
Load a text file into a string list.
Definition: cpl_string.cpp:397
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:445
char * CPLBinaryToHex(int nBytes, const GByte *pabyData) CPL_WARN_UNUSED_RESULT
Binary to hexadecimal translation.
Definition: cpl_string.cpp:2468
CPLStringT(const char *pszStr, size_t n)
Constructor.
Definition: cpl_string.h:349
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:92
bool CPLFetchBool(CSLConstList papszStrList, const char *pszKey, bool bDefault)
Check for boolean key value.
Definition: cpl_string.cpp:1600
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:81
int size() const
Return size of list.
Definition: cpl_string.h:469
CSLConstList List() const
Return list.
Definition: cpl_string.h:527
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:2565
Various convenience functions for CPL.
CPLStringT(const std::string &oStr)
Constructor.
Definition: cpl_string.h:344
int CPLsnprintf(char *str, size_t size, const char *fmt,...)
snprintf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1337
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:1140
int CPLTestBoolean(const char *pszValue)
Test what boolean value contained in the string.
Definition: cpl_string.cpp:1575
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:2789
const char * operator[](size_t i) const
Return string at specified index.
Definition: cpl_string.h:518
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:1048
CPLSTRING_DLL CPLString & Printf(const char *pszFormat,...)
Assign the content of the string using sprintf()
Definition: cplstring.cpp:67
#define CPL_FORMAT_STRING(arg)
Macro into which to wrap the format argument of a printf-like function.
Definition: cpl_port.h:925
CPLStringList & InsertString(int nInsertAtLineNo, const char *pszNewLine)
Insert into the list at identified location.
Definition: cpl_string.h:478
CPLString CPLURLAddKVP(const char *pszURL, const char *pszKey, const char *pszValue)
Return a new URL with a new key=value pair.
Definition: cplstring.cpp:476
String.
Definition: cpl_string.h:196
char & operator[](std::string::size_type i)
Return character at specified index.
Definition: cpl_string.h:355
#define CPL_RETURNS_NONNULL
Qualifier for a function that does not return NULL.
Definition: cpl_port.h:968
#define CPL_SCANF_FORMAT_STRING(arg)
Macro into which to wrap the format argument of a sscanf-like function.
Definition: cpl_port.h:927
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:343
int CSLSave(CSLConstList papszStrList, const char *pszFname)
Write a StringList to a text file.
Definition: cpl_string.cpp:412
const char & operator[](std::string::size_type i) const
Return character at specified index.
Definition: cpl_string.h:361
char ** CSLDuplicate(CSLConstList papszStrList) CPL_WARN_UNUSED_RESULT
Clone a string list.
Definition: cpl_string.cpp:228
char ** List()
Return list.
Definition: cpl_string.h:525
char ** CSLTokenizeString2(const char *pszString, const char *pszDelimiter, int nCSLTFlags) CPL_WARN_UNUSED_RESULT
Tokenize a string.
Definition: cpl_string.cpp:836
#define CPL_SCAN_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have scanf() formatting.
Definition: cpl_port.h:912
bool CPLTestBool(const char *pszValue)
Test what boolean value contained in the string.
Definition: cpl_string.cpp:1526
int CSLFindString(CSLConstList papszList, const char *pszTarget)
Find a string within a string list (case insensitive).
Definition: cpl_string.cpp:670
int CSLFindStringCaseSensitive(CSLConstList papszList, const char *pszTarget)
Find a string within a string list(case sensitive)
Definition: cpl_string.cpp:704
const char * CPLParseNameValue(const char *pszNameValue, char **ppszKey)
Parse NAME=VALUE string into name and value components.
Definition: cpl_string.cpp:1754
const char * CSLFetchNameValue(CSLConstList 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:1674
char ** CSLMerge(char **papszOrig, CSLConstList papszOverride) CPL_WARN_UNUSED_RESULT
Merge two lists.
Definition: cpl_string.cpp:268
CPLString CPLOvPrintf(const char *pszFormat, va_list args)
Return a CPLString with the content of vsprintf()
Definition: cplstring.cpp:545
const char & operator[](int i) const
Return character at specified index.
Definition: cpl_string.h:374
void CSLDestroy(char **papszStrList)
Free string list.
Definition: cpl_string.cpp:200
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:2242
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:2813
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:514
char ** CSLTokenizeStringComplex(const char *pszString, const char *pszDelimiter, int bHonourStrings, int bAllowEmptyTokens) CPL_WARN_UNUSED_RESULT
Obsolete tokenizing api.
Definition: cpl_string.cpp:769
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition: cpl_port.h:935
CPLStringT(void)
Constructor.
Definition: cpl_string.h:341
Integer.
Definition: cpl_string.h:198
int CSLFetchBoolean(CSLConstList papszStrList, const char *pszKey, int bDefault)
DEPRECATED.
Definition: cpl_string.cpp:1635
char ** CSLRemoveStrings(char **papszStrList, int nFirstLineToDelete, int nNumToRemove, char ***ppapszRetStrings) CPL_WARN_UNUSED_RESULT
Remove strings inside a StringList.
Definition: cpl_string.cpp:588

Generated for GDAL by doxygen 1.8.8.