-
Notifications
You must be signed in to change notification settings - Fork 121
/
UrlDecode.cpp
76 lines (67 loc) · 1.44 KB
/
UrlDecode.cpp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
WCHAR *UrlDecodeWCHAR(WCHAR *String1)
{
WCHAR *String2 = new WCHAR[wcslen(String1) - 1];
int Flag = 0;
for (int i = 0; i < wcslen(String1); i++)
{
if ((String1[i + Flag * 2] == L'%') && (String1[i + 1 + Flag * 2] == L'2'))
{
if (String1[i + 2 + Flag * 2] == L'0')
String2[i] = L' ';
else if (String1[i + 2 + Flag * 2] == L'2')
String2[i] = L'\"';
else if (String1[i + 2 + Flag * 2] == L'7')
String2[i] = L'\'';
else
continue;
Flag++;
}
else
{
String2[i] = String1[i + Flag * 2];
}
}
String2[wcslen(String1)] = '\0';
// printf("%ws", String2);
return String2;
}
char *UrlDecodeChar(char *String1)
{
char *String2 = new char[strlen(String1) - 1];
int Flag = 0;
for (int i = 0; i < strlen(String1); i++)
{
if ((String1[i + Flag * 2] == '%') && (String1[i + 1 + Flag * 2] == '2'))
{
if (String1[i+2 + Flag * 2] == '0')
String2[i] = ' ';
else if (String1[i + 2 + Flag * 2] == '2')
String2[i] = '\"';
else if (String1[i + 2 + Flag * 2] == '7')
String2[i] = '\'';
else
continue;
Flag++;
}
else
{
String2[i] = String1[i + Flag * 2];
}
}
String2[strlen(String1)] = '\0';
// printf("%s", String2);
return String2;
}
int main()
{
WCHAR *a = L"ab%22cd%20ef%27gh";
WCHAR *b = UrlDecodeWCHAR(a);
printf("%ws\n", b);
char *c = "ab%22cd%20ef%27gh";
char *d = UrlDecodeChar(c);
printf("%s\n", d);
return 0;
}