20 namespace strings_internal {
23 const unsigned char* us1 =
reinterpret_cast<const unsigned char*
>(s1);
24 const unsigned char* us2 =
reinterpret_cast<const unsigned char*
>(s2);
26 for (
size_t i = 0;
i <
len;
i++) {
30 if (diff != 0)
return diff;
35 char*
memdup(
const char* s,
size_t slen) {
37 if ((copy = malloc(slen)) ==
nullptr)
return nullptr;
38 memcpy(copy, s, slen);
39 return reinterpret_cast<char*
>(copy);
42 char*
memrchr(
const char* s,
int c,
size_t slen) {
43 for (
const char* e = s + slen - 1; e >= s; e--) {
44 if (*e == c)
return const_cast<char*
>(e);
49 size_t memspn(
const char* s,
size_t slen,
const char* accept) {
56 if (slen-- == 0)
return p - 1 - s;
57 for (spanp = accept; (sc = *spanp++) !=
'\0';)
58 if (sc == c)
goto cont;
62 size_t memcspn(
const char* s,
size_t slen,
const char* reject) {
69 for (spanp = reject; (sc = *spanp++) !=
'\0';)
70 if (sc == c)
return p - 1 - s;
75 char*
mempbrk(
const char* s,
size_t slen,
const char* accept) {
79 for (; slen; ++s, --slen) {
80 for (scanp = accept; (sc = *scanp++) !=
'\0';)
81 if (sc == *s)
return const_cast<char*
>(s);
88 const char*
memmatch(
const char* phaystack,
size_t haylen,
const char* pneedle,
93 if (haylen < neelen)
return nullptr;
96 const char* hayend = phaystack + haylen - neelen + 1;
99 while ((match = static_cast<const char*>(
100 memchr(phaystack, pneedle[0], hayend - phaystack)))) {
101 if (memcmp(match, pneedle, neelen) == 0)
104 phaystack = match + 1;
size_t memspn(const char *s, size_t slen, const char *accept)
char * memrchr(const char *s, int c, size_t slen)
char * memdup(const char *s, size_t slen)
char * mempbrk(const char *s, size_t slen, const char *accept)
size_t memcspn(const char *s, size_t slen, const char *reject)
const char * memmatch(const char *phaystack, size_t haylen, const char *pneedle, size_t neelen)
char ascii_tolower(unsigned char c)
int memcasecmp(const char *s1, const char *s2, size_t len)