Bonjour,
Dans mon programme je récupère une chaîne, à laquelle j'ai appliqué la fonction urlencode en php. Mon but est donc de la décoder en C.
Cette fonction existe - elle en bibliothèque standard?
Version imprimable
Bonjour,
Dans mon programme je récupère une chaîne, à laquelle j'ai appliqué la fonction urlencode en php. Mon but est donc de la décoder en C.
Cette fonction existe - elle en bibliothèque standard?
Absolument pas dans LA bibliothèque C standard.
Par contre, des bibliothèques externes comme curl doivent permettre ça...
c'est bon j'ai trouvé une petite fonction résolvant mon problème je l'inquiqe pour ceux que ça intéresse :
Code:
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 void SwapChar(char * pOriginal, char cBad, char cGood) { int i; // generic counter variable // Loop through the input string (cOriginal), character by // character, replacing each instance of cBad with cGood i = 0; while (pOriginal[i]) { if (pOriginal[i] == cBad) pOriginal[i] = cGood; i++; } } // Now, a subroutine that unescapes escaped characters. static int IntFromHex(char *pChars) { int Hi; // holds high byte int Lo; // holds low byte int Result; // holds result // Get the value of the first byte to Hi Hi = pChars[0]; if ('0' <= Hi && Hi <= '9') { Hi -= '0'; } else if ('a' <= Hi && Hi <= 'f') { Hi -= ('a'-10); } else if ('A' <= Hi && Hi <= 'F') { Hi -= ('A'-10); } // Get the value of the second byte to Lo Lo = pChars[1]; if ('0' <= Lo && Lo <= '9') { Lo -= '0'; } else if ('a' <= Lo && Lo <= 'f') { Lo -= ('a'-10); } else if ('A' <= Lo && Lo <= 'F') { Lo -= ('A'-10); } Result = Lo + (16 * Hi); return (Result); } void urldecode(unsigned char *pEncoded) { char *pDecoded; // generic pointer // First, change those pesky plusses to spaces SwapChar (pEncoded, '+', ' '); // Now, loop through looking for escapes pDecoded = pEncoded; while (*pEncoded) { if (*pEncoded=='%') { // A percent sign followed by two hex digits means // that the digits represent an escaped character. // We must decode it. pEncoded++; if (isxdigit(pEncoded[0]) && isxdigit(pEncoded[1])) { *pDecoded++ = (char) IntFromHex(pEncoded); pEncoded += 2; } } else { *pDecoded ++ = *pEncoded++; } } *pDecoded = '\0'; }