Add mg_strchr

Write unit tests for some mg_str functions.

PUBLISHED_FROM=1fc7e1d5d5ef259d4023f295aec8651caa3e7e86
This commit is contained in:
Deomid Ryabkov authored and Cesanta Bot committed 2017-07-03 15:05:54 +00:00
1 parent 5a0b6fc35a
commit cfd28a4f7a
2 files changed
+14

No files matched your search

+9
View File
@@ -1446,6 +1446,15 @@ struct mg_str mg_strdup_nul(const struct mg_str s) {
return mg_strdup_common(s, 1 /* NUL-terminate */);
}
const char *mg_strchr(const struct mg_str s, int c) WEAK;
const char *mg_strchr(const struct mg_str s, int c) {
size_t i;
for (i = 0; i < s.len; i++) {
if (s.p[i] == c) return &s.p[i];
}
return NULL;
}
int mg_strcmp(const struct mg_str str1, const struct mg_str str2) WEAK;
int mg_strcmp(const struct mg_str str1, const struct mg_str str2) {
size_t i = 0;