GDAL

Public Member Functions | List of all members
CPLString Class Reference

Convenient string class based on std::string. More...

`#include <cpl_string.h>`

Inheritance diagram for CPLString:

## Public Member Functions
| CPLString (void)
| Constructor.
| CPLString (const std::string &oStr)
| Constructor.
| CPLString (const char *pszStr)
| Constructor.
| CPLString (const char *pszStr, size_t n)
| Constructor.
| operator const char * (void) const
| Return string as zero terminated character array.
char & | operator[] (std::string::size_type i)
| Return character at specified index.
const char & | operator[] (std::string::size_type i) const
| Return character at specified index.
char & | operator[] (int i)
| Return character at specified index.
const char & | operator[] (int i) const
| Return character at specified index.
void | Clear ()
| Clear the string.
void | Seize (char *pszValue)
| Assign specified string and take ownership of it (assumed to be allocated with CPLMalloc()).
CPLString & | Printf (const char *pszFormat,...)
| Assign the content of the string using sprintf()
CPLString & | vPrintf (const char *pszFormat, va_list args)
| Assign the content of the string using vsprintf()
CPLString & | FormatC (double dfValue, const char *pszFormat=nullptr)
| Format double in C locale.
CPLString & | Trim ()
| Trim white space.
CPLString & | Recode (const char *pszSrcEncoding, const char *pszDstEncoding)
| Recode the string.
CPLString & | replaceAll (const std::string &osBefore, const std::string &osAfter)
| Replace all occurrences of osBefore with osAfter.
CPLString & | replaceAll (const std::string &osBefore, char chAfter)
| Replace all occurrences of osBefore with chAfter.
CPLString & | replaceAll (char chBefore, const std::string &osAfter)
| Replace all occurrences of chBefore with osAfter.
CPLString & | replaceAll (char chBefore, char chAfter)
| Replace all occurrences of chBefore with chAfter.
size_t | ifind (const std::string &str, size_t pos=0) const
| Case insensitive find() alternative.
size_t | ifind (const char *s, size_t pos=0) const
| Case insensitive find() alternative.
CPLString & | toupper (void)
| Convert to upper case in place.
CPLString & | tolower (void)
| Convert to lower case in place.
bool | endsWith (const std::string &osStr) const
| Returns whether the string ends with another string.
CPLString | URLEncode () const
| Return a string that can be a valid URL.
CPLString | SQLQuotedIdentifier () const
| Returns a string between double quotes and with all double quotes inside the string are escaped by being doubled.
CPLString | SQLQuotedLiteral () const
| Returns a string between single quotes and with all single quotes inside the string are escaped by being doubled.

## Detailed Description

Convenient string class based on std::string.

## Member Function Documentation

## ◆ endsWith()

bool CPLString::endsWith | ( | const std::string & | osStr | ) | const

Returns whether the string ends with another string.

Parameters

  osStr | other string.

Returns
  true if the string ends with osStr.

## ◆ FormatC()

CPLString & CPLString::FormatC | ( | double | dfValue,
|  | const char * | pszFormat = `nullptr`
| ) |  |

Format double in C locale.

The passed value is formatted using the C locale (period as decimal separator) and appended to the target CPLString.

Parameters

  dfValue | the value to format.
  pszFormat | the sprintf() style format to use or omit for default. Note that this format string should only include one substitution argument and it must be for a double (f or g).

Returns
  a reference to the CPLString.

## ◆ ifind() [1/2]

size_t CPLString::ifind | ( | const char * | s,
|  | size_t | nPos = `0`
| ) |  | const

Case insensitive find() alternative.

Parameters

  s | substring to find.
  nPos | offset in the string at which the search starts.

Returns
  the position of the substring in the string or std::string::npos if not found.

## ◆ ifind() [2/2]

size_t CPLString::ifind | ( | const std::string & | str,
|  | size_t | pos = `0`
| ) |  | const

Case insensitive find() alternative.

Parameters

  str | substring to find.
  pos | offset in the string at which the search starts.

Returns
  the position of substring in the string or std::string::npos if not found.

## ◆ Seize()

void CPLString::Seize | ( | char * | pszValue | ) |
| inline

Assign specified string and take ownership of it (assumed to be allocated with CPLMalloc()).

NULL can be safely passed to clear the string.

## ◆ SQLQuotedIdentifier()

CPLString CPLString::SQLQuotedIdentifier | ( |  | ) | const

Returns a string between double quotes and with all double quotes inside the string are escaped by being doubled.

Aimed at being used for SQL identifiers (table names, column names, etc.).

Since
  3.13

## ◆ SQLQuotedLiteral()

CPLString CPLString::SQLQuotedLiteral | ( |  | ) | const

Returns a string between single quotes and with all single quotes inside the string are escaped by being doubled.

Aimed at being used for SQL literal strings.

Since
  3.13

## ◆ Trim()

CPLString & CPLString::Trim | ( |  | ) |

Trim white space.

Trims white space off the let and right of the string. White space is any of a space, a tab, a newline ('\n') or a carriage control ('\r').

Returns
  a reference to the CPLString.

## ◆ URLEncode()

CPLString CPLString::URLEncode | ( |  | ) | const

Return a string that can be a valid URL.

Said otherwise if URLEncode() != *this was not a valid URL according to https://datatracker.ietf.org/doc/html/rfc3986.html.

This replaces all characters that are not reserved (:/?#[]@!$&'()*+,;=), unreserved (a-z, A-Z, 0-9 and -.-~) or already percent-encoded by their percent-encoding.

Note that when composing a URL, and typically query-parameters, it might be needed to use CPLEscape(,,CPLES_URL) to also substitute reserved characters.

Returns
  a URL encoded string

Since
  3.12

The documentation for this class was generated from the following files:

- cpl_string.h
- cplstring.cpp