/* The core of url_escape_* functions. Escapes the characters that match the provided mask in urlchr_table. */ static char *url_escape_1 (const char *s, unsigned char mask) { const char *p1; char *p2, *newstr; int newlen; int addition = 0; for (p1 = s; *p1; p1++) if (urlchr_test (*p1, mask)) addition += 2; if (!addition) return g_strdup (s); newlen = (p1 - s) + addition; newstr = g_malloc0 (newlen + 1); p1 = s; p2 = newstr; while (*p1) { if (urlchr_test (*p1, mask)) { unsigned char c = *p1++; *p2++ = '%'; *p2++ = XNUM_TO_DIGIT (c >> 4); *p2++ = XNUM_TO_DIGIT (c & 0xf); } else
static void _url_encode (const char *s, size_t length, char *newstr, int mask) { const char *p1; char *p2; p1 = s; p2 = newstr; while (length--) { /* Quote the characters that match the test mask. */ if (URLCHR_TEST(*p1, mask)) { unsigned char c = *p1++; *p2++ = '%'; *p2++ = XNUM_TO_DIGIT (c >> 4); *p2++ = XNUM_TO_DIGIT (c & 0xf); } else {
static CSTRING reencode_escapes (const char* src) { CSTRING dst; if(src) { while(*src) { if (char_needs_escaping (src)) { unsigned char c = *src++; dst += '%'; dst += XNUM_TO_DIGIT (c >> 4); dst += XNUM_TO_DIGIT (c & 0xf); } else dst += *src++; } }
static void copy_and_escape (const char *source, char *dest, char escape, int base) { const char *from = source; char *to = dest; unsigned char c; /* Copy chars from SOURCE to DEST, escaping non-printable ones. */ switch (base) { case 8: while ((c = *from++) != '\0') if (c_isprint (c)) *to++ = c; else { *to++ = escape; *to++ = '0' + (c >> 6); *to++ = '0' + ((c >> 3) & 7); *to++ = '0' + (c & 7); } break; case 16: while ((c = *from++) != '\0') if (c_isprint (c)) *to++ = c; else { *to++ = escape; *to++ = XNUM_TO_DIGIT (c >> 4); *to++ = XNUM_TO_DIGIT (c & 0xf); } break; default: abort (); } *to = '\0'; }