diff --git a/docs/README.md b/docs/README.md index 1bee1713..6736d33d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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] ``` diff --git a/mongoose.c b/mongoose.c index b230f022..c8f4c160 100644 --- a/mongoose.c +++ b/mongoose.c @@ -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); diff --git a/mongoose.h b/mongoose.h index 69883995..e46b5636 100644 --- a/mongoose.h +++ b/mongoose.h @@ -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); diff --git a/src/http.c b/src/http.c index 32a3e60d..097a48a1 100644 --- a/src/http.c +++ b/src/http.c @@ -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; } diff --git a/src/log.c b/src/log.c index b2e9e984..c8b1473c 100644 --- a/src/log.c +++ b/src/log.c @@ -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); } diff --git a/src/util.c b/src/util.c index def70bfb..4747f152 100644 --- a/src/util.c +++ b/src/util.c @@ -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); diff --git a/src/util.h b/src/util.h index e232aec0..4a391986 100644 --- a/src/util.h +++ b/src/util.h @@ -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); diff --git a/test/fuzz.c b/test/fuzz.c index 2eaf1d3f..2d1471d2 100644 --- a/test/fuzz.c +++ b/test/fuzz.c @@ -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; } diff --git a/test/unit_test.c b/test/unit_test.c index 0340de8f..e481df12 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -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) {