Skip to content
Snippets Groups Projects
Commit 88e3a4f0 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen Committed by Jean-Baptiste Kempf
Browse files

url: Optimize vlc_url_decode

parent 5f677641
No related branches found
No related tags found
1 merge request!664url: Optimize vlc_url_decode
Pipeline #192025 passed with stage
in 19 minutes and 57 seconds
......@@ -51,6 +51,20 @@ char *vlc_uri_decode_duplicate (const char *str)
return buf;
}
static char hex_to_char( char c )
{
unsigned char v = (unsigned char)c - '0';
if ( v < 10 )
return v;
v = (unsigned)c - 'a';
if ( v <= 5 )
return v + 10;
v = (unsigned)c - 'A';
if ( v <= 5 )
return v + 10;
return -1;
}
char *vlc_uri_decode (char *str)
{
char *in = str, *out = str;
......@@ -62,15 +76,15 @@ char *vlc_uri_decode (char *str)
{
if (c == '%')
{
char hex[3];
char a, b;
if (!(hex[0] = *(in++)) || !(hex[1] = *(in++)))
if ((a = hex_to_char(*(in++))) < 0 ||
(b = hex_to_char(*(in++))) < 0)
{
errno = EINVAL;
return NULL;
}
hex[2] = '\0';
*(out++) = strtoul (hex, NULL, 0x10);
*(out++) = a << 4 | b;
}
else
*(out++) = c;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment