Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * decode a percent-encoded C string with optional path normalization
- *
- * The buffer pointed to by @dst must be at least strlen(@src) bytes.
- * Decoding stops at the first character from @src that decodes to null.
- *
- * @param dst destination buffer
- * @param src source buffer
- * @return number of valid characters in @dst
- * @author Johan Lindh <johan@linkdata.se>
- * @legalese BSD licensed (http://opensource.org/licenses/BSD-2-Clause)
- */
- ptrdiff_t urldecode(char* dst, const char* src)
- {
- char* org_dst = dst;
- char ch, a, b;
- do {
- ch = *src++;
- if (ch == '%' && isxdigit(a = src[0]) && isxdigit(b = src[1])) {
- if (a < 'A') a -= '0';
- else if(a < 'a') a -= 'A' - 10;
- else a -= 'a' - 10;
- if (b < 'A') b -= '0';
- else if(b < 'a') b -= 'A' - 10;
- else b -= 'a' - 10;
- ch = 16 * a + b;
- src += 2;
- }
- *dst++ = ch;
- } while(ch);
- return (dst - org_dst) - 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement