}
}
-static int is_rfc3986_reserved(char ch)
+int is_rfc3986_reserved_or_unreserved(char ch)
{
+ if (is_rfc3986_unreserved(ch))
+ return 1;
switch (ch) {
case '!': case '*': case '\'': case '(': case ')': case ';':
case ':': case '@': case '&': case '=': case '+': case '$':
return 0;
}
-static int is_rfc3986_unreserved(char ch)
+int is_rfc3986_unreserved(char ch)
{
return isalnum(ch) ||
ch == '-' || ch == '_' || ch == '.' || ch == '~';
}
static void strbuf_add_urlencode(struct strbuf *sb, const char *s, size_t len,
- int reserved)
+ char_predicate allow_unencoded_fn)
{
strbuf_grow(sb, len);
while (len--) {
char ch = *s++;
- if (is_rfc3986_unreserved(ch) ||
- (!reserved && is_rfc3986_reserved(ch)))
+ if (allow_unencoded_fn(ch))
strbuf_addch(sb, ch);
else
strbuf_addf(sb, "%%%02x", (unsigned char)ch);
}
void strbuf_addstr_urlencode(struct strbuf *sb, const char *s,
- int reserved)
+ char_predicate allow_unencoded_fn)
{
- strbuf_add_urlencode(sb, s, strlen(s), reserved);
+ strbuf_add_urlencode(sb, s, strlen(s), allow_unencoded_fn);
}
static void strbuf_humanise(struct strbuf *buf, off_t bytes,