From 0eeff9148e327183e532752f46421a75506dd7a6 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 29 Jul 2022 18:22:59 +0200 Subject: Refactor to improve states * Remove custom kind wrappers, use plain bytes instead * Remove `Into`s, use the explicit expected types instead * Refactor to use `slice.as_str` in most places * Remove unneeded unique check before adding a definition * Use a shared CDATA prefix in constants * Inline byte checks into matches * Pass bytes back from parser instead of whole parse state * Refactor to work more often on bytes * Rename custom `size` to `len` --- src/construct/partial_bom.rs | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'src/construct/partial_bom.rs') diff --git a/src/construct/partial_bom.rs b/src/construct/partial_bom.rs index be8d6c8..155a1a3 100644 --- a/src/construct/partial_bom.rs +++ b/src/construct/partial_bom.rs @@ -10,13 +10,12 @@ use crate::tokenizer::{State, Tokenizer}; /// ^^^^ /// ``` pub fn start(tokenizer: &mut Tokenizer) -> State { - match tokenizer.current { - Some(0xEF) => { - tokenizer.enter(Token::ByteOrderMark); - tokenizer.consume(); - State::Fn(Box::new(cont)) - } - _ => State::Nok, + if tokenizer.current == Some(0xEF) { + tokenizer.enter(Token::ByteOrderMark); + tokenizer.consume(); + State::Fn(Box::new(cont)) + } else { + State::Nok } } @@ -27,12 +26,11 @@ pub fn start(tokenizer: &mut Tokenizer) -> State { /// ^^^^ /// ``` fn cont(tokenizer: &mut Tokenizer) -> State { - match tokenizer.current { - Some(0xBB) => { - tokenizer.consume(); - State::Fn(Box::new(end)) - } - _ => State::Nok, + if tokenizer.current == Some(0xBB) { + tokenizer.consume(); + State::Fn(Box::new(end)) + } else { + State::Nok } } @@ -43,12 +41,11 @@ fn cont(tokenizer: &mut Tokenizer) -> State { /// ^^^^ /// ``` fn end(tokenizer: &mut Tokenizer) -> State { - match tokenizer.current { - Some(0xBF) => { - tokenizer.consume(); - tokenizer.exit(Token::ByteOrderMark); - State::Ok - } - _ => State::Nok, + if tokenizer.current == Some(0xBF) { + tokenizer.consume(); + tokenizer.exit(Token::ByteOrderMark); + State::Ok + } else { + State::Nok } } -- cgit