MCPcopy Index your code
hub / github.com/antirez/botlib / parse_hex4

Function parse_hex4

cJSON.c:611–644  ·  view source on GitHub ↗

parse 4 digit hexadecimal number */

Source from the content-addressed store, hash-verified

609
610/* parse 4 digit hexadecimal number */
611static unsigned parse_hex4(const unsigned char * const input)
612{
613 unsigned int h = 0;
614 size_t i = 0;
615
616 for (i = 0; i < 4; i++)
617 {
618 /* parse digit */
619 if ((input[i] >= '0') && (input[i] <= '9'))
620 {
621 h += (unsigned int) input[i] - '0';
622 }
623 else if ((input[i] >= 'A') && (input[i] <= 'F'))
624 {
625 h += (unsigned int) 10 + input[i] - 'A';
626 }
627 else if ((input[i] >= 'a') && (input[i] <= 'f'))
628 {
629 h += (unsigned int) 10 + input[i] - 'a';
630 }
631 else /* invalid */
632 {
633 return 0;
634 }
635
636 if (i < 3)
637 {
638 /* shift left to make place for the next nibble */
639 h = h << 4;
640 }
641 }
642
643 return h;
644}
645
646/* converts a UTF-16 literal to UTF-8
647 * A literal can be one or two sequences of the form \uXXXX */

Callers 1

utf16_literal_to_utf8Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected