diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-08-12 17:02:01 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-08-12 17:02:01 +0200 |
commit | 6ba11bdaca1721fb4591819604c340d147798f45 (patch) | |
tree | ef602b518043c0a7228e76d9d00bee95a17798d4 /src/construct/html_flow.rs | |
parent | 504729a4a0c8f3e0d8fc9159e0273150b169e184 (diff) | |
download | markdown-rs-6ba11bdaca1721fb4591819604c340d147798f45.tar.gz markdown-rs-6ba11bdaca1721fb4591819604c340d147798f45.tar.bz2 markdown-rs-6ba11bdaca1721fb4591819604c340d147798f45.zip |
Remove `match` statements if clumsy
Diffstat (limited to 'src/construct/html_flow.rs')
-rw-r--r-- | src/construct/html_flow.rs | 116 |
1 files changed, 50 insertions, 66 deletions
diff --git a/src/construct/html_flow.rs b/src/construct/html_flow.rs index 2da4f47..2d685b6 100644 --- a/src/construct/html_flow.rs +++ b/src/construct/html_flow.rs @@ -525,21 +525,17 @@ pub fn complete_attribute_value_before(tokenizer: &mut Tokenizer) -> State { /// ^ /// ``` pub fn complete_attribute_value_quoted(tokenizer: &mut Tokenizer) -> State { - match tokenizer.current { - None | Some(b'\n') => { - tokenizer.tokenize_state.marker = 0; - tokenizer.tokenize_state.marker_b = 0; - State::Nok - } - Some(b'"' | b'\'') if tokenizer.current.unwrap() == tokenizer.tokenize_state.marker_b => { - tokenizer.tokenize_state.marker_b = 0; - tokenizer.consume(); - State::Next(StateName::HtmlFlowCompleteAttributeValueQuotedAfter) - } - _ => { - tokenizer.consume(); - State::Next(StateName::HtmlFlowCompleteAttributeValueQuoted) - } + if tokenizer.current == Some(tokenizer.tokenize_state.marker_b) { + tokenizer.tokenize_state.marker_b = 0; + tokenizer.consume(); + State::Next(StateName::HtmlFlowCompleteAttributeValueQuotedAfter) + } else if matches!(tokenizer.current, None | Some(b'\n')) { + tokenizer.tokenize_state.marker = 0; + tokenizer.tokenize_state.marker_b = 0; + State::Nok + } else { + tokenizer.consume(); + State::Next(StateName::HtmlFlowCompleteAttributeValueQuoted) } } @@ -624,47 +620,37 @@ pub fn complete_after(tokenizer: &mut Tokenizer) -> State { /// ^ /// ``` pub fn continuation(tokenizer: &mut Tokenizer) -> State { - match tokenizer.current { - Some(b'\n') - if tokenizer.tokenize_state.marker == BASIC - || tokenizer.tokenize_state.marker == COMPLETE => - { - tokenizer.exit(Name::HtmlFlowData); - tokenizer.check( - State::Next(StateName::HtmlFlowContinuationAfter), - State::Next(StateName::HtmlFlowContinuationStart), - ); - State::Retry(StateName::HtmlFlowBlankLineBefore) - } - // Note: important that this is after the basic/complete case. - None | Some(b'\n') => { - tokenizer.exit(Name::HtmlFlowData); - State::Retry(StateName::HtmlFlowContinuationStart) - } - Some(b'-') if tokenizer.tokenize_state.marker == COMMENT => { - tokenizer.consume(); - State::Next(StateName::HtmlFlowContinuationCommentInside) - } - Some(b'<') if tokenizer.tokenize_state.marker == RAW => { - tokenizer.consume(); - State::Next(StateName::HtmlFlowContinuationRawTagOpen) - } - Some(b'>') if tokenizer.tokenize_state.marker == DECLARATION => { - tokenizer.consume(); - State::Next(StateName::HtmlFlowContinuationClose) - } - Some(b'?') if tokenizer.tokenize_state.marker == INSTRUCTION => { - tokenizer.consume(); - State::Next(StateName::HtmlFlowContinuationDeclarationInside) - } - Some(b']') if tokenizer.tokenize_state.marker == CDATA => { - tokenizer.consume(); - State::Next(StateName::HtmlFlowContinuationCdataInside) - } - _ => { - tokenizer.consume(); - State::Next(StateName::HtmlFlowContinuation) - } + if tokenizer.tokenize_state.marker == COMMENT && tokenizer.current == Some(b'-') { + tokenizer.consume(); + State::Next(StateName::HtmlFlowContinuationCommentInside) + } else if tokenizer.tokenize_state.marker == RAW && tokenizer.current == Some(b'<') { + tokenizer.consume(); + State::Next(StateName::HtmlFlowContinuationRawTagOpen) + } else if tokenizer.tokenize_state.marker == DECLARATION && tokenizer.current == Some(b'>') { + tokenizer.consume(); + State::Next(StateName::HtmlFlowContinuationClose) + } else if tokenizer.tokenize_state.marker == INSTRUCTION && tokenizer.current == Some(b'?') { + tokenizer.consume(); + State::Next(StateName::HtmlFlowContinuationDeclarationInside) + } else if tokenizer.tokenize_state.marker == CDATA && tokenizer.current == Some(b']') { + tokenizer.consume(); + State::Next(StateName::HtmlFlowContinuationCdataInside) + } else if (tokenizer.tokenize_state.marker == BASIC + || tokenizer.tokenize_state.marker == COMPLETE) + && tokenizer.current == Some(b'\n') + { + tokenizer.exit(Name::HtmlFlowData); + tokenizer.check( + State::Next(StateName::HtmlFlowContinuationAfter), + State::Next(StateName::HtmlFlowContinuationStart), + ); + State::Retry(StateName::HtmlFlowBlankLineBefore) + } else if matches!(tokenizer.current, None | Some(b'\n')) { + tokenizer.exit(Name::HtmlFlowData); + State::Retry(StateName::HtmlFlowContinuationStart) + } else { + tokenizer.consume(); + State::Next(StateName::HtmlFlowContinuation) } } @@ -822,16 +808,14 @@ pub fn continuation_cdata_inside(tokenizer: &mut Tokenizer) -> State { /// ^ /// ``` pub fn continuation_declaration_inside(tokenizer: &mut Tokenizer) -> State { - match tokenizer.current { - Some(b'>') => { - tokenizer.consume(); - State::Next(StateName::HtmlFlowContinuationClose) - } - Some(b'-') if tokenizer.tokenize_state.marker == COMMENT => { - tokenizer.consume(); - State::Next(StateName::HtmlFlowContinuationDeclarationInside) - } - _ => State::Retry(StateName::HtmlFlowContinuation), + if tokenizer.tokenize_state.marker == COMMENT && tokenizer.current == Some(b'-') { + tokenizer.consume(); + State::Next(StateName::HtmlFlowContinuationDeclarationInside) + } else if tokenizer.current == Some(b'>') { + tokenizer.consume(); + State::Next(StateName::HtmlFlowContinuationClose) + } else { + State::Retry(StateName::HtmlFlowContinuation) } } |