parse 4 digit hexadecimal number */
| 609 | |
| 610 | /* parse 4 digit hexadecimal number */ |
| 611 | static 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 */ |
no outgoing calls
no test coverage detected