Reading share text with characters that are not ASCII #
No share has a character outside ASCII, but text given as a share can. decodeAscii only reads
ASCII bytes. decodeUtf8 reads any other text without a list as long as the text:
- Hex text: every character that is not ASCII is replaced by
~(on the bytes:substBytes), and the result is read bydecodeAscii.~is not a hex digit, not-, not whitespace and not in a tag, sodecodeSharereturns the same for both texts (decodeShare_subst). - Other text is only read if it is short once trimmed; longer text is too long to be a word
share. The trimmed part is cut out of the bytes and checked (
trimmedReader).
decodeUtf8_eq proves that it returns exactly what decodeShare returns.
Replacing characters that are not ASCII #
substChar keeps whitespace, and makes none.
substChar keeps hex digits, and makes none.
Hex-decoding does not see the replacement.
Cutting at - does not see the replacement.
The tag does not see the replacement.
Decoding does not see the replacement: the text with every character that is not ASCII
replaced by ~ decodes to the same record, or fails with the same error.
Trimming does not see the replacement.
looksHex does not see the replacement.
decodeShare does not see the replacement in hex text.
Text that is not hex and too long is not a word share.
The replacement on bytes #
What the replacement does to one byte of UTF-8: an ASCII byte is kept, the first byte of a
longer character becomes ~, and its other bytes go away.
Equations
Instances For
The other bytes of such a character go away.
substByte on the bytes of a character gives the byte of the replaced character.
substByte on the bytes of text gives the bytes of the replaced text.
Loop for substBytes.
Equations
- QedShare.Cli.substLoop bs 0 x✝¹ x✝ = x✝
- QedShare.Cli.substLoop bs n.succ x✝¹ x✝ = QedShare.Cli.substLoop bs n (x✝¹ + 1) (match QedShare.Cli.substByte (bs.get! x✝¹) with | some b => x✝.push b | none => x✝)
Instances For
The bytes of the text with every character that is not ASCII replaced by ~
(substBytes_toUTF8).
Equations
- QedShare.Cli.substBytes bs = QedShare.Cli.substLoop bs bs.size 0 (ByteArray.emptyWithCapacity bs.size)
Instances For
substLoop is List.filterMap on the bytes it reads.
substBytes is List.filterMap on the bytes.
substBytes gives ASCII bytes.
substBytes on the bytes of a text gives the bytes of the replaced text.
Trimming on the bytes #
Whitespace around text does not change what trimWs gives.
A reader only looks at the trimmed text.
Cutting whitespace bytes off both ends of a text does not change what trimWs gives.
The list-based reader on the text without the whitespace around it: the ends found by
skipWs and skipWsEnd are checked, and the text between them is checked to be UTF-8. Reads
what the list-based reader reads on the whole text (trimmedReader_eq).
Equations
- One or more equations did not get rendered due to their size.
Instances For
trimmedReader reads what the list-based reader reads.
The reader #
Read one share from the bytes of any text without a list as long as the text. Returns what
looksHex and decodeShare return (decodeUtf8_eq).
Short text goes to the list-based reader. In longer text, every character that is not ASCII is
replaced by ~ and the result is read by decodeAscii: for hex text that is the answer
(decodeShare_subst). Text that is not hex is too long to be a word share if its trimmed part
has more than maxWordShareChars characters (the replaced text has as many); shorter than
that, the trimmed part goes to the list-based reader (trimmedReader).
Equations
- One or more equations did not get rendered due to their size.
Instances For
decodeUtf8 reads what decodeShare reads. For the bytes of any text, it returns
whether the text is in the hex form (looksHex), and the packed record decodeShare returns,
or the same error.
The reader for text that is not a well-formed hex share: decodeAscii for ASCII text,
decodeUtf8 for the rest.
Equations
- QedShare.Cli.decodeOther label s = match QedShare.Cli.decodeAscii label s.toUTF8 with | some r => r | none => QedShare.Cli.decodeUtf8 label s.toUTF8 ⋯
Instances For
decodeOther reads what decodeShare reads, packed.
Read one share, hex or words, into a packed record, and say whether it is in the hex form.
Every text is read from its bytes; only text that is short once trimmed goes through the lists
of decodeShare. Returns
exactly what looksHex and decodeShare return, the record packed (decodePackedForm_eq).
Equations
Instances For
Read one share, hex or words, into a packed record. Returns exactly what decodeShare
returns, packed (decodePacked_eq).
Equations
- QedShare.Cli.decodePacked label s = (QedShare.Cli.decodePackedForm label s).snd
Instances For
decodePackedForm reads what decodeShare reads, packed. For every label and text, it
returns whether the text is in the hex form (looksHex), and the packed record of the record
decodeShare returns, or the same error.
decodePacked reads what decodeShare reads, packed. For every label and text,
decodePacked returns the packed record of the record decodeShare returns, or the same
error.
decodePackedForm on the UTF-8 bytes of the text: what the executable calls, so that the
text is never copied into a String (decodeBytes_eq). Only short text is made into a string,
for decodeShare.
Equations
- One or more equations did not get rendered due to their size.
Instances For
decodeBytes is decodePackedForm on the text with those bytes, so it returns what
looksHex and decodeShare return for that text.
Whether the text with these bytes is in the hex form: looksHex on the trimmed text, read
from the bytes (looksHexFast_eq). ASCII text is looked at directly (the ends found by skipWs
and skipWsEnd are checked); for any other text the reader says it. Used to decide how a file
is cut into shares.
Equations
- One or more equations did not get rendered due to their size.
Instances For
looksHexFast is looksHex on the trimmed text.