static char *decode_string(char *s) { char *save_s; char *p = s; save_s = s; for (; *s; s++, p++) { if (*s != '%') *p = *s; else { /* Do nothing if at the end of the string. Or if the chars are not hex-digits. */ if (!*(s + 1) || !*(s + 2) || !(isxdigit(*(s + 1)) && isxdigit(*(s + 2)))) { *p = *s; continue; } *p = (char)((ASC2HEXD(*(s + 1)) << 4) + ASC2HEXD(*(s + 2))); s += 2; } } *p = '\0'; return save_s; }
void decode_string (char* s) { char *p = s; for (; *s; s++, p++) { if (*s != '%') *p = *s; else { /* Do nothing if at the end of the string, or if the chars are not hex-digits. */ if (!*(s + 1) || !*(s + 2) || !(ISXDIGIT (*(s + 1)) && ISXDIGIT (*(s + 2)))) { *p = *s; continue; } *p = (ASC2HEXD (*(s + 1)) << 4) + ASC2HEXD (*(s + 2)); s += 2; } } *p = '\0'; }