* Build a wide character from the input buffer; the number of * bits we pull off the first character is dependent on the length, * but we put 6 bits off all other bytes. */
| 1099 | * but we put 6 bits off all other bytes. |
| 1100 | */ |
| 1101 | static inline wchar_t |
| 1102 | xo_utf8_char (const char *buf, ssize_t len) |
| 1103 | { |
| 1104 | /* Most common case: singleton byte */ |
| 1105 | if (len == 1) |
| 1106 | return (unsigned char) buf[0]; |
| 1107 | |
| 1108 | ssize_t i; |
| 1109 | wchar_t wc; |
| 1110 | const unsigned char *cp = (const unsigned char *) buf; |
| 1111 | |
| 1112 | wc = *cp & xo_utf8_data_bits[len]; |
| 1113 | for (i = 1; i < len; i++) { |
| 1114 | wc <<= 6; /* Low six bits have data */ |
| 1115 | wc |= cp[i] & 0x3f; |
| 1116 | if ((cp[i] & 0xc0) != 0x80) |
| 1117 | return (wchar_t) -1; |
| 1118 | } |
| 1119 | |
| 1120 | return wc; |
| 1121 | } |
| 1122 | |
| 1123 | /* |
| 1124 | * Determine the number of bytes needed to encode a wide character. |
no outgoing calls
no test coverage detected