Move mg_ncasecmp and sister to common string utils

PUBLISHED_FROM=182c43c3bd82190cb816c8ebaddccc13a94950d0
This commit is contained in:
Marko Mikulicic authored and Cesanta Bot committed 2016-11-17 11:21:17 +00:00
1 parent 81f738af3f
commit fc635a9340
5 files changed
+29 -47

No files matched your search

+19 -15
View File
@@ -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