|
|
|
@ -72,6 +72,8 @@ INLINE int str_to_i(str *s, int def); |
|
|
|
INLINE uint str_to_ui(str *s, int def); |
|
|
|
/* extracts the first/next token into "new_token" and modifies "ori_and_remainer" in place */ |
|
|
|
INLINE int str_token(str *new_token, str *ori_and_remainder, int sep); |
|
|
|
/* same as str_token but allows for a trailing non-empty token (e.g. "foo,bar" -> "foo", "bar" ) */ |
|
|
|
INLINE int str_token_sep(str *new_token, str *ori_and_remainder, int sep); |
|
|
|
/* copy a string to a regular C string buffer, limiting the max size */ |
|
|
|
INLINE char *str_ncpy(char *dst, size_t bufsize, const str *src); |
|
|
|
|
|
|
|
@ -320,6 +322,17 @@ INLINE int str_token(str *new_token, str *ori_and_remainder, int sep) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
INLINE int str_token_sep(str *new_token, str *ori_and_remainder, int sep) { |
|
|
|
str ori = *ori_and_remainder; |
|
|
|
if (!str_token(new_token, ori_and_remainder, sep)) |
|
|
|
return 0; |
|
|
|
// separator not found, use remainder as final token if not empty |
|
|
|
if (!ori.len) |
|
|
|
return -1; |
|
|
|
*new_token = ori; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
INLINE int str_uri_encode(char *out, const str *in) { |
|
|
|
return str_uri_encode_len(out, in->s, in->len); |
|
|
|
} |
|
|
|
|