From cfd28a4f7a7e5017feadddf9c66afeeaf7698322 Mon Sep 17 00:00:00 2001 From: Deomid Ryabkov Date: Mon, 3 Jul 2017 17:55:24 +0300 Subject: [PATCH] Add mg_strchr Write unit tests for some mg_str functions. PUBLISHED_FROM=1fc7e1d5d5ef259d4023f295aec8651caa3e7e86 --- mongoose.c | 9 +++++++++ mongoose.h | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/mongoose.c b/mongoose.c index 7e4cbeb1..986e424f 100644 --- a/mongoose.c +++ b/mongoose.c @@ -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; diff --git a/mongoose.h b/mongoose.h index acf01c79..4292276d 100644 --- a/mongoose.h +++ b/mongoose.h @@ -1801,6 +1801,11 @@ struct mg_str mg_strdup(const struct mg_str s); */ struct mg_str mg_strdup_nul(const struct mg_str s); +/* + * Locates character in a string. + */ +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);