Changeset 13858


Ignore:
Timestamp:
Jan 24, 2013, 12:53:37 AM (8 years ago)
Author:
jordan
Message:

(libT) unroll decode_hex_string()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/variant-json.c

    r13687 r13858  
    153153decode_hex_string (const char * in, unsigned int * setme)
    154154{
    155   bool success;
    156   char buf[5];
    157   char * end;
     155  unsigned int val = 0;
     156  const char * const end = in + 6;
    158157
    159158  assert (in != NULL);
    160159  assert (in[0] == '\\');
    161160  assert (in[1] == 'u');
    162 
    163   memcpy (buf, in+2, 4);
    164   buf[4] = '\0';
    165   *setme = strtoul (buf, &end, 16);
    166   success = end == buf+4;
    167 
    168   return success;
     161  in += 2;
     162
     163  do
     164    {
     165      val <<= 4;
     166      if (('0'<=*in) && (*in<='9'))
     167        val += (*in-'0');
     168      else if (('a'<=*in) && (*in<='f'))
     169        val += (*in-'a') + 10u;
     170      else if (('A'<=*in) && (*in<='F'))
     171        val += (*in-'A') + 10u;
     172      else
     173        return false;
     174    }
     175  while (++in != end);
     176
     177  *setme = val;
     178  return true;
    169179}
    170180
Note: See TracChangeset for help on using the changeset viewer.