| 778 | } |
| 779 | |
| 780 | static int decode_hex4(const char *hex) |
| 781 | { |
| 782 | int digit[4]; |
| 783 | int i; |
| 784 | |
| 785 | /* Convert ASCII hex digit to numeric digit |
| 786 | * Note: this returns an error for invalid hex digits, including |
| 787 | * NULL */ |
| 788 | for (i = 0; i < 4; i++) { |
| 789 | digit[i] = hexdigit2int(hex[i]); |
| 790 | if (digit[i] < 0) { |
| 791 | return -1; |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | return (digit[0] << 12) + |
| 796 | (digit[1] << 8) + |
| 797 | (digit[2] << 4) + |
| 798 | digit[3]; |
| 799 | } |
| 800 | |
| 801 | /* Converts a Unicode codepoint to UTF-8. |
| 802 | * Returns UTF-8 string length, and up to 4 bytes in *utf8 */ |
no test coverage detected