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

Function xo_utf8_char

tools/libxo/libxo/libxo.c:1101–1121  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

1099 * but we put 6 bits off all other bytes.
1100 */
1101static inline wchar_t
1102xo_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.

Callers 3

xo_format_string_directFunction · 0.85
xo_count_utf8_colsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected