Created
December 14, 2013 20:08
-
-
Save jmsaavedra/7964251 to your computer and use it in GitHub Desktop.
URL encoded string to character string (for arduino here)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char *in = "!%40%23%24%25%5e%26*()_%2b"; | |
char *out = "000000000000000000000000000000"; | |
void setup(){ | |
Serial.begin(9600); | |
while(!Serial){ | |
; | |
} | |
Serial.println(in); | |
urldecode2(out,in); | |
Serial.println(out); | |
} | |
void loop(){ | |
} | |
void urldecode2(char *dst, const char *src) | |
{ | |
char a, b; | |
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 { | |
*dst++ = *src++; | |
} | |
} | |
*dst++ = '\0'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment