1 /* vi: set sw=4 ts=4: */
3 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
6 //kbuild:lib-y += percent_decode.o
10 static unsigned hex_to_bin(unsigned char c)
17 /* c | 0x20: letters to lower case, non-letters
18 * to (potentially different) non-letters */
19 v = (unsigned)(c | 0x20) - 'a';
24 void t(char c) { printf("'%c'(%u) %u\n", c, c, hex_to_bin(c)); }
25 int main() { t(0x10); t(0x20); t('0'); t('9'); t('A'); t('F'); t('a'); t('f');
26 t('0'-1); t('9'+1); t('A'-1); t('F'+1); t('a'-1); t('f'+1); return 0; }
30 char* FAST_FUNC percent_decode_in_place(char *str, int strict)
32 /* note that decoded string is always shorter than original */
37 while ((c = *src++) != '\0') {
40 if (!strict && c == '+') {
48 v = hex_to_bin(src[0]);
56 v = (v * 16) | hex_to_bin(src[1]);
59 if (strict && (v == '/' || v == '\0')) {
60 /* caller takes it as indication of invalid
61 * (dangerous wrt exploits) chars */