43struct [[deprecated(
"Use std::string_view instead")]]
StringRef {
47 StringRef(
const char *str,
size_t l) : p(str), len(l) {}
48 StringRef(
const char *str) : p(str), len(str ? strlen(str) : 0) {}
49 StringRef(
const std::string &str) : p(str.data()), len(str.size()) {}
64 explicit operator bool()
const {
return p != 0; }
66 bool operator==(
const StringRef &a)
const {
67 return p ? (a.p && len == a.len && (!len || !memcmp(p, a.p, len))) : !a.p;
69 bool operator!=(
const StringRef &a)
const {
return !operator==(a); }
70 bool operator==(
const std::string &a)
const {
return operator==(
StringRef(a)); }
71 bool operator==(
const char *a)
const {
72 return p ? (a && (!len || !strncmp(p, a, len)) && !a[len]) : !a;
74 bool operator==(
cstring a)
const {
return operator==(a.c_str()); }
76 bool operator!=(T a)
const {
79 bool isNullOrEmpty()
const {
return p == 0 || len == 0; }
82 if (!p)
return a.p ? -1 : 0;
84 int rv = memcmp(p, a.p, std::min(len, a.len));
85 if (!rv && len != a.len) rv = len < a.len ? -1 : 1;
88 int compare(
const std::string &a)
const {
return compare(
StringRef(a)); }
89 int compare(
const char *a)
const {
90 if (!p)
return a ? -1 : 0;
92 int rv = strncmp(p, a, len);
93 if (!rv && a[len]) rv = -1;
96 int compare(
cstring a)
const {
return compare(a.c_str()); }
98 bool operator<(T a)
const {
99 return compare(a) < 0;
102 bool operator<=(T a)
const {
103 return compare(a) <= 0;
106 bool operator>(T a)
const {
107 return compare(a) > 0;
110 bool operator>=(T a)
const {
111 return compare(a) >= 0;
114 explicit operator std::string()
const {
return std::string(p, len); }
115 operator cstring()
const {
return std::string(p, len); }
116 cstring toString()
const {
return std::string(p, len); }
117 std::string string()
const {
return std::string(p, len); }
153 char operator[](
size_t i)
const {
return i < len ? p[i] : 0; }
154 char operator*()
const {
return len ? *p : 0; }
160 StringRef &trim(
const char *white =
" \t\r\n") {
161 while (len > 0 && strchr(white, *p)) {
165 while (len > 0 && strchr(white, p[len - 1])) {
172 while (len > 0 && p[len - 1] ==
'\r') {
178 StringRef trim(
const char *white =
" \t\r\n")
const {
183 const char *begin()
const {
return p; }
184 const char *end()
const {
return p + len; }
185 const char *find(
char ch)
const {
186 return p ?
static_cast<const char *
>(memchr(p, ch, len)) : p;
188 const char *findlast(
char ch)
const {
189 return p ?
static_cast<const char *
>(memrchr(p, ch, len)) : p;
191 const char *find(
const char *set)
const {
193 size_t off = strcspn(p, set);
194 return off >= len ? 0 : p + off;
197 if (sub.len < 1)
return p;
198 const char *s = begin(), *e = end();
199 while (s < e && (s =
static_cast<const char *
>(memchr(s, *sub.p, e - s)))) {
200 if (sub.len > (
size_t)(e - s))
return nullptr;
201 if (!memcmp(s, sub.p, sub.len))
return s;
212 StringRef substr(
size_t start,
size_t length)
const {
213 if (len <= start)
return 0;
214 if (len <= length)
return StringRef(p + start, len - start);
218 Split split(
char)
const;
219 Split split(
const char *)
const;
294 Split(
StringRef r,
const char *s,
const char *p) : rest(r), set(s), ptr(p) {}
297 Split begin()
const {
return *
this; }
299 StringRef operator*()
const {
return ptr ? rest.before(ptr) : rest; }
300 Split &operator++() {
302 rest = rest.after(ptr + 1);
303 ptr = set ? rest.find(set) : rest.find(*ptr);
309 bool operator==(
const Split &a)
const {
return rest == a.rest && ptr == a.ptr; }
310 bool operator!=(
const Split &a)
const {
return rest != a.rest || ptr != a.ptr; }
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24