From 8ffed1822bcbc1b6ce6647b840fb03996b0635ea Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 2 Aug 2022 14:27:31 +0200 Subject: Refactor to remove most closures --- src/construct/heading_atx.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/construct/heading_atx.rs') diff --git a/src/construct/heading_atx.rs b/src/construct/heading_atx.rs index d432b6c..6751567 100644 --- a/src/construct/heading_atx.rs +++ b/src/construct/heading_atx.rs @@ -93,7 +93,7 @@ pub fn start(tokenizer: &mut Tokenizer) -> State { fn before(tokenizer: &mut Tokenizer) -> State { if Some(b'#') == tokenizer.current { tokenizer.enter(Token::HeadingAtxSequence); - sequence_open(tokenizer, 0) + sequence_open(tokenizer) } else { State::Nok } @@ -105,23 +105,27 @@ fn before(tokenizer: &mut Tokenizer) -> State { /// > | ## aa /// ^ /// ``` -fn sequence_open(tokenizer: &mut Tokenizer, size: usize) -> State { +fn sequence_open(tokenizer: &mut Tokenizer) -> State { match tokenizer.current { - None | Some(b'\n') if size > 0 => { + None | Some(b'\n') if tokenizer.tokenize_state.size > 0 => { + tokenizer.tokenize_state.size = 0; tokenizer.exit(Token::HeadingAtxSequence); at_break(tokenizer) } - Some(b'#') if size < HEADING_ATX_OPENING_FENCE_SIZE_MAX => { + Some(b'#') if tokenizer.tokenize_state.size < HEADING_ATX_OPENING_FENCE_SIZE_MAX => { + tokenizer.tokenize_state.size += 1; tokenizer.consume(); - State::Fn(Box::new(move |tokenizer| { - sequence_open(tokenizer, size + 1) - })) + State::Fn(Box::new(sequence_open)) } - _ if size > 0 => { + _ if tokenizer.tokenize_state.size > 0 => { + tokenizer.tokenize_state.size = 0; tokenizer.exit(Token::HeadingAtxSequence); tokenizer.go(space_or_tab(), at_break)(tokenizer) } - _ => State::Nok, + _ => { + tokenizer.tokenize_state.size = 0; + State::Nok + } } } -- cgit