Add mg_next_query_string_entry_n() and mg_url_decode_n()

Move to mg_util.h so encode and decode are next ot each other.

Pull out mg_next_list_entry_n() for advanced use cases.

Add unit tests.
This commit is contained in:
Deomid Ryabkov committed 2020-10-24 22:53:50 +01:00
1 parent 9fe1c93c9b
commit be64f81eee
13 files changed
+424 -156

No files matched your search

+21
View File
@@ -205,6 +205,27 @@ struct mg_str mg_url_encode_opt(const struct mg_str src,
/* Same as `mg_url_encode_opt(src, "._-$,;~()/", 0)`. */
struct mg_str mg_url_encode(const struct mg_str src);
/*
* Decodes a URL-encoded string.
*
* Source string is specified by (`src`, `src_len`), and destination is
* (`dst`, `dst_len`). If `is_form_url_encoded` is non-zero, then
* `+` character is decoded as a blank space character. This function
* guarantees to NUL-terminate the destination. If destination is too small,
* then the source string is partially decoded and `-1` is returned.
* Otherwise, the length of the decoded string is returned,
* not counting final NUL.
*/
int mg_url_decode(const char *src, int src_len, char *dst, int dst_len,
int is_form_url_encoded);
/*
* mg_str variant of mg_url_decode. Does not NUL-terminate dst.
* It is ok for src and dst to be the same.
*/
int mg_url_decode_n(struct mg_str src, struct mg_str *dst,
int is_form_url_encoded);
#ifdef __cplusplus
}
#endif /* __cplusplus */