-
Notifications
You must be signed in to change notification settings - Fork 2.8k
mg_split -> mg_span. Remove mg_commalist #2597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,31 +129,17 @@ bool mg_globmatch(const char *s1, size_t n1, const char *s2, size_t n2) { | |
return mg_match(mg_str_n(s2, n2), mg_str_n(s1, n1), NULL); | ||
} | ||
|
||
static size_t mg_nce(const char *s, size_t n, size_t ofs, size_t *koff, | ||
size_t *klen, size_t *voff, size_t *vlen, char delim) { | ||
size_t kvlen, kl; | ||
for (kvlen = 0; ofs + kvlen < n && s[ofs + kvlen] != delim;) kvlen++; | ||
for (kl = 0; kl < kvlen && s[ofs + kl] != '=';) kl++; | ||
if (koff != NULL) *koff = ofs; | ||
if (klen != NULL) *klen = kl; | ||
if (voff != NULL) *voff = kl < kvlen ? ofs + kl + 1 : 0; | ||
if (vlen != NULL) *vlen = kl < kvlen ? kvlen - kl - 1 : 0; | ||
ofs += kvlen + 1; | ||
return ofs > n ? n : ofs; | ||
} | ||
|
||
bool mg_split(struct mg_str *s, struct mg_str *k, struct mg_str *v, char sep) { | ||
size_t koff = 0, klen = 0, voff = 0, vlen = 0, off = 0; | ||
if (s->ptr == NULL || s->len == 0) return 0; | ||
off = mg_nce(s->ptr, s->len, 0, &koff, &klen, &voff, &vlen, sep); | ||
if (k != NULL) *k = mg_str_n(s->ptr + koff, klen); | ||
if (v != NULL) *v = mg_str_n(s->ptr + voff, vlen); | ||
*s = mg_str_n(s->ptr + off, s->len - off); | ||
return off > 0; | ||
} | ||
|
||
bool mg_commalist(struct mg_str *s, struct mg_str *k, struct mg_str *v) { | ||
return mg_split(s, k, v, ','); | ||
bool mg_span(struct mg_str s, struct mg_str *a, struct mg_str *b, char sep) { | ||
if (s.len == 0 || s.ptr == NULL) { | ||
return false; // Empty string, nothing to span - fail | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No actual need for this else clause |
||
size_t len = 0; | ||
while (len < s.len && s.ptr[len] != sep) len++; // Find separator | ||
if (a) *a = mg_str_n(s.ptr, len); // Init a | ||
if (b) *b = mg_str_n(s.ptr + len, s.len - len); // Init b | ||
if (b && len < s.len) b->ptr++, b->len--; // Skip separator | ||
Comment on lines
+136
to
+140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool... |
||
return true; | ||
} | ||
} | ||
|
||
char *mg_hex(const void *buf, size_t len, char *to) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmm... I'm not sure...
We have other events that are INFO, in MIP for example. Yes, those are more important...