26 #include "mongo/client/export_macros.h"
52 StringData(
const char* str) : _data(str), _size((str == NULL) ? 0 : std::strlen(str)) {}
59 StringData(
const char* c,
size_t len) : _data(c), _size(len) {}
62 StringData(
const std::string& s) : _data(s.c_str()), _size(s.size()) {}
71 : _data(&val[0]), _size(N - 1) {}
84 bool equalCaseInsensitive(
const StringData& other)
const;
86 void copyTo(
char* dest,
bool includeEndingNull)
const;
88 StringData substr(
size_t pos,
size_t n = std::numeric_limits<size_t>::max())
const;
94 size_t find(
char c,
size_t fromPos = 0)
const;
96 size_t rfind(
char c,
size_t fromPos = std::string::npos)
const;
101 bool startsWith(
const StringData& prefix)
const;
106 bool endsWith(
const StringData& suffix)
const;
121 size_t size()
const {
127 std::string toString()
const {
128 return std::string(_data, size());
130 char operator[](
unsigned pos)
const {
140 size_t operator()(
const StringData& str)
const;
147 typedef const char* const_iterator;
149 const_iterator begin()
const {
152 const_iterator end()
const {
153 return rawData() + size();
161 inline bool operator==(
const StringData& lhs,
const StringData& rhs) {
162 return (lhs.size() == rhs.size()) && (lhs.compare(rhs) == 0);
165 inline bool operator!=(
const StringData& lhs,
const StringData& rhs) {
166 return !(lhs == rhs);
169 inline bool operator<(
const StringData& lhs,
const StringData& rhs) {
170 return lhs.compare(rhs) < 0;
173 inline bool operator<=(
const StringData& lhs,
const StringData& rhs) {
174 return lhs.compare(rhs) <= 0;
177 inline bool operator>(
const StringData& lhs,
const StringData& rhs) {
178 return lhs.compare(rhs) > 0;
181 inline bool operator>=(
const StringData& lhs,
const StringData& rhs) {
182 return lhs.compare(rhs) >= 0;
185 MONGO_CLIENT_API std::ostream& MONGO_CLIENT_FUNC
186 operator<<(std::ostream& stream,
const StringData& value);
190 #include "mongo/base/string_data-inl.h"
Functor compatible with std::hash for std::unordered_{map,set} Warning: The hash function is subject ...
Definition: string_data.h:139
StringData()
Constructs an empty string data.
Definition: string_data.h:46
A StringData object wraps a 'const string&' or a 'const char*' without copying its contents...
Definition: string_data.h:43
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
StringData(const char *str)
Constructs a StringData, for the case where the length of string is not known.
Definition: string_data.h:52
const char * rawData() const
Get the pointer to the first byte of StringData.
Definition: string_data.h:117
StringData(const std::string &s)
Constructs a StringData, for the case of a string.
Definition: string_data.h:62
StringData(const char *c, size_t len)
Constructs a StringData explicitly, for the case where the length of the string is already known...
Definition: string_data.h:59
Constructs a StringData explicitly, for the case of a literal whose size is known at compile time...
Definition: string_data.h:68