21 #include "gtest/gtest.h" 26 static char* memcasechr(
const char* s,
int c,
size_t slen) {
28 for (; slen; ++s, --slen) {
34 static const char* memcasematch(
const char* phaystack,
size_t haylen,
35 const char* pneedle,
size_t neelen) {
39 if (haylen < neelen)
return nullptr;
42 const char* hayend = phaystack + haylen - neelen + 1;
43 while ((match = static_cast<char*>(
44 memcasechr(phaystack, pneedle[0], hayend - phaystack)))) {
48 phaystack = match + 1;
53 TEST(MemUtilTest, AllTests) {
60 sizeof(
"hello there") - 1),
63 sizeof(
"hello there") - 1),
66 sizeof(
"hello there") - 2),
74 sizeof(
"hello there") - 1);
75 EXPECT_TRUE(p && p[-1] ==
'r');
77 sizeof(
"hello there") - 2);
78 EXPECT_TRUE(p && p[-1] ==
'h');
80 sizeof(
"hello there") - 1);
81 EXPECT_TRUE(p ==
nullptr);
84 sizeof(
"hello there") - 1,
"hole");
85 EXPECT_EQ(len,
sizeof(
"hello") - 1);
94 EXPECT_EQ(len,
sizeof(
"hello there") - 1);
96 sizeof(
"hello there!") - 1,
"trole h");
97 EXPECT_EQ(len,
sizeof(
"hello there") - 1);
99 sizeof(
"hello there!") - 2,
"trole h!");
100 EXPECT_EQ(len,
sizeof(
"hello there!") - 2);
103 sizeof(
"hello there") - 1,
"leho");
106 sizeof(
"hello there") - 1,
"u");
107 EXPECT_EQ(len,
sizeof(
"hello there") - 1);
109 sizeof(
"hello there") - 1,
"");
110 EXPECT_EQ(len,
sizeof(
"hello there") - 1);
112 sizeof(
"hello there") - 1,
" ");
117 EXPECT_TRUE(p && p[1] ==
'e' && p[2] ==
'l');
120 EXPECT_TRUE(p ==
nullptr);
122 sizeof(
"hello there!") - 2,
"!");
123 EXPECT_TRUE(p ==
nullptr);
126 EXPECT_TRUE(p && p[-1] ==
'o' && p[1] ==
't');
129 const char kHaystack[] =
"0123456789";
145 const char kHaystack[] =
"aBcDeFgHiJ";
162 const char kHaystack[] =
"0123456789";
char * memcat(char *dest, size_t destlen, const char *src, size_t srclen)
size_t memspn(const char *s, size_t slen, const char *accept)
const char * memmem(const char *phaystack, size_t haylen, const char *pneedle, size_t needlelen)
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)
TEST(Symbolize, Unimplemented)
const char * memmatch(const char *phaystack, size_t haylen, const char *pneedle, size_t neelen)
char ascii_tolower(unsigned char c)
const char * memcasemem(const char *phaystack, size_t haylen, const char *pneedle, size_t needlelen)
int memcasecmp(const char *s1, const char *s2, size_t len)