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 **
68 CSLAddStringMayFail(char **papszStrList,
69 const char *pszNewString) CPL_WARN_UNUSED_RESULT;
70 int CPL_DLL CSLCount(CSLConstList papszStrList);
71 const char CPL_DLL *CSLGetField(CSLConstList, int);
72 void CPL_DLL CPL_STDCALL CSLDestroy(char **papszStrList);
73 char CPL_DLL **CSLDuplicate(CSLConstList papszStrList) CPL_WARN_UNUSED_RESULT;
74 char CPL_DLL **CSLMerge(char **papszOrig,
75 CSLConstList papszOverride) CPL_WARN_UNUSED_RESULT;
76
77 char CPL_DLL **CSLTokenizeString(const char *pszString) CPL_WARN_UNUSED_RESULT;
78 char CPL_DLL **
79 CSLTokenizeStringComplex(const char *pszString, const char *pszDelimiter,
80 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(CSLConstList papszStrList, FILE *fpOut);
100 char CPL_DLL **CSLLoad(const char *pszFname) CPL_WARN_UNUSED_RESULT;
101 char CPL_DLL **CSLLoad2(const char *pszFname, int nMaxLines, int nMaxCols,
102 CSLConstList papszOptions) CPL_WARN_UNUSED_RESULT;
103 int CPL_DLL CSLSave(CSLConstList papszStrList, const char *pszFname);
104
105 char CPL_DLL **
106 CSLInsertStrings(char **papszStrList, int nInsertAtLineNo,
107 CSLConstList papszNewLines) CPL_WARN_UNUSED_RESULT;
108 char CPL_DLL **CSLInsertString(char **papszStrList, int nInsertAtLineNo,
109 const char *pszNewLine) CPL_WARN_UNUSED_RESULT;
110 char CPL_DLL **
111 CSLRemoveStrings(char **papszStrList, int nFirstLineToDelete, int nNumToRemove,
112 char ***ppapszRetStrings) CPL_WARN_UNUSED_RESULT;
113 int CPL_DLL CSLFindString(CSLConstList papszList, const char *pszTarget);
114 int CPL_DLL CSLFindStringCaseSensitive(CSLConstList papszList,
115 const char *pszTarget);
116 int CPL_DLL CSLPartialFindString(CSLConstList papszHaystack,
117 const char *pszNeedle);
118 int CPL_DLL CSLFindName(CSLConstList papszStrList, const char *pszName);
119 int CPL_DLL CSLFetchBoolean(CSLConstList papszStrList, const char *pszKey,
120 int bDefault);
121
122 /* TODO: Deprecate CSLTestBoolean. Remove in GDAL 3.x. */
123 int CPL_DLL CSLTestBoolean(const char *pszValue);
124 /* Do not use CPLTestBoolean in C++ code. Use CPLTestBool. */
125 int CPL_DLL CPLTestBoolean(const char *pszValue);
126
127 bool CPL_DLL CPLTestBool(const char *pszValue);
128 bool CPL_DLL CPLFetchBool(CSLConstList papszStrList, const char *pszKey,
129 bool bDefault);
130
131 const char CPL_DLL *CPLParseNameValue(const char *pszNameValue, char **ppszKey);
132
133 const char CPL_DLL *CSLFetchNameValue(CSLConstList papszStrList,
134 const char *pszName);
135 const char CPL_DLL *CSLFetchNameValueDef(CSLConstList papszStrList,
136 const char *pszName,
137 const char *pszDefault);
138 char CPL_DLL **CSLFetchNameValueMultiple(CSLConstList papszStrList,
139 const char *pszName);
140 char CPL_DLL **CSLAddNameValue(char **papszStrList, const char *pszName,
141 const char *pszValue) CPL_WARN_UNUSED_RESULT;
142 char CPL_DLL **CSLSetNameValue(char **papszStrList, const char *pszName,
143 const char *pszValue) CPL_WARN_UNUSED_RESULT;
144 void CPL_DLL CSLSetNameValueSeparator(char **papszStrList,
145 const char *pszSeparator);
146
147 char CPL_DLL **CSLParseCommandLine(const char *pszCommandLine);
148
150 #define CPLES_BackslashQuotable 0
151
152 #define CPLES_XML 1
153
154 #define CPLES_URL 2
155
156 #define CPLES_SQL 3
157
158 #define CPLES_CSV 4
159
161 #define CPLES_XML_BUT_QUOTES 5
162
163 #define CPLES_CSV_FORCE_QUOTING 6
164
165 #define CPLES_SQLI 7
166
167 char CPL_DLL *CPLEscapeString(const char *pszString, int nLength,
168 int nScheme) CPL_WARN_UNUSED_RESULT;
169 char CPL_DLL *CPLUnescapeString(const char *pszString, int *pnLength,
170 int nScheme) CPL_WARN_UNUSED_RESULT;
171
172 char CPL_DLL *CPLBinaryToHex(int nBytes,
173 const GByte *pabyData) CPL_WARN_UNUSED_RESULT;
174 GByte CPL_DLL *CPLHexToBinary(const char *pszHex,
175 int *pnBytes) CPL_WARN_UNUSED_RESULT;
176
177 char CPL_DLL *CPLBase64Encode(int nBytes,
178 const GByte *pabyData) CPL_WARN_UNUSED_RESULT;
179 int CPL_DLL CPLBase64DecodeInPlace(GByte *pszBase64) CPL_WARN_UNUSED_RESULT;
180
182 typedef enum
183 {
184 CPL_VALUE_STRING,
185 CPL_VALUE_REAL,
186 CPL_VALUE_INTEGER
187 } CPLValueType;
188
189 CPLValueType CPL_DLL CPLGetValueType(const char *pszValue);
190
191 size_t CPL_DLL CPLStrlcpy(char *pszDest, const char *pszSrc, size_t nDestSize);
192 size_t CPL_DLL CPLStrlcat(char *pszDest, const char *pszSrc, size_t nDestSize);
193 size_t CPL_DLL CPLStrnlen(const char *pszStr, size_t nMaxLen);
194
195 /* -------------------------------------------------------------------- */
196 /* Locale independent formatting functions. */
197 /* -------------------------------------------------------------------- */
198 int CPL_DLL CPLvsnprintf(char *str, size_t size,
199 CPL_FORMAT_STRING(const char *fmt), va_list args)
200 CPL_PRINT_FUNC_FORMAT(3, 0);
201
202 /* ALIAS_CPLSNPRINTF_AS_SNPRINTF might be defined to enable GCC 7 */
203 /* -Wformat-truncation= warnings, but shouldn't be set for normal use */
204 #if defined(ALIAS_CPLSNPRINTF_AS_SNPRINTF)
205 #define CPLsnprintf snprintf
206 #else
207 int CPL_DLL CPLsnprintf(char *str, size_t size,
208 CPL_FORMAT_STRING(const char *fmt), ...)
209 CPL_PRINT_FUNC_FORMAT(3, 4);
210 #endif
211
213 #if defined(GDAL_COMPILATION) && !defined(DONT_DEPRECATE_SPRINTF)
214 int CPL_DLL CPLsprintf(char *str, CPL_FORMAT_STRING(const char *fmt), ...)
215 CPL_PRINT_FUNC_FORMAT(2, 3) CPL_WARN_DEPRECATED("Use CPLsnprintf instead");
216 #else
217 int CPL_DLL CPLsprintf(char *str, CPL_FORMAT_STRING(const char *fmt), ...)
218 CPL_PRINT_FUNC_FORMAT(2, 3);
219 #endif
220
221 int CPL_DLL CPLprintf(CPL_FORMAT_STRING(const char *fmt), ...)
222 CPL_PRINT_FUNC_FORMAT(1, 2);
223
224 /* For some reason Doxygen_Suppress is needed to avoid warning. Not sure why */
226 /* caution: only works with limited number of formats */
227 int CPL_DLL CPLsscanf(const char *str, CPL_SCANF_FORMAT_STRING(const char *fmt),
228 ...) CPL_SCAN_FUNC_FORMAT(2, 3);
231 const char CPL_DLL *CPLSPrintf(CPL_FORMAT_STRING(const char *fmt), ...)
232 CPL_PRINT_FUNC_FORMAT(1, 2) CPL_WARN_UNUSED_RESULT;
233 char CPL_DLL **CSLAppendPrintf(char **papszStrList,
234 CPL_FORMAT_STRING(const char *fmt), ...)
235 CPL_PRINT_FUNC_FORMAT(2, 3) CPL_WARN_UNUSED_RESULT;
236 int CPL_DLL CPLVASPrintf(char **buf, CPL_FORMAT_STRING(const char *fmt),
237 va_list args) CPL_PRINT_FUNC_FORMAT(2, 0);
238
239 /* -------------------------------------------------------------------- */
240 /* RFC 23 character set conversion/recoding API (cpl_recode.cpp). */
241 /* -------------------------------------------------------------------- */
243 #define CPL_ENC_LOCALE ""
244
245 #define CPL_ENC_UTF8 "UTF-8"
246
247 #define CPL_ENC_UTF16 "UTF-16"
248
249 #define CPL_ENC_UCS2 "UCS-2"
250
251 #define CPL_ENC_UCS4 "UCS-4"
252
253 #define CPL_ENC_ASCII "ASCII"
254
255 #define CPL_ENC_ISO8859_1 "ISO-8859-1"
256
257 int CPL_DLL CPLEncodingCharSize(const char *pszEncoding);
259 void CPL_DLL CPLClearRecodeWarningFlags(void);
261 char CPL_DLL *CPLRecode(const char *pszSource, const char *pszSrcEncoding,
262 const char *pszDstEncoding)
263 CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
264 char CPL_DLL *
265 CPLRecodeFromWChar(const wchar_t *pwszSource, const char *pszSrcEncoding,
266 const char *pszDstEncoding) CPL_WARN_UNUSED_RESULT;
267 wchar_t CPL_DLL *
268 CPLRecodeToWChar(const char *pszSource, const char *pszSrcEncoding,
269 const char *pszDstEncoding) CPL_WARN_UNUSED_RESULT;
270 int CPL_DLL CPLIsUTF8(const char *pabyData, int nLen);
271 bool CPL_DLL CPLIsASCII(const char *pabyData, size_t nLen);
272 char CPL_DLL *CPLForceToASCII(const char *pabyData, int nLen,
273 char chReplacementChar) CPL_WARN_UNUSED_RESULT;
274 int CPL_DLL CPLStrlenUTF8(const char *pszUTF8Str);
275 int CPL_DLL CPLCanRecode(const char *pszTestStr, const char *pszSrcEncoding,
276 const char *pszDstEncoding) CPL_WARN_UNUSED_RESULT;
277 CPL_C_END
278
279 /************************************************************************/
280 /* CPLString */
281 /************************************************************************/
282
283 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
284
285 extern "C++"
286 {
287 #ifndef DOXYGEN_SKIP
288 #include <string>
289 #endif
290
291 // VC++ implicitly applies __declspec(dllexport) to template base classes
292 // of classes marked with __declspec(dllexport).
293 // Hence, if marked with CPL_DLL, VC++ would export symbols for the
294 // specialization of std::basic_string<char>, since it is a base class of
295 // CPLString. As a result, if an application linked both gdal.dll and a static
296 // library that (implicitly) instantiates std::string (almost all do!), then the
297 // linker would emit an error concerning duplicate symbols for std::string. The
298 // least intrusive solution is to not mark the whole class with
299 // __declspec(dllexport) for VC++, but only its non-inline methods.
300 #ifdef _MSC_VER
301 #define CPLSTRING_CLASS_DLL
302 #define CPLSTRING_METHOD_DLL CPL_DLL
303 #else
304
305 #define CPLSTRING_CLASS_DLL CPL_DLL
306 #define CPLSTRING_METHOD_DLL
307
308 #endif
309
311 class CPLSTRING_CLASS_DLL CPLString : public std::string
312 {
313 public:
315 CPLString(void)
316 {
317 }
319 // cppcheck-suppress noExplicitConstructor
320 CPLString(const std::string &oStr) : std::string(oStr)
321 {
322 }
324 // cppcheck-suppress noExplicitConstructor
325 CPLString(const char *pszStr) : std::string(pszStr)
326 {
327 }
329 CPLString(const char *pszStr, size_t n) : std::string(pszStr, n)
330 {
331 }
332
334 operator const char *(void) const
335 {
336 return c_str();
337 }
338
340 char &operator[](std::string::size_type i)
341 {
342 return std::string::operator[](i);
343 }
344
346 const char &operator[](std::string::size_type i) const
347 {
348 return std::string::operator[](i);
349 }
350
352 char &operator[](int i)
353 {
354 return std::string::operator[](
355 static_cast<std::string::size_type>(i));
356 }
357
359 const char &operator[](int i) const
360 {
361 return std::string::operator[](
362 static_cast<std::string::size_type>(i));
363 }
364
366 void Clear()
367 {
368 resize(0);
369 }
370
374 void Seize(char *pszValue)
375 {
376 if (pszValue == nullptr)
377 Clear();
378 else
379 {
380 *this = pszValue;
381 CPLFree(pszValue);
382 }
383 }
384
385 /* There seems to be a bug in the way the compiler count indices...
386 * Should be CPL_PRINT_FUNC_FORMAT (1, 2) */
387 CPLSTRING_METHOD_DLL CPLString &
388 Printf(CPL_FORMAT_STRING(const char *pszFormat), ...)
389 CPL_PRINT_FUNC_FORMAT(2, 3);
390 CPLSTRING_METHOD_DLL CPLString &
391 vPrintf(CPL_FORMAT_STRING(const char *pszFormat), va_list args)
392 CPL_PRINT_FUNC_FORMAT(2, 0);
393 CPLSTRING_METHOD_DLL CPLString &
394 FormatC(double dfValue, const char *pszFormat = nullptr);
395 CPLSTRING_METHOD_DLL CPLString &Trim();
396 CPLSTRING_METHOD_DLL CPLString &Recode(const char *pszSrcEncoding,
397 const char *pszDstEncoding);
398 CPLSTRING_METHOD_DLL CPLString &replaceAll(const std::string &osBefore,
399 const std::string &osAfter);
400 CPLSTRING_METHOD_DLL CPLString &replaceAll(const std::string &osBefore,
401 char chAfter);
402 CPLSTRING_METHOD_DLL CPLString &replaceAll(char chBefore,
403 const std::string &osAfter);
404 CPLSTRING_METHOD_DLL CPLString &replaceAll(char chBefore, char chAfter);
405
406 /* case insensitive find alternates */
407 CPLSTRING_METHOD_DLL size_t ifind(const std::string &str,
408 size_t pos = 0) const;
409 CPLSTRING_METHOD_DLL size_t ifind(const char *s, size_t pos = 0) const;
410 CPLSTRING_METHOD_DLL CPLString &toupper(void);
411 CPLSTRING_METHOD_DLL CPLString &tolower(void);
412
413 CPLSTRING_METHOD_DLL bool endsWith(const std::string &osStr) const;
414 };
415
416 #undef CPLSTRING_CLASS_DLL
417 #undef CPLSTRING_METHOD_DLL
418
419 CPLString CPL_DLL CPLOPrintf(CPL_FORMAT_STRING(const char *pszFormat), ...)
420 CPL_PRINT_FUNC_FORMAT(1, 2);
421 CPLString CPL_DLL CPLOvPrintf(CPL_FORMAT_STRING(const char *pszFormat),
422 va_list args) CPL_PRINT_FUNC_FORMAT(1, 0);
423 CPLString CPL_DLL CPLQuotedSQLIdentifier(const char *pszIdent);
424
425 /* -------------------------------------------------------------------- */
426 /* URL processing functions, here since they depend on CPLString. */
427 /* -------------------------------------------------------------------- */
428 CPLString CPL_DLL CPLURLGetValue(const char *pszURL, const char *pszKey);
429 CPLString CPL_DLL CPLURLAddKVP(const char *pszURL, const char *pszKey,
430 const char *pszValue);
431
432 /************************************************************************/
433 /* CPLStringList */
434 /************************************************************************/
435
437 class CPL_DLL CPLStringList
438 {
439 char **papszList = nullptr;
440 mutable int nCount = 0;
441 mutable int nAllocation = 0;
442 bool bOwnList = false;
443 bool bIsSorted = false;
444
445 bool MakeOurOwnCopy();
446 bool EnsureAllocation(int nMaxLength);
447 int FindSortedInsertionPoint(const char *pszLine);
448
449 public:
450 CPLStringList();
451 explicit CPLStringList(char **papszList, int bTakeOwnership = TRUE);
452 explicit CPLStringList(CSLConstList papszList);
453 CPLStringList(const CPLStringList &oOther);
454 CPLStringList(CPLStringList &&oOther);
455 ~CPLStringList();
456
457 CPLStringList &Clear();
458
460 int size() const
461 {
462 return Count();
463 }
464 int Count() const;
465
467 bool empty() const
468 {
469 return Count() == 0;
470 }
471
472 CPLStringList &AddString(const char *pszNewString);
473 CPLStringList &AddStringDirectly(char *pszNewString);
474
475 CPLStringList &InsertString(int nInsertAtLineNo, const char *pszNewLine)
476 {
477 return InsertStringDirectly(nInsertAtLineNo, CPLStrdup(pszNewLine));
478 }
479 CPLStringList &InsertStringDirectly(int nInsertAtLineNo,
480 char *pszNewLine);
481
482 // CPLStringList &InsertStrings( int nInsertAtLineNo, char
483 // **papszNewLines ); CPLStringList &RemoveStrings( int
484 // nFirstLineToDelete, int nNumToRemove=1 );
485
487 int FindString(const char *pszTarget) const
488 {
489 return CSLFindString(papszList, pszTarget);
490 }
493 int PartialFindString(const char *pszNeedle) const
494 {
495 return CSLPartialFindString(papszList, pszNeedle);
496 }
497
498 int FindName(const char *pszName) const;
499 bool FetchBool(const char *pszKey, bool bDefault) const;
500 // Deprecated.
501 int FetchBoolean(const char *pszKey, int bDefault) const;
502 const char *FetchNameValue(const char *pszKey) const;
503 const char *FetchNameValueDef(const char *pszKey,
504 const char *pszDefault) const;
505 CPLStringList &AddNameValue(const char *pszKey, const char *pszValue);
506 CPLStringList &SetNameValue(const char *pszKey, const char *pszValue);
507
508 CPLStringList &Assign(char **papszListIn, int bTakeOwnership = TRUE);
510 CPLStringList &operator=(char **papszListIn)
511 {
512 return Assign(papszListIn, TRUE);
513 }
515 CPLStringList &operator=(const CPLStringList &oOther);
517 CPLStringList &operator=(CSLConstList papszListIn);
519 CPLStringList &operator=(CPLStringList &&oOther);
520
522 char *operator[](int i);
524 char *operator[](size_t i)
525 {
526 return (*this)[static_cast<int>(i)];
527 }
529 const char *operator[](int i) const;
531 const char *operator[](size_t i) const
532 {
533 return (*this)[static_cast<int>(i)];
534 }
536 const char *operator[](const char *pszKey) const
537 {
538 return FetchNameValue(pszKey);
539 }
540
542 const char *const *begin() const
543 {
544 return papszList ? &papszList[0] : nullptr;
545 }
546
548 const char *const *end() const
549 {
550 return papszList ? &papszList[size()] : nullptr;
551 }
552
554 char **List()
555 {
556 return papszList;
557 }
559 CSLConstList List() const
560 {
561 return papszList;
562 }
563 char **StealList();
564
565 CPLStringList &Sort();
567 int IsSorted() const
568 {
569 return bIsSorted;
570 }
571
573 operator char **(void)
574 {
575 return List();
576 }
578 operator CSLConstList(void) const
579 {
580 return List();
581 }
582 };
583
584 #ifdef GDAL_COMPILATION
585
586 #include <memory>
587
589 struct CPL_DLL CSLDestroyReleaser
590 {
591 void operator()(char **papszStr) const
592 {
593 CSLDestroy(papszStr);
594 }
595 };
599 using CSLUniquePtr = std::unique_ptr<char *, CSLDestroyReleaser>;
600
602 struct CPL_DLL CPLFreeReleaser
603 {
604 void operator()(void *p) const
605 {
606 CPLFree(p);
607 }
608 };
613 using CPLCharUniquePtr = std::unique_ptr<char, CPLFreeReleaser>;
614
615 #endif
616
617 } // extern "C++"
618
619 #endif /* def __cplusplus && !CPL_SUPRESS_CPLUSPLUS */
620
621 #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:321
CPLStringList::operator=
CPLStringList & operator=(char **papszListIn)
Assignment operator.
Definition: cpl_string.h:510
CPL_PRINT_FUNC_FORMAT
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition: cpl_port.h:950
CPLRecodeFromWChar
char * CPLRecodeFromWChar(const wchar_t *pwszSource, const char *pszSrcEncoding, const char *pszDstEncoding)
Convert wchar_t string to UTF-8.
Definition: cpl_recode.cpp:178
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:563
CSLTokenizeString2
char ** CSLTokenizeString2(const char *pszString, const char *pszDelimiter, int nCSLTFlags)
Tokenize a string.
Definition: cpl_string.cpp:835
CSLFindStringCaseSensitive
int CSLFindStringCaseSensitive(CSLConstList papszList, const char *pszTarget)
Find a string within a string list(case sensitive)
Definition: cpl_string.cpp:705
GByte
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:196
CPLStringList::begin
const char *const * begin() const
begin() implementation
Definition: cpl_string.h:542
CPLString::CPLString
CPLString(const char *pszStr, size_t n)
Constructor.
Definition: cpl_string.h:329
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:446
CSLMerge
char ** CSLMerge(char **papszOrig, CSLConstList papszOverride)
Merge two lists.
Definition: cpl_string.cpp:273
CPLIsUTF8
int CPLIsUTF8(const char *pabyData, int nLen)
Test if a string is encoded as UTF-8.
Definition: cpl_recode.cpp:276
CPLEscapeString
char * CPLEscapeString(const char *pszString, int nLength, int nScheme)
Apply escaping to string to preserve special characters.
Definition: cpl_string.cpp:2058
CSLLoad
char ** CSLLoad(const char *pszFname)
Load a text file into a string list.
Definition: cpl_string.cpp:398
CPLOvPrintf
CPLString CPLOvPrintf(const char *pszFormat, va_list args)
Return a CPLString with the content of vsprintf()
Definition: cplstring.cpp:514
CPLStringList::InsertString
CPLStringList & InsertString(int nInsertAtLineNo, const char *pszNewLine)
Insert into the list at identified location.
Definition: cpl_string.h:475
CPLStrlcat
size_t CPLStrlcat(char *pszDest, const char *pszSrc, size_t nDestSize)
Appends a source string to a destination buffer.
Definition: cpl_string.cpp:2914
CPLStringList
String list class designed around our use of C "char**" string lists.
Definition: cpl_string.h:437
CSLFindName
int CSLFindName(CSLConstList papszStrList, const char *pszName)
Find StringList entry with given key name.
Definition: cpl_string.cpp:1733
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:2725
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:1674
CSLSetNameValue
char ** CSLSetNameValue(char **papszStrList, const char *pszName, const char *pszValue)
Assign value to name in StringList.
Definition: cpl_string.cpp:1899
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:1367
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:1036
CSLCount
int CSLCount(CSLConstList papszStrList)
Return number of items in a string list.
Definition: cpl_string.cpp:147
CPLStringList::List
CSLConstList List() const
Return list.
Definition: cpl_string.h:559
CPLString
Convenient string class based on std::string.
Definition: cpl_string.h:311
CPLStringList::size
int size() const
Return size of list.
Definition: cpl_string.h:460
CPLFetchBool
bool CPLFetchBool(CSLConstList papszStrList, const char *pszKey, bool bDefault)
Check for boolean key value.
Definition: cpl_string.cpp:1630
CPL_VALUE_STRING
@ CPL_VALUE_STRING
String.
Definition: cpl_string.h:184
CSLPartialFindString
int CSLPartialFindString(CSLConstList papszHaystack, const char *pszNeedle)
Find a substring within a string list.
Definition: cpl_string.cpp:737
CPLStringList::FindString
int FindString(const char *pszTarget) const
Return index of pszTarget in the list, or -1.
Definition: cpl_string.h:487
CPLString::CPLString
CPLString(const std::string &oStr)
Constructor.
Definition: cpl_string.h:320
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:173
CPLString::operator[]
const char & operator[](std::string::size_type i) const
Return character at specified index.
Definition: cpl_string.h:346
CPL_C_START
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:306
CSLTestBoolean
int CSLTestBoolean(const char *pszValue)
Test what boolean value contained in the string.
Definition: cpl_string.cpp:1583
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:235
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:498
CPLTestBool
bool CPLTestBool(const char *pszValue)
Test what boolean value contained in the string.
Definition: cpl_string.cpp:1558
CPLString::operator[]
char & operator[](int i)
Return character at specified index.
Definition: cpl_string.h:352
CPLprintf
int CPLprintf(const char *fmt,...)
printf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1422
CPLString::Seize
void Seize(char *pszValue)
Assign specified string and take ownership of it (assumed to be allocated with CPLMalloc()).
Definition: cpl_string.h:374
CPLString::operator[]
const char & operator[](int i) const
Return character at specified index.
Definition: cpl_string.h:359
CSLConstList
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1178
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:1055
CPLStringList::operator[]
char * operator[](size_t i)
Return string at specified index.
Definition: cpl_string.h:524
CPLBase64Encode
char * CPLBase64Encode(int nBytes, const GByte *pabyData)
Base64 encode a buffer.
Definition: cpl_base64.cpp:196
CPLStrlcpy
size_t CPLStrlcpy(char *pszDest, const char *pszSrc, size_t nDestSize)
Copy source string to a destination buffer.
Definition: cpl_string.cpp:2857
CPLStringList::empty
bool empty() const
Return whether the list is empty.
Definition: cpl_string.h:467
CPLString::operator[]
char & operator[](std::string::size_type i)
Return character at specified index.
Definition: cpl_string.h:340
CPL_SCAN_FUNC_FORMAT
#define CPL_SCAN_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have scanf() formatting.
Definition: cpl_port.h:952
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:413
CPL_C_END
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:310
CSLPrint
int CSLPrint(CSLConstList papszStrList, FILE *fpOut)
Print a StringList to fpOut.
Definition: cpl_string.cpp:462
CPLStringList::List
char ** List()
Return list.
Definition: cpl_string.h:554
CSLFindString
int CSLFindString(CSLConstList papszList, const char *pszTarget)
Find a string within a string list (case insensitive).
Definition: cpl_string.cpp:671
cpl_conv.h
CPL_VALUE_INTEGER
@ CPL_VALUE_INTEGER
Integer.
Definition: cpl_string.h:186
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:77
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:1147
CPLSPrintf
const char * CPLSPrintf(const char *fmt,...)
CPLSPrintf() that works with 10 static buffer.
Definition: cpl_string.cpp:983
CPLStringList::IsSorted
int IsSorted() const
Returns whether the list is sorted.
Definition: cpl_string.h:567
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:1860
CSLAddStringMayFail
char ** CSLAddStringMayFail(char **papszStrList, const char *pszNewString)
Same as CSLAddString() but may return NULL in case of (memory) failure.
Definition: cpl_string.cpp:92
CPLStrlenUTF8
int CPLStrlenUTF8(const char *pszUTF8Str)
Return the number of UTF-8 characters of a nul-terminated string.
Definition: cpl_recode.cpp:415
CPLStringList::operator[]
const char * operator[](size_t i) const
Return string at specified index.
Definition: cpl_string.h:531
CPLParseNameValue
const char * CPLParseNameValue(const char *pszNameValue, char **ppszKey)
Parse NAME=VALUE string into name and value components.
Definition: cpl_string.cpp:1778
CSLTokenizeStringComplex
char ** CSLTokenizeStringComplex(const char *pszString, const char *pszDelimiter, int bHonourStrings, int bAllowEmptyTokens)
Obsolete tokenizing api.
Definition: cpl_string.cpp:768
CPLUnescapeString
char * CPLUnescapeString(const char *pszString, int *pnLength, int nScheme)
Unescape a string.
Definition: cpl_string.cpp:2408
CPLEncodingCharSize
int CPLEncodingCharSize(const char *pszEncoding)
Return bytes per character for encoding.
Definition: cpl_recode.cpp:369
CPLStringList::end
const char *const * end() const
end() implementation
Definition: cpl_string.h:548
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:2949
CSLSave
int CSLSave(CSLConstList papszStrList, const char *pszFname)
Write a StringList to a text file.
Definition: cpl_string.cpp:413
CPLIsASCII
bool CPLIsASCII(const char *pabyData, size_t nLen)
Test if a string is encoded as ASCII.
Definition: cpl_recode.cpp:295
CSLDuplicate
char ** CSLDuplicate(CSLConstList papszStrList)
Clone a string list.
Definition: cpl_string.cpp:228
CPLStringList::PartialFindString
int PartialFindString(const char *pszNeedle) const
Return index of pszTarget in the list (using partial search), or -1.
Definition: cpl_string.h:493
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:968
CSLDestroy
void CSLDestroy(char **papszStrList)
Free string list.
Definition: cpl_string.cpp:200
CPL_VALUE_REAL
@ CPL_VALUE_REAL
Real number.
Definition: cpl_string.h:185
CPLValueType
CPLValueType
Type of value.
Definition: cpl_string.h:182
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:976
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:966
CPLString::CPLString
CPLString(const char *pszStr)
Constructor.
Definition: cpl_string.h:325
CSLTokenizeString
char ** CSLTokenizeString(const char *pszString)
Tokenizes a string and returns a StringList with one string for each token.
Definition: cpl_string.cpp:758
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:1980
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:327
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:1825
CPLTestBoolean
int CPLTestBoolean(const char *pszValue)
Test what boolean value contained in the string.
Definition: cpl_string.cpp:1605
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:1701
CSLRemoveStrings
char ** CSLRemoveStrings(char **papszStrList, int nFirstLineToDelete, int nNumToRemove, char ***ppapszRetStrings)
Remove strings inside a StringList.
Definition: cpl_string.cpp:589
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:441
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:83
CPLString::Clear
void Clear()
Clear the string.
Definition: cpl_string.h:366
CPLOPrintf
CPLString CPLOPrintf(const char *pszFormat,...)
Return a CPLString with the content of sprintf()
Definition: cplstring.cpp:495
CPLStrdup
char * CPLStrdup(const char *)
Safe version of strdup() function.
Definition: cpl_conv.cpp:306
CPLBinaryToHex
char * CPLBinaryToHex(int nBytes, const GByte *pabyData)
Binary to hexadecimal translation.
Definition: cpl_string.cpp:2632
CPLString::CPLString
CPLString(void)
Constructor.
Definition: cpl_string.h:315
CPLStringList::operator[]
const char * operator[](const char *pszKey) const
Return value corresponding to pszKey, or nullptr.
Definition: cpl_string.h:536
CSLParseCommandLine
char ** CSLParseCommandLine(const char *pszCommandLine)
Tokenize command line arguments in a list of strings.
Definition: cpl_string.cpp:2973
CPLBase64DecodeInPlace
int CPLBase64DecodeInPlace(GByte *pszBase64)
Decode base64 string "pszBase64" (null terminated) in place.
Definition: cpl_base64.cpp:90
CSLFetchBoolean
int CSLFetchBoolean(CSLConstList papszStrList, const char *pszKey, int bDefault)
DEPRECATED.
Definition: cpl_string.cpp:1663
CPLQuotedSQLIdentifier
CPLString CPLQuotedSQLIdentifier(const char *pszIdent)
Return a CPLString of the SQL quoted identifier.
Definition: cplstring.cpp:527
CPLFree
#define CPLFree
Alias of VSIFree()
Definition: cpl_conv.h:98
CPL_RETURNS_NONNULL
#define CPL_RETURNS_NONNULL
Qualifier for a function that does not return NULL.
Definition: cpl_port.h:1014
CPLHexToBinary
GByte * CPLHexToBinary(const char *pszHex, int *pnBytes)
Hexadecimal to binary translation.
Definition: cpl_string.cpp:2686