//! The entries of `memory.md` and `user.md`: text separated by a line holding only `§` (M5a spec, //! section 3). A file's size is the characters of its entries joined by separator lines, which //! is what `render` writes, less the final newline. use proto::memory::SEPARATOR; /// The entries of a file's text: split at lines that are only `§` (spaces around it allowed), /// each trimmed, empty ones left out. pub fn parse(text: &str) -> Vec { // Walk `text.lines()`, collecting lines into `current`. A line whose trim() equals SEPARATOR // ends an entry: `push(&mut entries, ¤t)`, then clear `current`. Any other line is pushed // onto `current`. After the last line, `push` once more. Return `entries`. todo!() } fn push(entries: &mut Vec, lines: &[&str]) { // Join `lines` with a newline, trim() the result, and push it (as a String) only when it is not // empty. todo!() } /// The entries joined by `\n§\n`, with a final newline; an empty list is an empty file. pub fn render(entries: &[String]) -> String { // An empty list is "". Otherwise the entries joined by format!("\n{SEPARATOR}\n"), with one // newline added at the end. todo!() } /// A file's size in characters, the one its limit is measured against. pub fn size(entries: &[String]) -> usize { // `render(entries)` without its final newline (`trim_end_matches('\n')`), counted in // characters: chars().count(). todo!() }