mirror of
https://github.com/cesanta/mongoose.git
synced 2025-06-08 01:42:52 +08:00
Move mg_ncasecmp and sister to common string utils
PUBLISHED_FROM=182c43c3bd82190cb816c8ebaddccc13a94950d0
This commit is contained in:
parent
81f738af3f
commit
fc635a9340
@ -8,7 +8,6 @@ items:
|
|||||||
- { name: mg_base64_decode.md }
|
- { name: mg_base64_decode.md }
|
||||||
- { name: mg_base64_encode.md }
|
- { name: mg_base64_encode.md }
|
||||||
- { name: mg_basic_auth_header.md }
|
- { name: mg_basic_auth_header.md }
|
||||||
- { name: mg_casecmp.md }
|
|
||||||
- { name: mg_conn_addr_to_str.md }
|
- { name: mg_conn_addr_to_str.md }
|
||||||
- { name: mg_fopen.md }
|
- { name: mg_fopen.md }
|
||||||
- { name: mg_hexdump.md }
|
- { name: mg_hexdump.md }
|
||||||
@ -17,7 +16,6 @@ items:
|
|||||||
- { name: mg_match_prefix.md }
|
- { name: mg_match_prefix.md }
|
||||||
- { name: mg_mbuf_append_base64.md }
|
- { name: mg_mbuf_append_base64.md }
|
||||||
- { name: mg_mbuf_append_base64_putc.md }
|
- { name: mg_mbuf_append_base64_putc.md }
|
||||||
- { name: mg_ncasecmp.md }
|
|
||||||
- { name: mg_next_comma_list_entry.md }
|
- { name: mg_next_comma_list_entry.md }
|
||||||
- { name: mg_open.md }
|
- { name: mg_open.md }
|
||||||
- { name: mg_skip.md }
|
- { name: mg_skip.md }
|
||||||
|
@ -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()`.
|
|
||||||
|
|
@ -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()`.
|
|
||||||
|
|
34
mongoose.c
34
mongoose.c
@ -1794,6 +1794,24 @@ int64_t cs_to64(const char *s) {
|
|||||||
}
|
}
|
||||||
#endif
|
#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 */
|
#endif /* EXCLUDE_COMMON */
|
||||||
#ifdef MG_MODULE_LINES
|
#ifdef MG_MODULE_LINES
|
||||||
#line 1 "mongoose/src/tun.h"
|
#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 */
|
/* For platforms with limited libc */
|
||||||
#ifndef MAX
|
#ifndef MAX
|
||||||
#define MAX(a,b) ((a) > (b)? (a): (b))
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char *mg_skip(const char *s, const char *end, const char *delims,
|
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);
|
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
|
#if MG_ENABLE_FILESYSTEM
|
||||||
int mg_stat(const char *path, cs_stat_t *st) {
|
int mg_stat(const char *path, cs_stat_t *st) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
20
mongoose.h
20
mongoose.h
@ -1859,6 +1859,16 @@ char *strdup(const char *src);
|
|||||||
int64_t cs_to64(const char *s);
|
int64_t cs_to64(const char *s);
|
||||||
#endif
|
#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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -3640,16 +3650,6 @@ extern "C" {
|
|||||||
const char *mg_skip(const char *s, const char *end_string,
|
const char *mg_skip(const char *s, const char *end_string,
|
||||||
const char *delimiters, struct mg_str *v);
|
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`.
|
* Decodes base64-encoded string `s`, `len` into the destination `dst`.
|
||||||
* The destination has to have enough space to hold the decoded buffer.
|
* The destination has to have enough space to hold the decoded buffer.
|
||||||
|
Loading…
Reference in New Issue
Block a user