Browse Source

reformatting: parse_hex4

pull/29/head
Max Bruckner 8 years ago
parent
commit
e10f2bf08d
  1. 91
      cJSON.c

91
cJSON.c

@ -344,17 +344,90 @@ static char *print_number(cJSON *item, printbuffer *p)
return str; return str;
} }
/* parse 4 digit hexadecimal number */
static unsigned parse_hex4(const char *str) static unsigned parse_hex4(const char *str)
{ {
unsigned h=0; unsigned h = 0;
if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0; /* first digit */
h=h<<4;str++; if ((*str >= '0') && (*str <= '9'))
if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0; {
h=h<<4;str++; h += (*str) - '0';
if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0; }
h=h<<4;str++; else if ((*str >= 'A') && (*str <= 'F'))
if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0; {
return h; h += 10 + (*str) - 'A';
}
else if ((*str >= 'a') && (*str <= 'f'))
{
h += 10 + (*str) - 'a';
}
else /* invalid */
{
return 0;
}
/* second digit */
h = h << 4;
str++;
if ((*str >= '0') && (*str <= '9'))
{
h += (*str) - '0';
}
else if ((*str >= 'A') && (*str <= 'F'))
{
h += 10 + (*str) - 'A';
}
else if ((*str >= 'a') && (*str <= 'f'))
{
h += 10 + (*str) - 'a';
}
else /* invalid */
{
return 0;
}
/* third digit */
h = h << 4;
str++;
if ((*str >= '0') && (*str <= '9'))
{
h += (*str) - '0';
}
else if ((*str >= 'A') && (*str <= 'F'))
{
h += 10 + (*str) - 'A';
}
else if ((*str >= 'a') && (*str <= 'f'))
{
h += 10 + (*str) - 'a';
}
else /* invalid */
{
return 0;
}
/* fourth digit */
h = h << 4;
str++;
if ((*str >= '0') && (*str <= '9'))
{
h += (*str) - '0';
}
else if ((*str >= 'A') && (*str <= 'F'))
{
h += 10 + (*str) - 'A';
}
else if ((*str >= 'a') && (*str <= 'f'))
{
h += 10 + (*str) - 'a';
}
else /* invalid */
{
return 0;
}
return h;
} }
/* Parse the input text into an unescaped cstring, and populate item. */ /* Parse the input text into an unescaped cstring, and populate item. */

Loading…
Cancel
Save