mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-27 15:01:03 +08:00
Add mg_strstr
PUBLISHED_FROM=4306e870e2cab854febb6becc198ca2247e2e002
This commit is contained in:
parent
41558bbf64
commit
2a2bc33a89
14
mongoose.c
14
mongoose.c
@ -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
|
||||
|
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user