Edit: The name "4" was a bad idea, because it is an numer. I changed it to "D". The number "4" causes a conflict when prefilling the textarea with text.
After reading that, it was not hard.
I wrote a function to decode it. After the function I also write a "\r\n" to the file.
void URLdecode (char *pText)
{
// The text is converted in the same string.
// So no extra memory is needed.
uint8_t hex;
char *pRead = pText;
char *pWrite = pText;
while (*pRead != '\0')
{
if (*pRead == '+')
{
// A '+' character is a space.
*pWrite++ = ' ';
pRead++;
}
else if (*pRead == '%')
{
// Read two hexadecimal digits
// Assume the hexadecimal notation is in capitals.
// No testing is done for illegal characters.
// If the buffer was full, the line could be truncated,
// so testing is done for the end of line.
pRead++;
if (*pRead < 'A')
hex = (*pRead - '0') * 16;
else
hex = (*pRead - 'A' + 10) * 16;
if (*pRead != '\0')
pRead++;
if (*pRead < 'A')
hex += (*pRead - '0');
else
hex += (*pRead - 'A' + 10);
*pWrite++ = hex;
if (*pRead != '\0')
pRead++;
}
else
{
*pWrite++ = *pRead++;
}
}
*pWrite = '\0';
}