UTF-8 decoding #
This file contains the low-level proof that UTF-8 decoding and encoding are inverses. An important corollary is that attempting to decode a byte array that is valid UTF-8 will succeed.
utf8EncodeChar #
utf8EncodeChar low-level API #
Returns the sequence of bytes in a character's UTF-8 encoding.
Equations
- One or more equations did not get rendered due to their size.
Instances For
utf8EncodeChar BitVec API #
Size one #
Size two #
Size three #
Size four #
parseFirstByte definition #
Equations
- One or more equations did not get rendered due to their size.
Instances For
parseFirstByte low-level API #
parseFirstByte BitVec API #
Size one #
Size two #
Size three #
Size four #
UInt8.isUTF8ContinuationByte definition & API #
Checks whether a byte is a UTF-8 continuation byte, that is, whether it has the form 0b10xxxxxx.
Equations
- b.isUTF8ContinuationByte = (b &&& 192 == 128)
Instances For
parseFirstByte, isUTF8ContinuationByte and utf8EncodeChar #
Instances For
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- ByteArray.utf8DecodeChar?.verify₂ w x = if (!x.isUTF8ContinuationByte) = true then false else have r := ByteArray.utf8DecodeChar?.assemble₂Unchecked w x; decide (128 ≤ r)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Decodes and returns the Char whose UTF-8 encoding begins at i in bytes.
Returns none if i is not the start of a valid UTF-8 encoding of a character.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Decodes a list of bytes as UTF-8, stopping at the first invalid sequence.
This is the model used by String.toList. It is structurally recursive on the list, so the kernel
reduces it in time linear in the number of bytes, unlike ByteArray.utf8Decode?, which indexes into
an array.
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
utf8DecodeChar? low-level API #
Main theorems #
utf8DecodeChar?_utf8EncodeChar_append and toByteArray_utf8EncodeChar_of_utf8DecodeChar?_eq_some are the two main results that together
imply that UTF-8 encoding and decoding are inverse.
Corollaries #
Decodes and returns the Char whose UTF-8 encoding begins at i in bytes.
This function requires a proof that there is, in fact, a valid Char at i. utf8DecodeChar? is
an alternative function that returns Option Char instead of requiring a proof ahead of time.
Equations
- bytes.utf8DecodeChar i h = (bytes.utf8DecodeChar? i).get h
Instances For
Predicate for whether a byte has the bit pattern of a UTF-8 leading byte, that is, one of the forms
0b0xxxxxxx, 0b110xxxxx, 0b1110xxxx or 0b11110xxx. Every first byte of the UTF-8 encoding of a
Unicode scalar value satisfies this, but so do some bytes that never occur in valid UTF-8 (0xC0,
0xC1 and 0xF5 to 0xF7).