mirror of
https://github.com/cesanta/mongoose.git
synced 2024-11-24 02:59:01 +08:00
Add mg_strcasecmp()
CL: Add mg_strcasecmp() PUBLISHED_FROM=cd2a26fa12473bfa0f5e7a0a1d34fb86562ee082
This commit is contained in:
parent
10b11b03a8
commit
70dc6d8dc9
21
mongoose.c
21
mongoose.c
@ -1764,8 +1764,10 @@ 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;
|
||||
while (i < str1.len && i < str2.len) {
|
||||
if (str1.p[i] < str2.p[i]) return -1;
|
||||
if (str1.p[i] > str2.p[i]) return 1;
|
||||
int c1 = str1.p[i];
|
||||
int c2 = str2.p[i];
|
||||
if (c1 < c2) return -1;
|
||||
if (c1 > c2) return 1;
|
||||
i++;
|
||||
}
|
||||
if (i < str1.len) return 1;
|
||||
@ -1787,6 +1789,21 @@ int mg_strncmp(const struct mg_str str1, const struct mg_str str2, size_t n) {
|
||||
return mg_strcmp(s1, s2);
|
||||
}
|
||||
|
||||
int mg_strcasecmp(const struct mg_str str1, const struct mg_str str2) WEAK;
|
||||
int mg_strcasecmp(const struct mg_str str1, const struct mg_str str2) {
|
||||
size_t i = 0;
|
||||
while (i < str1.len && i < str2.len) {
|
||||
int c1 = tolower((int) str1.p[i]);
|
||||
int c2 = tolower((int) str2.p[i]);
|
||||
if (c1 < c2) return -1;
|
||||
if (c1 > c2) return 1;
|
||||
i++;
|
||||
}
|
||||
if (i < str1.len) return 1;
|
||||
if (i < str2.len) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mg_strfree(struct mg_str *s) WEAK;
|
||||
void mg_strfree(struct mg_str *s) {
|
||||
char *sp = (char *) s->p;
|
||||
|
@ -2351,6 +2351,11 @@ 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);
|
||||
|
||||
/*
|
||||
* Compare two `mg_str`s ignoreing case; return value is the same as `strcmp`.
|
||||
*/
|
||||
int mg_strcasecmp(const struct mg_str str1, const struct mg_str str2);
|
||||
|
||||
/*
|
||||
* Free the string (assuming it was heap allocated).
|
||||
*/
|
||||
@ -6239,6 +6244,7 @@ int mg_dns_encode_record(struct mbuf *io, struct mg_dns_resource_record *rr,
|
||||
* Encodes a DNS name.
|
||||
*/
|
||||
int mg_dns_encode_name(struct mbuf *io, const char *name, size_t len);
|
||||
int mg_dns_encode_name_s(struct mbuf *io, struct mg_str name);
|
||||
|
||||
/* Low-level: parses a DNS response. */
|
||||
int mg_parse_dns(const char *buf, int len, struct mg_dns_message *msg);
|
||||
|
Loading…
Reference in New Issue
Block a user