Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -3,38 +3,38 @@
|
|||
|
||||
inline int ishex(int x)
|
||||
{
|
||||
return (x >= '0' && x <= '9') ||
|
||||
(x >= 'a' && x <= 'f') ||
|
||||
(x >= 'A' && x <= 'F');
|
||||
return (x >= '0' && x <= '9') ||
|
||||
(x >= 'a' && x <= 'f') ||
|
||||
(x >= 'A' && x <= 'F');
|
||||
}
|
||||
|
||||
int decode(const char *s, char *dec)
|
||||
{
|
||||
char *o;
|
||||
const char *end = s + strlen(s);
|
||||
int c;
|
||||
char *o;
|
||||
const char *end = s + strlen(s);
|
||||
int c;
|
||||
|
||||
for (o = dec; s <= end; o++) {
|
||||
c = *s++;
|
||||
if (c == '+') c = ' ';
|
||||
else if (c == '%' && ( !ishex(*s++) ||
|
||||
!ishex(*s++) ||
|
||||
!sscanf(s - 2, "%2x", &c)))
|
||||
return -1;
|
||||
for (o = dec; s <= end; o++) {
|
||||
c = *s++;
|
||||
if (c == '+') c = ' ';
|
||||
else if (c == '%' && ( !ishex(*s++) ||
|
||||
!ishex(*s++) ||
|
||||
!sscanf(s - 2, "%2x", &c)))
|
||||
return -1;
|
||||
|
||||
if (dec) *o = c;
|
||||
}
|
||||
if (dec) *o = c;
|
||||
}
|
||||
|
||||
return o - dec;
|
||||
return o - dec;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const char *url = "http%3A%2F%2ffoo+bar%2fabcd";
|
||||
char out[strlen(url) + 1];
|
||||
const char *url = "http%3A%2F%2ffoo+bar%2fabcd";
|
||||
char out[strlen(url) + 1];
|
||||
|
||||
printf("length: %d\n", decode(url, 0));
|
||||
puts(decode(url, out) < 0 ? "bad string" : out);
|
||||
printf("length: %d\n", decode(url, 0));
|
||||
puts(decode(url, out) < 0 ? "bad string" : out);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue