56 if (c >=
'0' && c <=
'9') {
58 }
else if (c >=
'A' && c <=
'F') {
68 size_t *length_out,
char **result_out)
75 if ((str == NULL) || (result_out == NULL)) {
83 result = malloc(length + 1);
89 str_end = str + length;
92 while (str < str_end) {
107 while (str < str_end) {
112 new_len = res_pos -
result;
114 if (new_len != length) {
116 char *tmp = realloc(
result, new_len + 1);
122 if (length_out != NULL) {
123 *length_out = new_len;
132 const char *escexceptions,
char **
result)
138 if (unescaped == NULL ||
result == NULL) {
142 len = strlen(unescaped);
144 escaped = malloc(len * 3 + 1);
145 if (escaped == NULL) {
150 for (c = unescaped; *c !=
'\0'; c++) {
158 "<>%\"{}|\\^`~" , *c) &&
160 !strchr(escexceptions, *c))) ||
161 *c <= 0x20 || *c == 0x7f) {
162 if (*c == 0x20 && sptoplus) {
166 *pos++ =
"0123456789ABCDEF"[(*c >> 4) & 0xf];
167 *pos++ =
"0123456789ABCDEF"[*c & 0xf];
175 new_len = pos - escaped;
177 if (new_len != len) {
179 char *tmp = realloc(escaped, new_len + 1);
Helpers for ASCII string handling.
static bool ascii_is_hex(char c)
Test whether a character is hexadecimal (upper or lower case).
nserror
Enumeration of error codes.
@ NSERROR_BAD_PARAMETER
Bad Parameter.
@ NSERROR_NOMEM
Memory exhaustion.
Interface to utility string handling.
nserror url_escape(const char *unescaped, bool sptoplus, const char *escexceptions, char **result)
Escape a string suitable for inclusion in an URL.
nserror url_unescape(const char *str, size_t length, size_t *length_out, char **result_out)
Convert an escaped string to plain.
static char xdigit_to_hex(char c)
Convert a hex digit to a hex value.
Interface to URL parsing and joining operations.