MCPcopy Create free account
hub / github.com/DaveGamble/cJSON / parse_hex4

Function parse_hex4

cJSON.c:661–694  ·  view source on GitHub ↗

parse 4 digit hexadecimal number */

Source from the content-addressed store, hash-verified

659
660/* parse 4 digit hexadecimal number */
661static unsigned parse_hex4(const unsigned char * const input)
662{
663 unsigned int h = 0;
664 size_t i = 0;
665
666 for (i = 0; i < 4; i++)
667 {
668 /* parse digit */
669 if ((input[i] >= '0') && (input[i] <= '9'))
670 {
671 h += (unsigned int) input[i] - '0';
672 }
673 else if ((input[i] >= 'A') && (input[i] <= 'F'))
674 {
675 h += (unsigned int) 10 + input[i] - 'A';
676 }
677 else if ((input[i] >= 'a') && (input[i] <= 'f'))
678 {
679 h += (unsigned int) 10 + input[i] - 'a';
680 }
681 else /* invalid */
682 {
683 return 0;
684 }
685
686 if (i < 3)
687 {
688 /* shift left to make place for the next nibble */
689 h = h << 4;
690 }
691 }
692
693 return h;
694}
695
696/* converts a UTF-16 literal to UTF-8
697 * A literal can be one or two sequences of the form \uXXXX */

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…