aboutsummaryrefslogtreecommitdiffstats
path: root/src/construct/list.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-08-12 17:02:01 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-08-12 17:02:01 +0200
commit6ba11bdaca1721fb4591819604c340d147798f45 (patch)
treeef602b518043c0a7228e76d9d00bee95a17798d4 /src/construct/list.rs
parent504729a4a0c8f3e0d8fc9159e0273150b169e184 (diff)
downloadmarkdown-rs-6ba11bdaca1721fb4591819604c340d147798f45.tar.gz
markdown-rs-6ba11bdaca1721fb4591819604c340d147798f45.tar.bz2
markdown-rs-6ba11bdaca1721fb4591819604c340d147798f45.zip
Remove `match` statements if clumsy
Diffstat (limited to 'src/construct/list.rs')
-rw-r--r--src/construct/list.rs53
1 files changed, 28 insertions, 25 deletions
diff --git a/src/construct/list.rs b/src/construct/list.rs
index 206f823..076ff58 100644
--- a/src/construct/list.rs
+++ b/src/construct/list.rs
@@ -86,17 +86,20 @@ pub fn start(tokenizer: &mut Tokenizer) -> State {
/// ^
/// ```
pub fn before(tokenizer: &mut Tokenizer) -> State {
- match tokenizer.current {
- // Unordered.
- Some(b'*' | b'-') => {
- tokenizer.check(State::Nok, State::Next(StateName::ListBeforeUnordered));
- State::Retry(StateName::ThematicBreakStart)
- }
- Some(b'+') => State::Retry(StateName::ListBeforeUnordered),
- // Ordered.
- Some(b'0'..=b'9') if !tokenizer.interrupt => State::Retry(StateName::ListBeforeOrdered),
- Some(b'1') => State::Retry(StateName::ListBeforeOrdered),
- _ => State::Nok,
+ // Unordered.
+ if matches!(tokenizer.current, Some(b'*' | b'-')) {
+ tokenizer.check(State::Nok, State::Next(StateName::ListBeforeUnordered));
+ State::Retry(StateName::ThematicBreakStart)
+ } else if tokenizer.current == Some(b'+') {
+ State::Retry(StateName::ListBeforeUnordered)
+ }
+ // Ordered.
+ else if tokenizer.current == Some(b'1')
+ || (matches!(tokenizer.current, Some(b'0'..=b'9')) && !tokenizer.interrupt)
+ {
+ State::Retry(StateName::ListBeforeOrdered)
+ } else {
+ State::Nok
}
}
@@ -132,20 +135,20 @@ pub fn before_ordered(tokenizer: &mut Tokenizer) -> State {
/// ^
/// ```
pub fn value(tokenizer: &mut Tokenizer) -> State {
- match tokenizer.current {
- Some(b'.' | b')') if !tokenizer.interrupt || tokenizer.tokenize_state.size < 2 => {
- tokenizer.exit(Name::ListItemValue);
- State::Retry(StateName::ListMarker)
- }
- Some(b'0'..=b'9') if tokenizer.tokenize_state.size + 1 < LIST_ITEM_VALUE_SIZE_MAX => {
- tokenizer.tokenize_state.size += 1;
- tokenizer.consume();
- State::Next(StateName::ListValue)
- }
- _ => {
- tokenizer.tokenize_state.size = 0;
- State::Nok
- }
+ if matches!(tokenizer.current, Some(b'.' | b')'))
+ && (!tokenizer.interrupt || tokenizer.tokenize_state.size < 2)
+ {
+ tokenizer.exit(Name::ListItemValue);
+ State::Retry(StateName::ListMarker)
+ } else if matches!(tokenizer.current, Some(b'0'..=b'9'))
+ && tokenizer.tokenize_state.size + 1 < LIST_ITEM_VALUE_SIZE_MAX
+ {
+ tokenizer.tokenize_state.size += 1;
+ tokenizer.consume();
+ State::Next(StateName::ListValue)
+ } else {
+ tokenizer.tokenize_state.size = 0;
+ State::Nok
}
}