* Emit one wide character into the given buffer */
| 1146 | * Emit one wide character into the given buffer |
| 1147 | */ |
| 1148 | static void |
| 1149 | xo_utf8_emit_char (char *buf, ssize_t len, wchar_t wc) |
| 1150 | { |
| 1151 | ssize_t i; |
| 1152 | |
| 1153 | if (len == 1) { /* Simple case */ |
| 1154 | buf[0] = wc & 0x7f; |
| 1155 | return; |
| 1156 | } |
| 1157 | |
| 1158 | /* Start with the low bits and insert them, six bits at a time */ |
| 1159 | for (i = len - 1; i >= 0; i--) { |
| 1160 | buf[i] = 0x80 | (wc & 0x3f); |
| 1161 | wc >>= 6; /* Drop the low six bits */ |
| 1162 | } |
| 1163 | |
| 1164 | /* Finish off the first byte with the length bits */ |
| 1165 | buf[0] &= xo_utf8_data_bits[len]; /* Clear out the length bits */ |
| 1166 | buf[0] |= xo_utf8_len_bits[len]; /* Drop in new length bits */ |
| 1167 | } |
| 1168 | |
| 1169 | /* |
| 1170 | * Append a single UTF-8 character to a buffer, converting it to locale |
no outgoing calls
no test coverage detected