| 1031 | } |
| 1032 | |
| 1033 | static int decode_hex4(const char *hex) |
| 1034 | { |
| 1035 | int digit[4]; |
| 1036 | int i; |
| 1037 | |
| 1038 | /* Convert ASCII hex digit to numeric digit |
| 1039 | * Note: this returns an error for invalid hex digits, including |
| 1040 | * NULL */ |
| 1041 | for (i = 0; i < 4; i++) { |
| 1042 | digit[i] = hexdigit2int(hex[i]); |
| 1043 | if (digit[i] < 0) { |
| 1044 | return -1; |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | return (digit[0] << 12) + |
| 1049 | (digit[1] << 8) + |
| 1050 | (digit[2] << 4) + |
| 1051 | digit[3]; |
| 1052 | } |
| 1053 | |
| 1054 | /* Converts a Unicode codepoint to UTF-8. |
| 1055 | * Returns UTF-8 string length, and up to 4 bytes in *utf8 */ |
no test coverage detected