| 750 | } |
| 751 | |
| 752 | static int decode_hex4(const char *hex) |
| 753 | { |
| 754 | int digit[4]; |
| 755 | int i; |
| 756 | |
| 757 | /* Convert ASCII hex digit to numeric digit |
| 758 | * Note: this returns an error for invalid hex digits, including |
| 759 | * NULL */ |
| 760 | for (i = 0; i < 4; i++) { |
| 761 | digit[i] = hexdigit2int(hex[i]); |
| 762 | if (digit[i] < 0) { |
| 763 | return -1; |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | return (digit[0] << 12) + |
| 768 | (digit[1] << 8) + |
| 769 | (digit[2] << 4) + |
| 770 | digit[3]; |
| 771 | } |
| 772 | |
| 773 | /* Converts a Unicode codepoint to UTF-8. |
| 774 | * Returns UTF-8 string length, and up to 4 bytes in *utf8 */ |
no test coverage detected