pub fn read_rtf(text: &str) -> Result<FlightLog, LogError>Expand description
Reads an Eggtimer TRS’s terminal download saved inside an RTF document, as a text editor saves
what a terminal program captured: the document’s plain text, unwrapped from its markup, read
as read_text reads a terminal download (ADR-258 §4).
The text is unwrapped by the subset of the RTF specification (Microsoft, Rich Text Format (RTF) Specification, version 1.9.1, 2008) that a saved terminal capture needs:
- groups,
{to}, nested at mostMAX_RTF_DEPTHdeep; the document is one group, and an unbalanced brace is refused; - control words,
\and letters, then an optional signed number and one space ending the word, which isn’t text; a number of any length is read saturating, never overflowing; \par,\line,\sect,\pageand\rowas line breaks, and\at a line’s end as\par;\taband\cellas a tab;\emdash,\endash,\bullet, the space words and the quote words as their characters;- control symbols:
\\,\{and\}as the character;\~a no-break space,\_a hyphen,\-nothing;\'hha byte in the document’s code page, Windows 1252 (\ansi, the default, or\ansicpg1252), any other code page’s bytes from 0x80 counted and read as U+FFFD; \uNa Unicode character, the\ucNfallback characters after it skipped;- destinations skipped whole: a group opening
\*, and the font, color and style tables, the document’s information, pictures and objects;\binN’s N bytes skipped; - raw line ends, other control words and other control symbols ignored, as the specification says a reader may.
The work is one pass with a stack of groups, no recursion, and the text is never longer than the document.
A document may hold several downloads one after another, each with its title, settings, summary and table. A record holds one flight: the first download is read, its table ending at its last row before the next download’s lead-in, and the others are counted in a note with the lines of their titles. An error names the RTF document’s line.
§Errors
LogError::NotThisFormat if the file isn’t an RTF document, or if its text holds no Eggtimer
download: no title Eggtimer … Flight Settings before an Eggtimer header row within the first
MAX_PREAMBLE_LINES lines that aren’t blank; LogError::Syntax for RTF markup the reader
refuses (unbalanced braces, groups nested deeper than MAX_RTF_DEPTH, a \' escape without
two hexadecimal digits); otherwise what read_text refuses, naming the document’s line.