MCPcopy Create free account
hub / github.com/Tencent/Hardcoder / parse_hex4

Function parse_hex4

libapp2sys/src/main/cpp/cjson/cJSON.c:542–575  ·  view source on GitHub ↗

parse 4 digit hexadecimal number */

Source from the content-addressed store, hash-verified

540
541/* parse 4 digit hexadecimal number */
542static unsigned parse_hex4(const unsigned char * const input)
543{
544 unsigned int h = 0;
545 size_t i = 0;
546
547 for (i = 0; i < 4; i++)
548 {
549 /* parse digit */
550 if ((input[i] >= '0') && (input[i] <= '9'))
551 {
552 h += (unsigned int) input[i] - '0';
553 }
554 else if ((input[i] >= 'A') && (input[i] <= 'F'))
555 {
556 h += (unsigned int) 10 + input[i] - 'A';
557 }
558 else if ((input[i] >= 'a') && (input[i] <= 'f'))
559 {
560 h += (unsigned int) 10 + input[i] - 'a';
561 }
562 else /* invalid */
563 {
564 return 0;
565 }
566
567 if (i < 3)
568 {
569 /* shift left to make place for the next nibble */
570 h = h << 4;
571 }
572 }
573
574 return h;
575}
576
577/* converts a UTF-16 literal to UTF-8
578 * 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