Add mg_strstr

PUBLISHED_FROM=4306e870e2cab854febb6becc198ca2247e2e002
This commit is contained in:
Deomid Ryabkov 2017-07-05 17:14:34 +01:00 committed by Cesanta Bot
parent 41558bbf64
commit 2a2bc33a89
2 changed files with 16 additions and 0 deletions

View File

@ -1481,6 +1481,20 @@ int mg_strncmp(const struct mg_str str1, const struct mg_str str2, size_t n) {
}
return mg_strcmp(s1, s2);
}
const char *mg_strstr(const struct mg_str haystack,
const struct mg_str needle) WEAK;
const char *mg_strstr(const struct mg_str haystack,
const struct mg_str needle) {
size_t i;
if (needle.len > haystack.len) return NULL;
for (i = 0; i <= haystack.len - needle.len; i++) {
if (memcmp(haystack.p + i, needle.p, needle.len) == 0) {
return haystack.p + i;
}
}
return NULL;
}
#ifdef MG_MODULE_LINES
#line 1 "common/str_util.c"
#endif

View File

@ -1809,6 +1809,8 @@ const char *mg_strchr(const struct mg_str s, int c);
int mg_strcmp(const struct mg_str str1, const struct mg_str str2);
int mg_strncmp(const struct mg_str str1, const struct mg_str str2, size_t n);
const char *mg_strstr(const struct mg_str haystack, const struct mg_str needle);
#ifdef __cplusplus
}
#endif /* __cplusplus */