From f7e5fb852dc9c416b9eeb1f0d4f2d51ba5b68456 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 28 Jul 2022 16:48:00 +0200 Subject: Refactor to work on `char`s MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, a custom char implementation was used. This was easier to work with, as sometimes “virtual” characters are injected, or characters are ignored. This replaces that with working on actual `char`s. In the hope of in the future working on `u8`s, even. This simplifies the state machine somewhat, as only `\n` is fed, regardless of whether it was a CRLF, CR, or LF. It also feeds `' '` instead of virtual spaces. The BOM, if present, is now available as a `ByteOrderMark` event. --- src/lib.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 4dc15e6..c1b0fa0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,6 @@ mod util; use crate::compiler::compile; use crate::parser::parse; -use crate::tokenizer::Code; /// Type of line endings in markdown. #[derive(Debug, Default, Clone, PartialEq)] @@ -61,16 +60,16 @@ impl LineEnding { LineEnding::LineFeed => "\n", } } - /// Turn a [Code] into a line ending. + /// Turn a string into a line ending. /// /// ## Panics /// /// Panics if `code` is not `\r\n`, `\r`, or `\n`. - fn from_code(code: Code) -> LineEnding { - match code { - Code::CarriageReturnLineFeed => LineEnding::CarriageReturnLineFeed, - Code::Char('\r') => LineEnding::CarriageReturn, - Code::Char('\n') => LineEnding::LineFeed, + fn from_str(str: &str) -> LineEnding { + match str { + "\r\n" => LineEnding::CarriageReturnLineFeed, + "\r" => LineEnding::CarriageReturn, + "\n" => LineEnding::LineFeed, _ => unreachable!("invalid code"), } } @@ -425,5 +424,5 @@ pub fn micromark(value: &str) -> String { #[must_use] pub fn micromark_with_options(value: &str, options: &Options) -> String { let (events, result) = parse(value, options); - compile(&events, &result.codes, options) + compile(&events, &result.chars, options) } -- cgit