25 int res = memcmp(_data, other._data, std::min(_size, other._size));
27 return res > 0 ? 1 : -1;
28 }
else if (_size == other._size) {
31 return _size > other._size ? 1 : -1;
36 if (other.size() != size())
39 for (
size_t x = 0; x < size(); x++) {
41 char b = other._data[x];
44 if (tolower(a) == tolower(b))
52 inline void StringData::copyTo(
char* dest,
bool includeEndingNull)
const {
53 memcpy(dest, _data, size());
54 if (includeEndingNull)
58 inline size_t StringData::find(
char c,
size_t fromPos)
const {
59 if (fromPos >= size())
60 return std::string::npos;
62 const void* x = memchr(_data + fromPos, c, _size - fromPos);
64 return std::string::npos;
65 return static_cast<size_t>(
static_cast<const char*
>(x) - _data);
68 inline size_t StringData::find(
const StringData& needle)
const {
70 size_t needleSize = needle.size();
74 else if (needleSize > mx)
75 return std::string::npos;
79 for (
size_t i = 0; i <= mx; i++) {
80 if (memcmp(_data + i, needle._data, needleSize) == 0)
83 return std::string::npos;
86 inline size_t StringData::rfind(
char c,
size_t fromPos)
const {
87 const size_t sz = size();
91 for (
const char* cur = _data + fromPos; cur > _data; --cur) {
93 return (cur - _data) - 1;
95 return std::string::npos;
98 inline StringData StringData::substr(
size_t pos,
size_t n)
const {
100 throw std::out_of_range(
"out of range");
103 if (n > size() - pos)
111 return substr(0, prefix.size()) == prefix;
116 const size_t thisSize = size();
117 const size_t suffixSize = suffix.size();
118 if (suffixSize > thisSize)
120 return substr(thisSize - suffixSize) == suffix;
bool equalCaseInsensitive(const StringData &other) const
note: this uses tolower, and therefore does not handle come languages correctly.
Definition: string_data-inl.h:35
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
bool endsWith(const StringData &suffix) const
Returns true if 'suffix' is a substring of this instance, anchored at the end.
Definition: string_data-inl.h:114
int compare(const StringData &other) const
Returns -1, 0, or 1 if 'this' is less, equal, or greater than 'other' in lexicographical order...
Definition: string_data-inl.h:24
bool startsWith(const StringData &prefix) const
Returns true if 'prefix' is a substring of this instance, anchored at position 0. ...
Definition: string_data-inl.h:109