MongoDB C++ Driver
legacy-1.1.2
|
A StringData object wraps a 'const string&' or a 'const char*' without copying its contents. More...
#include <string_data.h>
Classes | |
struct | Hasher |
Functor compatible with std::hash for std::unordered_{map,set} Warning: The hash function is subject to change. More... | |
struct | LiteralTag |
Constructs a StringData explicitly, for the case of a literal whose size is known at compile time. More... | |
Public Member Functions | |
StringData () | |
Constructs an empty string data. | |
StringData (const char *str) | |
Constructs a StringData, for the case where the length of string is not known. More... | |
StringData (const char *c, size_t len) | |
Constructs a StringData explicitly, for the case where the length of the string is already known. More... | |
StringData (const std::string &s) | |
Constructs a StringData, for the case of a string. More... | |
int | compare (const StringData &other) const |
Returns -1, 0, or 1 if 'this' is less, equal, or greater than 'other' in lexicographical order. | |
bool | equalCaseInsensitive (const StringData &other) const |
note: this uses tolower, and therefore does not handle come languages correctly. More... | |
bool | startsWith (const StringData &prefix) const |
Returns true if 'prefix' is a substring of this instance, anchored at position 0. | |
bool | endsWith (const StringData &suffix) const |
Returns true if 'suffix' is a substring of this instance, anchored at the end. | |
const char * | rawData () const |
Get the pointer to the first byte of StringData. More... | |
A StringData object wraps a 'const string&' or a 'const char*' without copying its contents.
The most common usage is as a function argument that takes any of the two forms of strings above. Fundamentally, this class tries go around the fact that string literals in C++ are char[N]'s.
Notes:
|
inline |
Constructs a StringData, for the case where the length of string is not known.
'c' must be a pointer to a null-terminated string.
|
inline |
Constructs a StringData explicitly, for the case where the length of the string is already known.
'c' must be a pointer to a null-terminated string, and len must be the length that strlen(c) would return, a.k.a the index of the terminator in c.
|
inline |
Constructs a StringData, for the case of a string.
|
inline |
note: this uses tolower, and therefore does not handle come languages correctly.
should be use sparingly
|
inline |
Get the pointer to the first byte of StringData.
This is not guaranteed to be null-terminated, so if using this without checking size(), you are likely doing something wrong.