Commit 2a2bc33a authored by Deomid Ryabkov's avatar Deomid Ryabkov Committed by Cesanta Bot

Add mg_strstr

PUBLISHED_FROM=4306e870e2cab854febb6becc198ca2247e2e002
parent 41558bbf
...@@ -1481,6 +1481,20 @@ int mg_strncmp(const struct mg_str str1, const struct mg_str str2, size_t n) { ...@@ -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); 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 #ifdef MG_MODULE_LINES
#line 1 "common/str_util.c" #line 1 "common/str_util.c"
#endif #endif
......
...@@ -1809,6 +1809,8 @@ const char *mg_strchr(const struct mg_str s, int c); ...@@ -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_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); 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 #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment