Commit fc635a93 authored by Marko Mikulicic's avatar Marko Mikulicic Committed by Cesanta Bot

Move mg_ncasecmp and sister to common string utils

PUBLISHED_FROM=182c43c3bd82190cb816c8ebaddccc13a94950d0
parent 81f738af
......@@ -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 }
......
---
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()`.
---
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()`.
......@@ -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
......
......@@ -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.
......
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