MCPcopy Create free account
hub / github.com/F-Stack/f-stack / xo_utf8_emit_char

Function xo_utf8_emit_char

tools/libxo/libxo/libxo.c:1148–1167  ·  view source on GitHub ↗

* Emit one wide character into the given buffer */

Source from the content-addressed store, hash-verified

1146 * Emit one wide character into the given buffer
1147 */
1148static void
1149xo_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

Callers 1

xo_format_string_directFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected