(libT) unroll decode_hex_string()

This commit is contained in:
Jordan Lee 2013-01-24 00:53:37 +00:00
parent 06d9f20759
commit 644c647799
1 changed files with 18 additions and 8 deletions

View File

@ -152,20 +152,30 @@ action_callback_PUSH (jsonsl_t jsn,
static bool
decode_hex_string (const char * in, unsigned int * setme)
{
bool success;
char buf[5];
char * end;
unsigned int val = 0;
const char * const end = in + 6;
assert (in != NULL);
assert (in[0] == '\\');
assert (in[1] == 'u');
in += 2;
memcpy (buf, in+2, 4);
buf[4] = '\0';
*setme = strtoul (buf, &end, 16);
success = end == buf+4;
do
{
val <<= 4;
if (('0'<=*in) && (*in<='9'))
val += (*in-'0');
else if (('a'<=*in) && (*in<='f'))
val += (*in-'a') + 10u;
else if (('A'<=*in) && (*in<='F'))
val += (*in-'A') + 10u;
else
return false;
}
while (++in != end);
return success;
*setme = val;
return true;
}
static char*