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 spatialys.com>
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
39 #include <stdbool.h>
40
63 CPL_C_START
64
65 char CPL_DLL **CSLAddString(char **papszStrList,
66 const char *pszNewString) CPL_WARN_UNUSED_RESULT;
67 char CPL_DLL **CSLAddStringMayFail(
68 char **papszStrList, const char *pszNewString) CPL_WARN_UNUSED_RESULT;
69 int CPL_DLL CSLCount(CSLConstList papszStrList);
70 const char CPL_DLL *CSLGetField( CSLConstList, int );
71 void CPL_DLL CPL_STDCALL CSLDestroy(char **papszStrList);
72 char CPL_DLL **CSLDuplicate(CSLConstList papszStrList) CPL_WARN_UNUSED_RESULT;
73 char CPL_DLL **CSLMerge( char **papszOrig,
74 CSLConstList papszOverride ) CPL_WARN_UNUSED_RESULT;
75
76 char CPL_DLL **CSLTokenizeString(const char *pszString ) CPL_WARN_UNUSED_RESULT;
77 char CPL_DLL **CSLTokenizeStringComplex(
78 const char *pszString, const char *pszDelimiter, int bHonourStrings,
79 int bAllowEmptyTokens ) CPL_WARN_UNUSED_RESULT;
80 char CPL_DLL **CSLTokenizeString2( const char *pszString,
81 const char *pszDelimiter,
82 int nCSLTFlags ) CPL_WARN_UNUSED_RESULT;
83
85 #define CSLT_HONOURSTRINGS 0x0001
86
87 #define CSLT_ALLOWEMPTYTOKENS 0x0002
88
89 #define CSLT_PRESERVEQUOTES 0x0004
90
91 #define CSLT_PRESERVEESCAPES 0x0008
92
93 #define CSLT_STRIPLEADSPACES 0x0010
94
95 #define CSLT_STRIPENDSPACES 0x0020
96
97 int CPL_DLL CSLPrint(CSLConstList papszStrList, FILE *fpOut);
98 char CPL_DLL **CSLLoad(const char *pszFname) CPL_WARN_UNUSED_RESULT;
99 char CPL_DLL **CSLLoad2(
100 const char *pszFname, int nMaxLines, int nMaxCols,
101 CSLConstList papszOptions) CPL_WARN_UNUSED_RESULT;
102 int CPL_DLL CSLSave(CSLConstList papszStrList, const char *pszFname);
103
104 char CPL_DLL **CSLInsertStrings(char **papszStrList, int nInsertAtLineNo,
105 CSLConstList papszNewLines) CPL_WARN_UNUSED_RESULT;
106 char CPL_DLL **CSLInsertString(char **papszStrList, int nInsertAtLineNo,
107 const char *pszNewLine) CPL_WARN_UNUSED_RESULT;
108 char CPL_DLL **CSLRemoveStrings(
109 char **papszStrList, int nFirstLineToDelete,
110 int nNumToRemove, char ***ppapszRetStrings) CPL_WARN_UNUSED_RESULT;
111 int CPL_DLL CSLFindString( CSLConstList papszList, const char *pszTarget );
112 int CPL_DLL CSLFindStringCaseSensitive( CSLConstList papszList,
113 const char *pszTarget );
114 int CPL_DLL CSLPartialFindString( CSLConstList papszHaystack,
115 const char *pszNeedle );
116 int CPL_DLL CSLFindName(CSLConstList papszStrList, const char *pszName);
117 int CPL_DLL CSLFetchBoolean( CSLConstList papszStrList, const char *pszKey,
118 int bDefault );
119
120 /* TODO: Deprecate CSLTestBoolean. Remove in GDAL 3.x. */
121 int CPL_DLL CSLTestBoolean( const char *pszValue );
122 /* Do not use CPLTestBoolean in C++ code. Use CPLTestBool. */
123 int CPL_DLL CPLTestBoolean( const char *pszValue );
124
125 bool CPL_DLL CPLTestBool( const char *pszValue );
126 bool CPL_DLL CPLFetchBool( CSLConstList papszStrList, const char *pszKey,
127 bool bDefault );
128
129 const char CPL_DLL *
130 CPLParseNameValue( const char *pszNameValue, char **ppszKey );
131
132 const char CPL_DLL *
133 CSLFetchNameValue( CSLConstList papszStrList, const char *pszName);
134 const char CPL_DLL *
135 CSLFetchNameValueDef( CSLConstList papszStrList,
136 const char *pszName,
137 const char *pszDefault );
138 char CPL_DLL **
139 CSLFetchNameValueMultiple(CSLConstList papszStrList, const char *pszName);
140 char CPL_DLL **
141 CSLAddNameValue(char **papszStrList,
142 const char *pszName,
143 const char *pszValue) CPL_WARN_UNUSED_RESULT;
144 char CPL_DLL **
145 CSLSetNameValue(char **papszStrList,
146 const char *pszName,
147 const char *pszValue) CPL_WARN_UNUSED_RESULT;
148 void CPL_DLL CSLSetNameValueSeparator( char ** papszStrList,
149 const char *pszSeparator );
150
151 char CPL_DLL ** CSLParseCommandLine(const char* pszCommandLine);
152
154 #define CPLES_BackslashQuotable 0
155
156 #define CPLES_XML 1
157
158 #define CPLES_URL 2
159
160 #define CPLES_SQL 3
161
162 #define CPLES_CSV 4
163
164 #define CPLES_XML_BUT_QUOTES 5
165
166 #define CPLES_CSV_FORCE_QUOTING 6
167
168 #define CPLES_SQLI 7
169
170 char CPL_DLL *CPLEscapeString( const char *pszString, int nLength,
171 int nScheme ) CPL_WARN_UNUSED_RESULT;
172 char CPL_DLL *CPLUnescapeString( const char *pszString, int *pnLength,
173 int nScheme ) CPL_WARN_UNUSED_RESULT;
174
175 char CPL_DLL *CPLBinaryToHex( int nBytes,
176 const GByte *pabyData ) CPL_WARN_UNUSED_RESULT;
177 GByte CPL_DLL *CPLHexToBinary( const char *pszHex,
178 int *pnBytes ) CPL_WARN_UNUSED_RESULT;
179
180 char CPL_DLL *CPLBase64Encode( int nBytes,
181 const GByte *pabyData ) CPL_WARN_UNUSED_RESULT;
182 int CPL_DLL CPLBase64DecodeInPlace( GByte* pszBase64 ) CPL_WARN_UNUSED_RESULT;
183
185 typedef enum
186 {
187 CPL_VALUE_STRING,
188 CPL_VALUE_REAL,
189 CPL_VALUE_INTEGER
190 } CPLValueType;
191
192 CPLValueType CPL_DLL CPLGetValueType(const char* pszValue);
193
194 size_t CPL_DLL CPLStrlcpy(char* pszDest, const char* pszSrc, size_t nDestSize);
195 size_t CPL_DLL CPLStrlcat(char* pszDest, const char* pszSrc, size_t nDestSize);
196 size_t CPL_DLL CPLStrnlen(const char *pszStr, size_t nMaxLen);
197
198 /* -------------------------------------------------------------------- */
199 /* Locale independent formatting functions. */
200 /* -------------------------------------------------------------------- */
201 int CPL_DLL CPLvsnprintf( char *str, size_t size,
202 CPL_FORMAT_STRING(const char* fmt),
203 va_list args )
204 CPL_PRINT_FUNC_FORMAT(3, 0 );
205
206 /* ALIAS_CPLSNPRINTF_AS_SNPRINTF might be defined to enable GCC 7 */
207 /* -Wformat-truncation= warnings, but shouldn't be set for normal use */
208 #if defined(ALIAS_CPLSNPRINTF_AS_SNPRINTF)
209 #define CPLsnprintf snprintf
210 #else
211 int CPL_DLL CPLsnprintf( char *str, size_t size,
212 CPL_FORMAT_STRING(const char* fmt), ... )
213 CPL_PRINT_FUNC_FORMAT(3, 4);
214 #endif
215
217 #if defined(GDAL_COMPILATION) && !defined(DONT_DEPRECATE_SPRINTF)
218 int CPL_DLL CPLsprintf( char *str, CPL_FORMAT_STRING(const char* fmt), ... )
219 CPL_PRINT_FUNC_FORMAT(2, 3)
220 CPL_WARN_DEPRECATED("Use CPLsnprintf instead");
221 #else
222 int CPL_DLL CPLsprintf( char *str, CPL_FORMAT_STRING(const char* fmt), ... )
223 CPL_PRINT_FUNC_FORMAT(2, 3);
224 #endif
225
226 int CPL_DLL CPLprintf( CPL_FORMAT_STRING(const char* fmt), ... )
227 CPL_PRINT_FUNC_FORMAT(1, 2);
228
229 /* For some reason Doxygen_Suppress is needed to avoid warning. Not sure why */
231 /* caution: only works with limited number of formats */
232 int CPL_DLL CPLsscanf( const char* str,
233 CPL_SCANF_FORMAT_STRING(const char* fmt), ... )
234 CPL_SCAN_FUNC_FORMAT(2, 3);
237 const char CPL_DLL *CPLSPrintf( CPL_FORMAT_STRING(const char *fmt), ... )
238 CPL_PRINT_FUNC_FORMAT(1, 2) CPL_WARN_UNUSED_RESULT;
239 char CPL_DLL **CSLAppendPrintf( char **papszStrList,
240 CPL_FORMAT_STRING(const char *fmt), ... )
241 CPL_PRINT_FUNC_FORMAT(2, 3) CPL_WARN_UNUSED_RESULT;
242 int CPL_DLL CPLVASPrintf( char **buf,
243 CPL_FORMAT_STRING(const char *fmt), va_list args )
244 CPL_PRINT_FUNC_FORMAT(2, 0);
245
246 /* -------------------------------------------------------------------- */
247 /* RFC 23 character set conversion/recoding API (cpl_recode.cpp). */
248 /* -------------------------------------------------------------------- */
250 #define CPL_ENC_LOCALE ""
251
252 #define CPL_ENC_UTF8 "UTF-8"
253
254 #define CPL_ENC_UTF16 "UTF-16"
255
256 #define CPL_ENC_UCS2 "UCS-2"
257
258 #define CPL_ENC_UCS4 "UCS-4"
259
260 #define CPL_ENC_ASCII "ASCII"
261
262 #define CPL_ENC_ISO8859_1 "ISO-8859-1"
263
264 int CPL_DLL CPLEncodingCharSize( const char *pszEncoding );
266 void CPL_DLL CPLClearRecodeWarningFlags( void );
268 char CPL_DLL *CPLRecode(
269 const char *pszSource, const char *pszSrcEncoding,
270 const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
271 char CPL_DLL *CPLRecodeFromWChar(
272 const wchar_t *pwszSource, const char *pszSrcEncoding,
273 const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
274 wchar_t CPL_DLL *CPLRecodeToWChar(
275 const char *pszSource, const char *pszSrcEncoding,
276 const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
277 int CPL_DLL CPLIsUTF8( const char* pabyData, int nLen );
278 bool CPL_DLL CPLIsASCII( const char* pabyData, size_t nLen );
279 char CPL_DLL *CPLForceToASCII(
280 const char* pabyData, int nLen,
281 char chReplacementChar ) CPL_WARN_UNUSED_RESULT;
282 int CPL_DLL CPLStrlenUTF8( const char *pszUTF8Str );
283 int CPL_DLL CPLCanRecode(
284 const char *pszTestStr, const char *pszSrcEncoding,
285 const char *pszDstEncoding) CPL_WARN_UNUSED_RESULT;
286 CPL_C_END
287
288 /************************************************************************/
289 /* CPLString */
290 /************************************************************************/
291
292 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
293
294 extern "C++"
295 {
296 #ifndef DOXYGEN_SKIP
297 #include <string>
298 #endif
299
300 // VC++ implicitly applies __declspec(dllexport) to template base classes
301 // of classes marked with __declspec(dllexport).
302 // Hence, if marked with CPL_DLL, VC++ would export symbols for the specialization
303 // of std::basic_string<char>, since it is a base class of CPLString.
304 // As a result, if an application linked both gdal.dll and a static library that
305 // (implicitly) instantiates std::string (almost all do!), then the linker would
306 // emit an error concerning duplicate symbols for std::string.
307 // The least intrusive solution is to not mark the whole class with
308 // __declspec(dllexport) for VC++, but only its non-inline methods.
309 #ifdef _MSC_VER
310 # define CPLSTRING_CLASS_DLL
311 # define CPLSTRING_METHOD_DLL CPL_DLL
312 #else
313
314 # define CPLSTRING_CLASS_DLL CPL_DLL
315 # define CPLSTRING_METHOD_DLL
316
317 #endif
318
320 class CPLSTRING_CLASS_DLL CPLString : public std::string
321 {
322 public:
323
325 CPLString(void) {}
327 // cppcheck-suppress noExplicitConstructor
328 CPLString( const std::string &oStr ) : std::string( oStr ) {}
330 // cppcheck-suppress noExplicitConstructor
331 CPLString( const char *pszStr ) : std::string( pszStr ) {}
333 CPLString( const char *pszStr, size_t n ) : std::string( pszStr, n ) {}
334
336 operator const char* (void) const { return c_str(); }
337
339 char& operator[](std::string::size_type i)
340 {
341 return std::string::operator[](i);
342 }
343
345 const char& operator[](std::string::size_type i) const
346 {
347 return std::string::operator[](i);
348 }
349
351 char& operator[](int i)
352 {
353 return std::string::operator[](
354 static_cast<std::string::size_type>(i));
355 }
356
358 const char& operator[](int i) const
359 {
360 return std::string::operator[](
361 static_cast<std::string::size_type>(i));
362 }
363
365 void Clear() { resize(0); }
366
370 void Seize( char *pszValue )
371 {
372 if (pszValue == nullptr )
373 Clear();
374 else
375 {
376 *this = pszValue;
377 CPLFree(pszValue);
378 }
379 }
380
381 /* There seems to be a bug in the way the compiler count indices...
382 * Should be CPL_PRINT_FUNC_FORMAT (1, 2) */
383 CPLSTRING_METHOD_DLL CPLString &Printf(
384 CPL_FORMAT_STRING(const char *pszFormat), ... )
385 CPL_PRINT_FUNC_FORMAT (2, 3);
386 CPLSTRING_METHOD_DLL CPLString &vPrintf(
387 CPL_FORMAT_STRING(const char *pszFormat), va_list args )
388 CPL_PRINT_FUNC_FORMAT(2, 0);
389 CPLSTRING_METHOD_DLL CPLString &FormatC( double dfValue, const char *pszFormat = nullptr );
390 CPLSTRING_METHOD_DLL CPLString &Trim();
391 CPLSTRING_METHOD_DLL CPLString &Recode( const char *pszSrcEncoding, const char *pszDstEncoding );
392 CPLSTRING_METHOD_DLL CPLString &replaceAll(
393 const std::string &osBefore, const std::string& osAfter );
394 CPLSTRING_METHOD_DLL CPLString &replaceAll( const std::string &osBefore, char chAfter );
395 CPLSTRING_METHOD_DLL CPLString &replaceAll( char chBefore, const std::string &osAfter );
396 CPLSTRING_METHOD_DLL CPLString &replaceAll( char chBefore, char chAfter );
397
398 /* case insensitive find alternates */
399 CPLSTRING_METHOD_DLL size_t ifind( const std::string & str, size_t pos = 0 ) const;
400 CPLSTRING_METHOD_DLL size_t ifind( const char * s, size_t pos = 0 ) const;
401 CPLSTRING_METHOD_DLL CPLString &toupper( void );
402 CPLSTRING_METHOD_DLL CPLString &tolower( void );
403
404 CPLSTRING_METHOD_DLL bool endsWith( const std::string& osStr ) const;
405 };
406
407 #undef CPLSTRING_CLASS_DLL
408 #undef CPLSTRING_METHOD_DLL
409
410 CPLString CPL_DLL CPLOPrintf(CPL_FORMAT_STRING(const char *pszFormat), ... )
411 CPL_PRINT_FUNC_FORMAT (1, 2);
412 CPLString CPL_DLL CPLOvPrintf(
413 CPL_FORMAT_STRING(const char *pszFormat), va_list args)
414 CPL_PRINT_FUNC_FORMAT (1, 0);
415 CPLString CPL_DLL CPLQuotedSQLIdentifier(const char *pszIdent);
416
417 /* -------------------------------------------------------------------- */
418 /* URL processing functions, here since they depend on CPLString. */
419 /* -------------------------------------------------------------------- */
420 CPLString CPL_DLL CPLURLGetValue(const char* pszURL, const char* pszKey);
421 CPLString CPL_DLL CPLURLAddKVP(const char* pszURL, const char* pszKey,
422 const char* pszValue);
423
424 /************************************************************************/
425 /* CPLStringList */
426 /************************************************************************/
427
429 class CPL_DLL CPLStringList
430 {
431 char **papszList = nullptr;
432 mutable int nCount = 0;
433 mutable int nAllocation = 0;
434 bool bOwnList = false;
435 bool bIsSorted = false;
436
437 bool MakeOurOwnCopy();
438 bool EnsureAllocation( int nMaxLength );
439 int FindSortedInsertionPoint( const char *pszLine );
440
441 public:
442 CPLStringList();
443 explicit CPLStringList( char **papszList, int bTakeOwnership=TRUE );
444 explicit CPLStringList( CSLConstList papszList );
445 CPLStringList( const CPLStringList& oOther );
446 CPLStringList( CPLStringList&& oOther );
447 ~CPLStringList();
448
449 CPLStringList &Clear();
450
452 int size() const { return Count(); }
453 int Count() const;
454
456 bool empty() const { return Count() == 0; }
457
458 CPLStringList &AddString( const char *pszNewString );
459 CPLStringList &AddStringDirectly( char *pszNewString );
460
461 CPLStringList &InsertString( int nInsertAtLineNo, const char *pszNewLine )
462 { return InsertStringDirectly( nInsertAtLineNo, CPLStrdup(pszNewLine) ); }
463 CPLStringList &InsertStringDirectly( int nInsertAtLineNo, char *pszNewLine);
464
465 // CPLStringList &InsertStrings( int nInsertAtLineNo, char **papszNewLines );
466 // CPLStringList &RemoveStrings( int nFirstLineToDelete, int nNumToRemove=1 );
467
469 int FindString( const char *pszTarget ) const
470 { return CSLFindString( papszList, pszTarget ); }
472 int PartialFindString( const char *pszNeedle ) const
473 { return CSLPartialFindString( papszList, pszNeedle ); }
474
475 int FindName( const char *pszName ) const;
476 bool FetchBool( const char *pszKey, bool bDefault ) const;
477 // Deprecated.
478 int FetchBoolean( const char *pszKey, int bDefault ) const;
479 const char *FetchNameValue( const char *pszKey ) const;
480 const char *FetchNameValueDef(
481 const char *pszKey, const char *pszDefault ) const;
482 CPLStringList &AddNameValue( const char *pszKey, const char *pszValue );
483 CPLStringList &SetNameValue( const char *pszKey, const char *pszValue );
484
485 CPLStringList &Assign( char **papszListIn, int bTakeOwnership=TRUE );
487 CPLStringList &operator=(char **papszListIn) {
488 return Assign( papszListIn, TRUE ); }
490 CPLStringList &operator=(const CPLStringList& oOther);
492 CPLStringList &operator=(CSLConstList papszListIn);
494 CPLStringList &operator=(CPLStringList&& oOther);
495
497 char * operator[](int i);
499 char * operator[](size_t i) { return (*this)[static_cast<int>(i)]; }
501 const char * operator[](int i) const;
503 const char * operator[](size_t i) const {
504 return (*this)[static_cast<int>(i)]; }
506 const char * operator[](const char* pszKey) const {
507 return FetchNameValue(pszKey); }
508
510 char** List() { return papszList; }
512 CSLConstList List() const { return papszList; }
513 char **StealList();
514
515 CPLStringList &Sort();
517 int IsSorted() const { return bIsSorted; }
518
520 operator char**(void) { return List(); }
522 operator CSLConstList(void) const { return List(); }
523 };
524
525 #ifdef GDAL_COMPILATION
526
527 #include <memory>
528
530 struct CPL_DLL CSLDestroyReleaser
531 {
532 void operator()(char** papszStr) const { CSLDestroy(papszStr); }
533 };
537 using CSLUniquePtr = std::unique_ptr< char*, CSLDestroyReleaser>;
538
540 struct CPL_DLL CPLFreeReleaser
541 {
542 void operator()(void* p) const { CPLFree(p); }
543 };
547 using CPLCharUniquePtr = std::unique_ptr<char, CPLFreeReleaser>;
548
549 #endif
550
551 } // extern "C++"
552
553 #endif /* def __cplusplus && !CPL_SUPRESS_CPLUSPLUS */
554
555 #endif /* CPL_STRING_H_INCLUDED */
CSLLoad2
char ** CSLLoad2(const char *pszFname, int nMaxLines, int nMaxCols, CSLConstList papszOptions)
Load a text file into a string list.
Definition: cpl_string.cpp:322
CPLStringList::operator=
CPLStringList & operator=(char **papszListIn)
Assignment operator.
Definition: cpl_string.h:487
CPL_PRINT_FUNC_FORMAT
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition: cpl_port.h:844
CPLRecodeFromWChar
char * CPLRecodeFromWChar(const wchar_t *pwszSource, const char *pszSrcEncoding, const char *pszDstEncoding)
Convert wchar_t string to UTF-8.
Definition: cpl_recode.cpp:182
CSLInsertString
char ** CSLInsertString(char **papszStrList, int nInsertAtLineNo, const char *pszNewLine)
Insert a string at a given line number inside a StringList.
Definition: cpl_string.cpp:568
CSLTokenizeString2
char ** CSLTokenizeString2(const char *pszString, const char *pszDelimiter, int nCSLTFlags)
Tokenize a string.
Definition: cpl_string.cpp:842
CSLFindStringCaseSensitive
int CSLFindStringCaseSensitive(CSLConstList papszList, const char *pszTarget)
Find a string within a string list(case sensitive)
Definition: cpl_string.cpp:710
GByte
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:203
CPLString::CPLString
CPLString(const char *pszStr, size_t n)
Constructor.
Definition: cpl_string.h:333
cpl_error.h
CPLURLAddKVP
CPLString CPLURLAddKVP(const char *pszURL, const char *pszKey, const char *pszValue)
Return a new URL with a new key=value pair.
Definition: cplstring.cpp:454
CSLMerge
char ** CSLMerge(char **papszOrig, CSLConstList papszOverride)
Merge two lists.
Definition: cpl_string.cpp:274
CPLIsUTF8
int CPLIsUTF8(const char *pabyData, int nLen)
Test if a string is encoded as UTF-8.
Definition: cpl_recode.cpp:284
CPLEscapeString
char * CPLEscapeString(const char *pszString, int nLength, int nScheme)
Apply escaping to string to preserve special characters.
Definition: cpl_string.cpp:2056
CSLLoad
char ** CSLLoad(const char *pszFname)
Load a text file into a string list.
Definition: cpl_string.cpp:403
CPLOvPrintf
CPLString CPLOvPrintf(const char *pszFormat, va_list args)
Return a CPLString with the content of vsprintf()
Definition: cplstring.cpp:523
CPLStringList::InsertString
CPLStringList & InsertString(int nInsertAtLineNo, const char *pszNewLine)
Insert into the list at identified location.
Definition: cpl_string.h:461
CPLStrlcat
size_t CPLStrlcat(char *pszDest, const char *pszSrc, size_t nDestSize)
Appends a source string to a destination buffer.
Definition: cpl_string.cpp:2927
CPLStringList
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:429
CSLFindName
int CSLFindName(CSLConstList papszStrList, const char *pszName)
Find StringList entry with given key name.
Definition: cpl_string.cpp:1728
CPLGetValueType
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:2738
cpl_vsi.h
CSLFetchNameValueDef
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:1666
CSLSetNameValue
char ** CSLSetNameValue(char **papszStrList, const char *pszName, const char *pszValue)
Assign value to name in StringList.
Definition: cpl_string.cpp:1897
CPLsnprintf
int CPLsnprintf(char *str, size_t size, const char *fmt,...)
snprintf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1353
CSLAppendPrintf
char ** CSLAppendPrintf(char **papszStrList, const char *fmt,...)
Use CPLSPrintf() to append a new line at the end of a StringList.
Definition: cpl_string.cpp:1045
CSLCount
int CSLCount(CSLConstList papszStrList)
Return number of items in a string list.
Definition: cpl_string.cpp:148
CPLStringList::List
CSLConstList List() const
Return list.
Definition: cpl_string.h:512
CPLString
Convenient string class based on std::string.
Definition: cpl_string.h:320
CPLStringList::size
int size() const
Return size of list.
Definition: cpl_string.h:452
CPLFetchBool
bool CPLFetchBool(CSLConstList papszStrList, const char *pszKey, bool bDefault)
Check for boolean key value.
Definition: cpl_string.cpp:1620
CPL_VALUE_STRING
@ CPL_VALUE_STRING
String.
Definition: cpl_string.h:187
CSLPartialFindString
int CSLPartialFindString(CSLConstList papszHaystack, const char *pszNeedle)
Find a substring within a string list.
Definition: cpl_string.cpp:743
CPLStringList::FindString
int FindString(const char *pszTarget) const
Return index of pszTarget in the list, or -1.
Definition: cpl_string.h:469
CPLString::CPLString
CPLString(const std::string &oStr)
Constructor.
Definition: cpl_string.h:328
CSLGetField
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:174
CPLString::operator[]
const char & operator[](std::string::size_type i) const
Return character at specified index.
Definition: cpl_string.h:345
CPL_C_START
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:304
CSLTestBoolean
int CSLTestBoolean(const char *pszValue)
Test what boolean value contained in the string.
Definition: cpl_string.cpp:1573
CPLRecodeToWChar
wchar_t * CPLRecodeToWChar(const char *pszSource, const char *pszSrcEncoding, const char *pszDstEncoding)
Convert UTF-8 string to a wchar_t string.
Definition: cpl_recode.cpp:241
CSLInsertStrings
char ** CSLInsertStrings(char **papszStrList, int nInsertAtLineNo, CSLConstList papszNewLines)
Copies the contents of a StringList inside another StringList before the specified line.
Definition: cpl_string.cpp:503
CPLTestBool
bool CPLTestBool(const char *pszValue)
Test what boolean value contained in the string.
Definition: cpl_string.cpp:1546
CPLString::operator[]
char & operator[](int i)
Return character at specified index.
Definition: cpl_string.h:351
CPLprintf
int CPLprintf(const char *fmt,...)
printf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1409
CPLString::Seize
void Seize(char *pszValue)
Assign specified string and take ownership of it (assumed to be allocated with CPLMalloc()).
Definition: cpl_string.h:370
CPLString::operator[]
const char & operator[](int i) const
Return character at specified index.
Definition: cpl_string.h:358
CSLConstList
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1056
CPLVASPrintf
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:1064
CPLStringList::operator[]
char * operator[](size_t i)
Return string at specified index.
Definition: cpl_string.h:499
CPLBase64Encode
char * CPLBase64Encode(int nBytes, const GByte *pabyData)
Base64 encode a buffer.
Definition: cpl_base64.cpp:198
CPLStrlcpy
size_t CPLStrlcpy(char *pszDest, const char *pszSrc, size_t nDestSize)
Copy source string to a destination buffer.
Definition: cpl_string.cpp:2870
CPLStringList::empty
bool empty() const
Return whether the list is empty.
Definition: cpl_string.h:456
CPLString::operator[]
char & operator[](std::string::size_type i)
Return character at specified index.
Definition: cpl_string.h:339
CPL_SCAN_FUNC_FORMAT
#define CPL_SCAN_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have scanf() formatting.
Definition: cpl_port.h:846
CPLURLGetValue
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:421
CPL_C_END
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:306
CSLPrint
int CSLPrint(CSLConstList papszStrList, FILE *fpOut)
Print a StringList to fpOut.
Definition: cpl_string.cpp:467
CPLStringList::List
char ** List()
Return list.
Definition: cpl_string.h:510
CSLFindString
int CSLFindString(CSLConstList papszList, const char *pszTarget)
Find a string within a string list (case insensitive).
Definition: cpl_string.cpp:676
cpl_conv.h
CPL_VALUE_INTEGER
@ CPL_VALUE_INTEGER
Integer.
Definition: cpl_string.h:189
CPLRecode
char * CPLRecode(const char *pszSource, const char *pszSrcEncoding, const char *pszDstEncoding)
Convert a string from a source encoding to a destination encoding.
Definition: cpl_recode.cpp:80
CPLvsnprintf
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:1156
CPLSPrintf
const char * CPLSPrintf(const char *fmt,...)
CPLSPrintf() that works with 10 static buffer.
Definition: cpl_string.cpp:993
CPLStringList::IsSorted
int IsSorted() const
Returns whether the list is sorted.
Definition: cpl_string.h:517
CSLAddNameValue
char ** CSLAddNameValue(char **papszStrList, const char *pszName, const char *pszValue)
Add a new entry to a StringList of "Name=Value" pairs, ("Name:Value" pairs are also supported for bac...
Definition: cpl_string.cpp:1858
CSLAddStringMayFail
char ** CSLAddStringMayFail(char **papszStrList, const char *pszNewString)
Same as CSLAddString() but may return NULL in case of (memory) failure.
Definition: cpl_string.cpp:93
CPLStrlenUTF8
int CPLStrlenUTF8(const char *pszUTF8Str)
Return the number of UTF-8 characters of a nul-terminated string.
Definition: cpl_recode.cpp:424
CPLStringList::operator[]
const char * operator[](size_t i) const
Return string at specified index.
Definition: cpl_string.h:503
CPLParseNameValue
const char * CPLParseNameValue(const char *pszNameValue, char **ppszKey)
Parse NAME=VALUE string into name and value components.
Definition: cpl_string.cpp:1774
CSLTokenizeStringComplex
char ** CSLTokenizeStringComplex(const char *pszString, const char *pszDelimiter, int bHonourStrings, int bAllowEmptyTokens)
Obsolete tokenizing api.
Definition: cpl_string.cpp:775
CPLUnescapeString
char * CPLUnescapeString(const char *pszString, int *pnLength, int nScheme)
Unescape a string.
Definition: cpl_string.cpp:2414
CPLEncodingCharSize
int CPLEncodingCharSize(const char *pszEncoding)
Return bytes per character for encoding.
Definition: cpl_recode.cpp:377
CPLStrnlen
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:2962
CSLSave
int CSLSave(CSLConstList papszStrList, const char *pszFname)
Write a StringList to a text file.
Definition: cpl_string.cpp:418
CPLIsASCII
bool CPLIsASCII(const char *pabyData, size_t nLen)
Test if a string is encoded as ASCII.
Definition: cpl_recode.cpp:303
CSLDuplicate
char ** CSLDuplicate(CSLConstList papszStrList)
Clone a string list.
Definition: cpl_string.cpp:229
CPLStringList::PartialFindString
int PartialFindString(const char *pszNeedle) const
Return index of pszTarget in the list (using partial search), or -1.
Definition: cpl_string.h:472
CPL_SCANF_FORMAT_STRING
#define CPL_SCANF_FORMAT_STRING(arg)
Macro into which to wrap the format argument of a sscanf-like function.
Definition: cpl_port.h:861
CSLDestroy
void CSLDestroy(char **papszStrList)
Free string list.
Definition: cpl_string.cpp:201
CPL_VALUE_REAL
@ CPL_VALUE_REAL
Real number.
Definition: cpl_string.h:188
CPLValueType
CPLValueType
Type of value.
Definition: cpl_string.h:185
CPL_WARN_UNUSED_RESULT
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition: cpl_port.h:869
CPL_FORMAT_STRING
#define CPL_FORMAT_STRING(arg)
Macro into which to wrap the format argument of a printf-like function.
Definition: cpl_port.h:859
CPLString::CPLString
CPLString(const char *pszStr)
Constructor.
Definition: cpl_string.h:331
CSLTokenizeString
char ** CSLTokenizeString(const char *pszString)
Tokenizes a string and returns a StringList with one string for each token.
Definition: cpl_string.cpp:765
CSLSetNameValueSeparator
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:1977
CPLForceToASCII
char * CPLForceToASCII(const char *pabyData, int nLen, char chReplacementChar)
Return a new string that is made only of ASCII characters.
Definition: cpl_recode.cpp:335
CSLFetchNameValueMultiple
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:1821
CPLTestBoolean
int CPLTestBoolean(const char *pszValue)
Test what boolean value contained in the string.
Definition: cpl_string.cpp:1595
CSLFetchNameValue
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:1694
CSLRemoveStrings
char ** CSLRemoveStrings(char **papszStrList, int nFirstLineToDelete, int nNumToRemove, char ***ppapszRetStrings)
Remove strings inside a StringList.
Definition: cpl_string.cpp:594
CPLCanRecode
int CPLCanRecode(const char *pszTestStr, const char *pszSrcEncoding, const char *pszDstEncoding)
Checks if it is possible to recode a string from one encoding to another.
Definition: cpl_recode.cpp:450
CSLAddString
char ** CSLAddString(char **papszStrList, const char *pszNewString)
Append a string to a StringList and return a pointer to the modified StringList.
Definition: cpl_string.cpp:84
CPLString::Clear
void Clear()
Clear the string.
Definition: cpl_string.h:365
CPLOPrintf
CPLString CPLOPrintf(const char *pszFormat,...)
Return a CPLString with the content of sprintf()
Definition: cplstring.cpp:504
CPLStrdup
char * CPLStrdup(const char *)
Safe version of strdup() function.
Definition: cpl_conv.cpp:301
CPLBinaryToHex
char * CPLBinaryToHex(int nBytes, const GByte *pabyData)
Binary to hexadecimal translation.
Definition: cpl_string.cpp:2641
CPLString::CPLString
CPLString(void)
Constructor.
Definition: cpl_string.h:325
CPLStringList::operator[]
const char * operator[](const char *pszKey) const
Return value corresponding to pszKey, or nullptr.
Definition: cpl_string.h:506
CSLParseCommandLine
char ** CSLParseCommandLine(const char *pszCommandLine)
Tokenize command line arguments in a list of strings.
Definition: cpl_string.cpp:2986
CPLBase64DecodeInPlace
int CPLBase64DecodeInPlace(GByte *pszBase64)
Decode base64 string "pszBase64" (null terminated) in place.
Definition: cpl_base64.cpp:92
CSLFetchBoolean
int CSLFetchBoolean(CSLConstList papszStrList, const char *pszKey, int bDefault)
DEPRECATED.
Definition: cpl_string.cpp:1655
CPLQuotedSQLIdentifier
CPLString CPLQuotedSQLIdentifier(const char *pszIdent)
Return a CPLString of the SQL quoted identifier.
Definition: cplstring.cpp:536
CPLFree
#define CPLFree
Alias of VSIFree()
Definition: cpl_conv.h:83
CPL_RETURNS_NONNULL
#define CPL_RETURNS_NONNULL
Qualifier for a function that does not return NULL.
Definition: cpl_port.h:902
CPLHexToBinary
GByte * CPLHexToBinary(const char *pszHex, int *pnBytes)
Hexadecimal to binary translation.
Definition: cpl_string.cpp:2699