mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-27 06:51:04 +08:00
mg_next_comma_entry -> mg_comma
This commit is contained in:
parent
9b37ac384f
commit
1c456fc2df
@ -1216,7 +1216,7 @@ The glob pattern matching rules are as follows:
|
||||
### mg\_next\_comma\_entry()
|
||||
|
||||
```c
|
||||
bool mg_next_comma_entry(struct mg_str *s, struct mg_str *k, struct mg_str *v);
|
||||
bool mg_comma(struct mg_str *s, struct mg_str *k, struct mg_str *v);
|
||||
```
|
||||
|
||||
Parse string `s`, which is a comma-separated list of entries. An entry could be
|
||||
@ -1228,7 +1228,7 @@ example:
|
||||
|
||||
```c
|
||||
struct mg_str k, v, s = mg_str("a=333,b=777");
|
||||
while (mg_next_comma_entry(&s, &k, &v)) // This loop output:
|
||||
while (mg_comma(&s, &k, &v)) // This loop output:
|
||||
printf("[%.*s] set to [%.*s]\n", // [a] set to [333]
|
||||
(int) k.len, k.ptr, (int) v.len, v.ptr); // [b] set to [777]
|
||||
```
|
||||
|
@ -1260,7 +1260,7 @@ static struct mg_str guess_content_type(struct mg_str path, const char *extra) {
|
||||
path.len = i;
|
||||
|
||||
// Process user-provided mime type overrides, if any
|
||||
while (mg_next_comma_entry(&s, &k, &v)) {
|
||||
while (mg_comma(&s, &k, &v)) {
|
||||
if (mg_strcmp(path, k) == 0) return v;
|
||||
}
|
||||
|
||||
@ -1820,7 +1820,7 @@ bool mg_log_prefix(int level, const char *file, int line, const char *fname) {
|
||||
if (p == NULL) p = strrchr(file, '\\');
|
||||
p = p == NULL ? file : p + 1;
|
||||
|
||||
while (mg_next_comma_entry(&s, &k, &v)) {
|
||||
while (mg_comma(&s, &k, &v)) {
|
||||
if (v.len == 0) max = atoi(k.ptr);
|
||||
if (v.len > 0 && strncmp(p, k.ptr, k.len) == 0) max = atoi(v.ptr);
|
||||
}
|
||||
@ -4230,7 +4230,7 @@ static size_t mg_nce(const char *s, size_t n, size_t ofs, size_t *koff,
|
||||
return ofs > n ? n : ofs;
|
||||
}
|
||||
|
||||
bool mg_next_comma_entry(struct mg_str *s, struct mg_str *k, struct mg_str *v) {
|
||||
bool mg_comma(struct mg_str *s, struct mg_str *k, struct mg_str *v) {
|
||||
size_t koff = 0, klen = 0, voff = 0, vlen = 0;
|
||||
size_t off = mg_nce(s->ptr, s->len, 0, &koff, &klen, &voff, &vlen);
|
||||
if (k != NULL) *k = mg_str_n(s->ptr + koff, klen);
|
||||
|
@ -536,7 +536,7 @@ bool mg_file_write(const char *path, const void *buf, size_t len);
|
||||
bool mg_file_printf(const char *path, const char *fmt, ...);
|
||||
void mg_random(void *buf, size_t len);
|
||||
bool mg_globmatch(const char *pattern, size_t plen, const char *s, size_t n);
|
||||
bool mg_next_comma_entry(struct mg_str *s, struct mg_str *k, struct mg_str *v);
|
||||
bool mg_comma(struct mg_str *s, struct mg_str *k, struct mg_str *v);
|
||||
uint16_t mg_ntohs(uint16_t net);
|
||||
uint32_t mg_ntohl(uint32_t net);
|
||||
uint32_t mg_crc32(uint32_t crc, const char *buf, size_t len);
|
||||
|
@ -489,7 +489,7 @@ static struct mg_str guess_content_type(struct mg_str path, const char *extra) {
|
||||
path.len = i;
|
||||
|
||||
// Process user-provided mime type overrides, if any
|
||||
while (mg_next_comma_entry(&s, &k, &v)) {
|
||||
while (mg_comma(&s, &k, &v)) {
|
||||
if (mg_strcmp(path, k) == 0) return v;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ bool mg_log_prefix(int level, const char *file, int line, const char *fname) {
|
||||
if (p == NULL) p = strrchr(file, '\\');
|
||||
p = p == NULL ? file : p + 1;
|
||||
|
||||
while (mg_next_comma_entry(&s, &k, &v)) {
|
||||
while (mg_comma(&s, &k, &v)) {
|
||||
if (v.len == 0) max = atoi(k.ptr);
|
||||
if (v.len > 0 && strncmp(p, k.ptr, k.len) == 0) max = atoi(v.ptr);
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ static size_t mg_nce(const char *s, size_t n, size_t ofs, size_t *koff,
|
||||
return ofs > n ? n : ofs;
|
||||
}
|
||||
|
||||
bool mg_next_comma_entry(struct mg_str *s, struct mg_str *k, struct mg_str *v) {
|
||||
bool mg_comma(struct mg_str *s, struct mg_str *k, struct mg_str *v) {
|
||||
size_t koff = 0, klen = 0, voff = 0, vlen = 0;
|
||||
size_t off = mg_nce(s->ptr, s->len, 0, &koff, &klen, &voff, &vlen);
|
||||
if (k != NULL) *k = mg_str_n(s->ptr + koff, klen);
|
||||
|
@ -8,7 +8,7 @@ bool mg_file_write(const char *path, const void *buf, size_t len);
|
||||
bool mg_file_printf(const char *path, const char *fmt, ...);
|
||||
void mg_random(void *buf, size_t len);
|
||||
bool mg_globmatch(const char *pattern, size_t plen, const char *s, size_t n);
|
||||
bool mg_next_comma_entry(struct mg_str *s, struct mg_str *k, struct mg_str *v);
|
||||
bool mg_comma(struct mg_str *s, struct mg_str *k, struct mg_str *v);
|
||||
uint16_t mg_ntohs(uint16_t net);
|
||||
uint32_t mg_ntohl(uint32_t net);
|
||||
uint32_t mg_crc32(uint32_t crc, const char *buf, size_t len);
|
||||
|
@ -41,7 +41,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
mg_globmatch((char *) data, size, (char *) data, size);
|
||||
|
||||
struct mg_str k, v, s = mg_str_n((char *) data, size);
|
||||
while (mg_next_comma_entry(&s, &k, &v)) k.len = v.len = 0;
|
||||
while (mg_comma(&s, &k, &v)) k.len = v.len = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -41,28 +41,28 @@ static void test_globmatch(void) {
|
||||
static void test_commalist(void) {
|
||||
struct mg_str k, v, s1 = mg_str(""), s2 = mg_str("a"), s3 = mg_str("a,b");
|
||||
struct mg_str s4 = mg_str("a=123"), s5 = mg_str("a,b=123");
|
||||
ASSERT(mg_next_comma_entry(&s1, &k, &v) == false);
|
||||
ASSERT(mg_comma(&s1, &k, &v) == false);
|
||||
|
||||
ASSERT(mg_next_comma_entry(&s2, &k, &v) == true);
|
||||
ASSERT(mg_comma(&s2, &k, &v) == true);
|
||||
ASSERT(v.len == 0 && mg_vcmp(&k, "a") == 0);
|
||||
ASSERT(mg_next_comma_entry(&s2, &k, &v) == false);
|
||||
ASSERT(mg_comma(&s2, &k, &v) == false);
|
||||
|
||||
ASSERT(mg_next_comma_entry(&s3, &k, &v) == true);
|
||||
ASSERT(mg_comma(&s3, &k, &v) == true);
|
||||
ASSERT(v.len == 0 && mg_vcmp(&k, "a") == 0);
|
||||
ASSERT(mg_next_comma_entry(&s3, &k, &v) == true);
|
||||
ASSERT(mg_comma(&s3, &k, &v) == true);
|
||||
ASSERT(v.len == 0 && mg_vcmp(&k, "b") == 0);
|
||||
ASSERT(mg_next_comma_entry(&s3, &k, &v) == false);
|
||||
ASSERT(mg_comma(&s3, &k, &v) == false);
|
||||
|
||||
ASSERT(mg_next_comma_entry(&s4, &k, &v) == true);
|
||||
ASSERT(mg_comma(&s4, &k, &v) == true);
|
||||
ASSERT(mg_vcmp(&k, "a") == 0 && mg_vcmp(&v, "123") == 0);
|
||||
ASSERT(mg_next_comma_entry(&s4, &k, &v) == false);
|
||||
ASSERT(mg_next_comma_entry(&s4, &k, &v) == false);
|
||||
ASSERT(mg_comma(&s4, &k, &v) == false);
|
||||
ASSERT(mg_comma(&s4, &k, &v) == false);
|
||||
|
||||
ASSERT(mg_next_comma_entry(&s5, &k, &v) == true);
|
||||
ASSERT(mg_comma(&s5, &k, &v) == true);
|
||||
ASSERT(v.len == 0 && mg_vcmp(&k, "a") == 0);
|
||||
ASSERT(mg_next_comma_entry(&s5, &k, &v) == true);
|
||||
ASSERT(mg_comma(&s5, &k, &v) == true);
|
||||
ASSERT(mg_vcmp(&k, "b") == 0 && mg_vcmp(&v, "123") == 0);
|
||||
ASSERT(mg_next_comma_entry(&s4, &k, &v) == false);
|
||||
ASSERT(mg_comma(&s4, &k, &v) == false);
|
||||
}
|
||||
|
||||
static void test_http_get_var(void) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user