-
Notifications
You must be signed in to change notification settings - Fork 6
/
urldecode.c
38 lines (33 loc) · 892 Bytes
/
urldecode.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdlib.h>
#include <ctype.h>
#include <stdint.h>
// By ThomasH - https://stackoverflow.com/questions/2673207/c-c-url-decode-library/2766963
char *urldecode (char *dst, const char *src)
{
uint8_t a, b;
char *d = dst;
if(src) while (*src) {
if ((*src == '%') && ((a = src[1]) && (b = src[2])) && (isxdigit(a) && isxdigit(b))) {
if (a >= 'a')
a -= 'a'-'A';
if (a >= 'A')
a -= ('A' - 10);
else
a -= '0';
if (b >= 'a')
b -= 'a'-'A';
if (b >= 'A')
b -= ('A' - 10);
else
b -= '0';
*dst++ = 16 * a + b;
src+=3;
} else if (*src == '+') {
*dst++ = ' ';
src++;
} else
*dst++ = *src++;
}
*dst = '\0';
return d;
}