LOCAL INSTANCE Naturals
NotNegNat == {i \in Nat: i >= 0} \* array index
\* BIT
BIT == {0, 1}
\* ASCII == 1 byte UTF-8 == 0XXX_XXXX
UTF8_1B == [0 -> 0] \cup [1 .. 7 -> BIT]
ASCII == UTF8_1B
\* bytes 2, 3, 4 for 2,3,4 byte UTF8 == 10XX_XXXX
UTF8_B234 == {[0 -> 1], [1 -> 0], [2 .. 7 -> BIT]}
\* 2 byte UTF8 == 110X_XXXX, 10XX_XXXX
UTF8_2B ==
[1 -> {[0 -> 1], [1 -> 1], [2 -> 0], [3 .. 7 -> BIT]}]
\cup
[2 -> UTF8_B234]
\* 3 byte UTF8 == 1110_XXXX, 10XX_XXXX, 10XX_XXXX
UTF8_3B ==
[1 -> {[0 -> 1], [1 -> 1], [2 -> 1], [3 -> 0], [4 .. 7 -> BIT]}]
\cup
[2 .. 3 -> UTF8_B234]
\* 4 byte UTF8 == 1111_0XXX, 10XX_XXXX, 10XX_XXXX, 10XX_XXXX
UTF8_4B ==
[1 -> {[0 -> 1], [1 -> 1], [2 -> 1], [3 -> 1], [4 -> 0], [5 .. 7 -> BIT]}]
\cup
[2 .. 4 -> UTF8_B234]
UTF8_CHAR == UTF8_1B \/ UTF8_2B \/ UTF8_3B \/ UTF8_4B
\* Sequence of UTF8 Characters
UTF8_SEQ == [NotNegNat -> UTF8_CHAR]