diff --git a/docs/c-api/util.h/intro.md b/docs/c-api/util.h/intro.md index 0268cd7d..62f2f5e6 100644 --- a/docs/c-api/util.h/intro.md +++ b/docs/c-api/util.h/intro.md @@ -8,7 +8,6 @@ items: - { name: mg_base64_decode.md } - { name: mg_base64_encode.md } - { name: mg_basic_auth_header.md } - - { name: mg_casecmp.md } - { name: mg_conn_addr_to_str.md } - { name: mg_fopen.md } - { name: mg_hexdump.md } @@ -17,7 +16,6 @@ items: - { name: mg_match_prefix.md } - { name: mg_mbuf_append_base64.md } - { name: mg_mbuf_append_base64_putc.md } - - { name: mg_ncasecmp.md } - { name: mg_next_comma_list_entry.md } - { name: mg_open.md } - { name: mg_skip.md } diff --git a/docs/c-api/util.h/mg_casecmp.md b/docs/c-api/util.h/mg_casecmp.md deleted file mode 100644 index 8d23dbf6..00000000 --- a/docs/c-api/util.h/mg_casecmp.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_casecmp()" -decl_name: "mg_casecmp" -symbol_kind: "func" -signature: | - int mg_casecmp(const char *s1, const char *s2); ---- - -Cross-platform version of `strcasecmp()`. - diff --git a/docs/c-api/util.h/mg_ncasecmp.md b/docs/c-api/util.h/mg_ncasecmp.md deleted file mode 100644 index 3e113810..00000000 --- a/docs/c-api/util.h/mg_ncasecmp.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_ncasecmp()" -decl_name: "mg_ncasecmp" -symbol_kind: "func" -signature: | - int mg_ncasecmp(const char *s1, const char *s2, size_t len); ---- - -Cross-platform version of `strncasecmp()`. - diff --git a/mongoose.c b/mongoose.c index 28842fef..fe993814 100644 --- a/mongoose.c +++ b/mongoose.c @@ -1794,6 +1794,24 @@ int64_t cs_to64(const char *s) { } #endif +static int str_util_lowercase(const char *s) { + return tolower(*(const unsigned char *) s); +} + +int mg_ncasecmp(const char *s1, const char *s2, size_t len) { + int diff = 0; + + if (len > 0) do { + diff = str_util_lowercase(s1++) - str_util_lowercase(s2++); + } while (diff == 0 && s1[-1] != '\0' && --len > 0); + + return diff; +} + +int mg_casecmp(const char *s1, const char *s2) { + return mg_ncasecmp(s1, s2, (size_t) ~0); +} + #endif /* EXCLUDE_COMMON */ #ifdef MG_MODULE_LINES #line 1 "mongoose/src/tun.h" @@ -8891,7 +8909,7 @@ struct mg_connection *mg_connect_ws(struct mg_mgr *mgr, /* For platforms with limited libc */ #ifndef MAX -#define MAX(a,b) ((a) > (b)? (a): (b)) +#define MAX(a, b) ((a) > (b) ? (a) : (b)) #endif const char *mg_skip(const char *s, const char *end, const char *delims, @@ -8907,20 +8925,6 @@ static int lowercase(const char *s) { return tolower(*(const unsigned char *) s); } -int mg_ncasecmp(const char *s1, const char *s2, size_t len) { - int diff = 0; - - if (len > 0) do { - diff = lowercase(s1++) - lowercase(s2++); - } while (diff == 0 && s1[-1] != '\0' && --len > 0); - - return diff; -} - -int mg_casecmp(const char *s1, const char *s2) { - return mg_ncasecmp(s1, s2, (size_t) ~0); -} - #if MG_ENABLE_FILESYSTEM int mg_stat(const char *path, cs_stat_t *st) { #ifdef _WIN32 diff --git a/mongoose.h b/mongoose.h index 1ba48c47..57d13eed 100644 --- a/mongoose.h +++ b/mongoose.h @@ -1859,6 +1859,16 @@ char *strdup(const char *src); int64_t cs_to64(const char *s); #endif +/* + * Cross-platform version of `strncasecmp()`. + */ +int mg_ncasecmp(const char *s1, const char *s2, size_t len); + +/* + * Cross-platform version of `strcasecmp()`. + */ +int mg_casecmp(const char *s1, const char *s2); + #ifdef __cplusplus } #endif @@ -3640,16 +3650,6 @@ extern "C" { const char *mg_skip(const char *s, const char *end_string, const char *delimiters, struct mg_str *v); -/* - * Cross-platform version of `strncasecmp()`. - */ -int mg_ncasecmp(const char *s1, const char *s2, size_t len); - -/* - * Cross-platform version of `strcasecmp()`. - */ -int mg_casecmp(const char *s1, const char *s2); - /* * Decodes base64-encoded string `s`, `len` into the destination `dst`. * The destination has to have enough space to hold the decoded buffer.