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