benilla-re systems structs docs

s_utf8TrailingBytes

global · storm

Address
0x80e780 · 256 bytes, up to 0x80e87f
Type
const uint8_t[256]
Meaning
Holds the bytes that follow each UTF-8 lead byte: 0 to 0xbf none, then 1 to 5
Confidence
verified, proof one
Finding
storm/unicode#converting-utf-8-to-utf-16

Finding: Converting UTF-8 to UTF-16 in storm: UTF-8 to UTF-16

SUniConvertUTF8to16(dst, cap, src, len, &written, &read) folds a sequence of n + 1 bytes as v = (v << 6) + byte modulo 2^32, less the nth dword of 0x80e764. A v up to 0xffff is one unit, surrogates and overlong forms too, and 0 ends the run with result 0; above 0x10ffff it is 0xfffd; between, the pair 0xd800 + ((v − 0x10000) >> 10), 0xdc00 + (v & 0x3ff). What does not fit in cap returns 1 unstored; a source that runs out returns −1, a sequence past its end −(n + 1). written counts units with the NUL, read bytes without its sequence; a null source or a len of 0 returns −1 and sets neither.

The derivation is in the doc.