parse 4 digit hexadecimal number */
| 540 | |
| 541 | /* parse 4 digit hexadecimal number */ |
| 542 | static 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 */ |
no outgoing calls
no test coverage detected