diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-07-05 13:03:09 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-07-05 13:03:09 +0200 |
commit | fd860a975b84da9a79abfa247787e6adbd5ea34c (patch) | |
tree | bd9db168c57478f4f37c234eac4087c2d69a6445 /src/tokenizer.rs | |
parent | 0bc099f8f8b6541a962e604b7ac25445a2a9252a (diff) | |
download | markdown-rs-fd860a975b84da9a79abfa247787e6adbd5ea34c.tar.gz markdown-rs-fd860a975b84da9a79abfa247787e6adbd5ea34c.tar.bz2 markdown-rs-fd860a975b84da9a79abfa247787e6adbd5ea34c.zip |
Refactor code style
Diffstat (limited to '')
-rw-r--r-- | src/tokenizer.rs | 78 |
1 files changed, 0 insertions, 78 deletions
diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 1fa94d7..f0f9ff0 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -11,7 +11,6 @@ //! [`attempt`]: Tokenizer::attempt //! [`check`]: Tokenizer::check -use crate::constant::TAB_SIZE; use crate::parser::ParseState; use std::collections::HashMap; @@ -2224,83 +2223,6 @@ fn feed_impl( check_statefn_result((state, None)) } -/// Turn a string into codes. -pub fn as_codes(value: &str) -> Vec<Code> { - let mut codes: Vec<Code> = vec![]; - let mut at_start = true; - let mut at_carriage_return = false; - let mut column = 1; - - for char in value.chars() { - if at_start { - if char == '\u{feff}' { - // Ignore. - continue; - } - - at_start = false; - } - - // Send a CRLF. - if at_carriage_return && '\n' == char { - at_carriage_return = false; - codes.push(Code::CarriageReturnLineFeed); - } else { - // Send the previous CR: we’re not at a next `\n`. - if at_carriage_return { - at_carriage_return = false; - codes.push(Code::Char('\r')); - } - - match char { - // Send a replacement character. - '\0' => { - column += 1; - codes.push(Code::Char('�')); - } - // Send a tab and virtual spaces. - '\t' => { - let remainder = column % TAB_SIZE; - let mut virtual_spaces = if remainder == 0 { - 0 - } else { - TAB_SIZE - remainder - }; - codes.push(Code::Char(char)); - column += 1; - while virtual_spaces > 0 { - codes.push(Code::VirtualSpace); - column += 1; - virtual_spaces -= 1; - } - } - // Send an LF. - '\n' => { - column = 1; - codes.push(Code::Char(char)); - } - // Don’t send anything yet. - '\r' => { - column = 1; - at_carriage_return = true; - } - // Send the char. - _ => { - column += 1; - codes.push(Code::Char(char)); - } - } - }; - } - - // Send the last CR: we’re not at a next `\n`. - if at_carriage_return { - codes.push(Code::Char('\r')); - } - - codes -} - /// Check a [`StateFnResult`][], make sure its valid (that there are no bugs), /// and clean a final eof passed back in `remainder`. fn check_statefn_result(result: StateFnResult) -> StateFnResult { |