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