12 #ifndef __SYS_String__
13 #define __SYS_String__
24 static inline constexpr
uint32
29 bool allow_nulls =
false)
31 if (!str ||
length <= 0 || (!allow_nulls && *str ==
'\0'))
47 hash = (37 * hash) + (*str);
54 hash = (37 * hash) + (*str);
69 static inline constexpr
uint32
73 bool allow_nulls =
false)
75 return SYSstring_hashseed(str, len, 0, allow_nulls);
106 SYSstrtok(
char *
string,
const char *delimit,
char **context)
109 return strtok_r(
string, delimit, context);
113 if (
string ==
nullptr)
119 string += strspn(
string, delimit);
133 string = strpbrk(token, delimit);
138 *context = strchr(token,
'\0');
145 *context =
string + 1;
182 char *
end = (
char *)::memccpy(dest, src, 0, size);
185 return end - dest - 1;
210 for (dlen = 0; dlen <
size; dlen++)
216 return dlen +
SYSstrlcpy(dest+dlen, src, size-dlen);
230 return ::stricmp(a, b);
232 return ::strcasecmp(a, b);
246 return ::strcmp(a, b);
249 #define WRAP_NULLTEST_C(FUNCTION, CONST) \
250 inline CONST char * \
251 SYS##FUNCTION(CONST char *s, int c) \
253 if (!s) return nullptr; \
254 return ::FUNCTION(s, c); \
258 #define WRAP_NULLTEST(FUNCTION) \
259 WRAP_NULLTEST_C(FUNCTION, ) \
260 WRAP_NULLTEST_C(FUNCTION, const) \
270 #undef WRAP_NULLTEST_C
282 return ::strnicmp(a, b, n);
284 return ::strncasecmp(a, b, n);
296 if (!haystack || !needle)
301 return const_cast<char *
>(haystack);
305 while(*haystack && tolower(*haystack) != tolower(*needle))
312 const char *
h = haystack, *
n = needle;
317 return const_cast<char *
>(haystack);
321 }
while(tolower(*h) == tolower(*n));
326 return const_cast<char*
>(::strcasestr(const_cast<char*>(haystack),needle));
335 size_t l = ::strlen(s);
337 char *
r = (
char *)::malloc(n + 1);
342 return ::strndup(s, n);
350 SYSisalpha(
unsigned char c)
353 return (
unsigned(c & ~(1<<5)) -
'A') <= (
'Z' -
'A');
356 SYSisdigit(
unsigned char c)
359 return (c >=
'0' && c <=
'9');
370 return ( c >= static_cast<unsigned char>(32)
371 && c < static_cast<unsigned char>(127));
378 #define SYS_IS_WRAPPER(TEST) \
379 SYS_FORCE_INLINE bool \
380 SYS##TEST(unsigned char c) \
407 #undef SYS_IS_WRAPPER
410 SYSmemrchr(
const void *
v,
int c,
exint n)
413 return ::memrchr(v, c, n);
415 const unsigned char *beg = (
const unsigned char *)v;
416 const unsigned char *full_end = (
const unsigned char *)v + n;
417 const unsigned char *
end = (
const unsigned char *)v + (n/4)*4;
418 for (
const unsigned char *
s = full_end;
s-->end;)
423 for (
const unsigned char *
s = end-1;
s > beg;)
425 if (*
s == c)
return s;
427 if (*
s == c)
return s;
429 if (*
s == c)
return s;
431 if (*
s == c)
return s;
439 SYSmemcmp(
const void *lhs,
const void *rhs,
size_t count)
441 return __builtin_memcmp(lhs, rhs, count);
444 #define CREATE_SYSisspace(TYPE) \
452 return (c == ' ' || (c <= '\xd' && c >= '\x9')); \
459 #undef CREATE_SYSisspace
size_t SYSstrlcat(char *dest, const char *src, size_t size)
#define SYS_IS_WRAPPER(TEST)
GLsizei const GLchar *const * string
#define CREATE_SYSisspace(TYPE)
GLboolean GLboolean GLboolean GLboolean a
GLuint GLsizei GLsizei * length
SYS_FORCE_INLINE bool SYSisprint(unsigned char c)
int SYSstrncasecmp(const char *a, const char *b, size_t n)
char * SYSstrtok(char *string, const char *delimit, char **context)
int SYSstrcmp(const char *a, const char *b)
size_t SYSstrlcpy(char *dest, const char *src, size_t size)
GLboolean GLboolean GLboolean b
GLfloat GLfloat GLfloat GLfloat h
char * SYSstrcasestr(const char *haystack, const char *needle)
Replacement for strcasestr, since no equivalent exists on Win32.
int SYSstrcasecmp(const char *a, const char *b)
char * SYSstrndup(const char *s, size_t n)
bool isalpha(const std::string &str)
Verify that str consists of letters only.
#define WRAP_NULLTEST(FUNCTION)