Unicode module

trailingBytesForUTF8

constantSource

How many continuation bytes follow a first byte, for each byte value. It is 0 for ASCII and for continuation bytes themselves, 1 to 3 for the lead bytes of valid sequences and 4 or 5 for the bytes of the old five and six byte forms (0xF8 and up).

ExampleOpen in playground ↗
assert(trailingBytesForUTF8[#char "a"] == 0);
assert(trailingBytesForUTF8[0xc3] == 1);
assert(trailingBytesForUTF8[0xe2] == 2);
assert(trailingBytesForUTF8[0xf0] == 3);
trailingBytesForUTF8 :: #run trailing_table()

See also