1 #ifndef URLQueryString_h
2 #define URLQueryString_h
9 strncpy(fQueryBuffer, query.c_str(),
sizeof(fQueryBuffer)-1);
10 fNumParams = parse(fQueryBuffer,
'&', fParams,
SizeOfArray(fParams));
15 return get(
id, value,
false);
18 bool get(
const char*
id, String& value,
bool expected =
true)
20 for (
int i = 0; i < fNumParams; i++)
22 if (strcmp(
id, fParams[i].key) == 0)
24 value = String(fParams[i].val);
42 char fQueryBuffer[1024];
46 static void unescape(
char* str)
49 while ((e = strchr(str,
'%')) != NULL)
54 if ((ec >=
'0' && ec <=
'9')) {
56 }
else if (ec >=
'a' && ec <=
'f') {
57 ch = ec -
'a' + 10; i++;
58 }
else if (ec >=
'A' && ec <=
'F') {
59 ch = ec -
'a' + 10; i++;
62 if ((ec >=
'0' && ec <=
'9')) {
63 ch = (ch << 4) | (ec -
'0'); i++;
64 }
else if (ec >=
'a' && ec <=
'f') {
65 ch = (ch << 4) | (ec -
'a' + 10); i++;
67 else if (ec >=
'A' && ec <=
'F') {
68 ch = (ch << 4) | (ec -
'A' + 10); i++;
73 memmove(&e[1], &e[3], strlen(&e[3])+1);
76 while ((e = strchr(str,
'+')) != NULL)
82 static int parse(
char *query,
char delimiter, Param* params,
int max_params)
86 if (NULL == query ||
'\0' == *query) {
90 params[i++].key = query;
91 while (i < max_params && NULL != (query = strchr(query, delimiter)))
94 params[i].key = ++query;
100 if ((params[i - 1].val = strchr(params[i - 1].key,
'=')) != NULL)
102 *(params[i - 1].val)++ =
'\0';
103 unescape(params[i - 1].val);
110 if ((params[i - 1].val = strchr(params[i - 1].key,
'=')) != NULL)
112 *(params[i - 1].val)++ =
'\0';
113 unescape(params[i - 1].val);