6 #ifndef TURI_STRING_INTERNALS_H_ 7 #define TURI_STRING_INTERNALS_H_ 9 namespace turi {
namespace gl_string_internal {
11 static constexpr
size_t npos = size_t(-1);
15 int _compare(
const char* __s1,
const char* __s2,
size_t __n) noexcept {
16 for (; __n; --__n, ++__s1, ++__s2) {
27 const char* _find(
const char* __s,
size_t __n,
const char& __a) noexcept {
38 size_t str_find(
const char *p,
size_t sz,
char c,
size_t pos) noexcept {
41 const char* r = _find(p + pos, sz - pos, c);
44 return static_cast<size_t>(r - p);
49 size_t str_find(
const char *p,
size_t sz,
const char* s,
size_t pos,
size_t n) noexcept {
50 if (pos > sz || sz - pos < n)
54 const char* r = std::search(p + pos, p + sz, s, s + n);
57 return static_cast<size_t>(r - p);
62 static inline size_t str_rfind(
const char *p,
size_t sz,
char c,
size_t pos) noexcept {
70 for (
const char* ps = p + pos; ps != p;) {
72 return static_cast<size_t>(ps - p);
79 static inline size_t str_rfind(
80 const char *p,
size_t sz,
const char* s,
size_t pos,
size_t n) noexcept {
82 pos = std::min(pos, sz);
88 const char* r = std::find_end(p, p + pos, s, s + n);
90 if (n > 0 && r == p + pos)
93 return static_cast<size_t>(r - p);
98 static inline size_t str_find_first_of(
99 const char *p,
size_t sz,
const char* s,
size_t pos,
size_t n) noexcept {
101 if (pos >= sz || n == 0)
103 const char* r = std::find_first_of(p + pos, p + sz, s, s + n);
106 return static_cast<size_t>(r - p);
112 static inline size_t str_find_last_of(
113 const char *p,
size_t sz,
const char* s,
size_t pos,
size_t n) noexcept {
120 for (
const char* ps = p + pos; ps != p;) {
121 const char* r = _find(s, n, *--ps);
123 return static_cast<size_t>(ps - p);
132 static inline size_t str_find_first_not_of(
133 const char *p,
size_t sz,
const char* s,
size_t pos,
size_t n) noexcept {
135 const char* pe = p + sz;
136 for (
const char* ps = p + pos; ps != pe; ++ps)
137 if (_find(s, n, *ps) == 0)
138 return static_cast<size_t>(ps - p);
145 static inline size_t str_find_first_not_of(
146 const char *p,
size_t sz,
char c,
size_t pos) noexcept {
149 const char* pe = p + sz;
150 for (
const char* ps = p + pos; ps != pe; ++ps)
152 return static_cast<size_t>(ps - p);
159 static inline size_t str_find_last_not_of(
160 const char *p,
size_t sz,
const char* s,
size_t pos,
size_t n) noexcept {
167 for (
const char* ps = p + pos; ps != p;)
168 if (_find(s, n, *--ps) == 0)
169 return static_cast<size_t>(ps - p);
174 static inline size_t str_find_last_not_of(
175 const char *p,
size_t sz,
char c,
size_t pos) noexcept {
182 for (
const char* ps = p + pos; ps != p;)
184 return static_cast<size_t>(ps - p);
189 static inline int compare(
const char* s1,
const char* s2,
size_t n) {
190 for (; n; --n, ++s1, ++s2) {
191 if (*s1 < *s2)
return -1;
192 if (*s2 < *s1)
return 1;
#define GL_HOT_INLINE_FLATTEN