21 #ifndef XAPIAN_INCLUDED_STRINGUTILS_H 22 #define XAPIAN_INCLUDED_STRINGUTILS_H 33 #define STRINGIZE_(X) #X 36 #define STRINGIZE(X) STRINGIZE_(X) 43 #define CONST_STRLEN(S) (sizeof(S"") - 1) 53 return !s.empty() && s[0] == pfx;
57 startswith(
const std::string & s,
const char * pfx,
size_t len)
59 return s.size() >= len && (std::memcmp(s.data(), pfx, len) == 0);
69 startswith(
const std::string & s,
const std::string & pfx)
77 return !s.empty() && s[s.size() - 1] == sfx;
81 endswith(
const std::string & s,
const char * sfx,
size_t len)
83 return s.size() >= len && (std::memcmp(s.data() + s.size() - len, sfx, len) == 0);
87 endswith(
const std::string & s,
const char * sfx)
89 return endswith(s, sfx, std::strlen(sfx));
93 endswith(
const std::string & s,
const std::string & sfx)
95 return endswith(s, sfx.data(), sfx.size());
101 return s.find(substring) != s.npos;
105 contains(
const std::string& s,
const char* substring,
size_t len)
107 return s.find(substring, 0, len) != s.npos;
111 contains(
const std::string& s,
const char* substring)
113 return s.find(substring) != s.npos;
117 contains(
const std::string& s,
const std::string& substring)
119 return s.find(substring) != s.npos;
122 inline std::string::size_type
125 std::string::size_type minlen = std::min(a.size(), b.size());
126 std::string::size_type common;
127 for (common = 0; common < minlen; ++common) {
128 if (a[common] != b[common])
break;
133 inline std::string::size_type
135 std::string::size_type max_prefix_len)
137 std::string::size_type minlen = std::min({a.size(),
140 std::string::size_type common;
141 for (common = 0; common < minlen; ++common) {
142 if (a[common] != b[common])
break;
166 static_assert(
'\x20' ==
' ',
"character set isn't a superset of ASCII");
174 return C_tab[
static_cast<unsigned char>(ch)];
247 #endif // XAPIAN_INCLUDED_STRINGUTILS_H The Xapian namespace contains public interfaces for the Xapian library.
bool endswith(const std::string &s, char sfx)
unsigned char C_tab_(char ch)
const unsigned char IS_DIGIT
const unsigned char IS_UPPER
bool contains(const std::string &s, char substring)
const unsigned char IS_ALPHA
Mechanism for accessing a struct of constant information.
const struct constinfo * get_constinfo_()
bool C_isnotalpha(char ch)
bool startswith(const std::string &s, char pfx)
std::string::size_type common_prefix_length(const std::string &a, const std::string &b)
char hex_decode(char ch1, char ch2)
Decode a pair of ASCII hex digits.
bool C_isnotlower(char ch)
bool C_isnotdigit(char ch)
bool C_isnotxdigit(char ch)
bool C_isnotspace(char ch)
const unsigned char HEX_MASK
bool C_isnotupper(char ch)
bool C_isnotalnum(char ch)
const unsigned char IS_SPACE