aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-06-20 18:41:11 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-06-20 18:41:11 +0200
commitef5f9a97493fe4a616b49a744d5a571a99ead8e9 (patch)
tree26c72d49f5d79811383c78e67f87e1d1ba73b75f /src
parente869533b99eecdc133ed3b4bedc22d24dc2c2dd9 (diff)
downloadmarkdown-rs-ef5f9a97493fe4a616b49a744d5a571a99ead8e9.tar.gz
markdown-rs-ef5f9a97493fe4a616b49a744d5a571a99ead8e9.tar.bz2
markdown-rs-ef5f9a97493fe4a616b49a744d5a571a99ead8e9.zip
Refactor some code
Diffstat (limited to '')
-rw-r--r--src/construct/partial_destination.rs63
1 files changed, 31 insertions, 32 deletions
diff --git a/src/construct/partial_destination.rs b/src/construct/partial_destination.rs
index 901a10d..82e83fe 100644
--- a/src/construct/partial_destination.rs
+++ b/src/construct/partial_destination.rs
@@ -140,51 +140,50 @@ fn enclosed_escape(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
/// ```markdown
/// a|b
/// ```
-// To do: these arms can be improved?
fn raw(tokenizer: &mut Tokenizer, code: Code, balance: usize) -> StateFnResult {
// To do: configurable.
let limit = usize::MAX;
match code {
- Code::Char('(') if balance >= limit => (State::Nok, None),
Code::Char('(') => {
- tokenizer.consume(code);
- (
- State::Fn(Box::new(move |t, c| raw(t, c, balance + 1))),
- None,
- )
- }
- Code::Char(')') if balance == 0 => {
- tokenizer.exit(TokenType::ChunkString);
- tokenizer.exit(TokenType::DefinitionDestinationString);
- tokenizer.exit(TokenType::DefinitionDestinationRaw);
- tokenizer.exit(TokenType::DefinitionDestination);
- (State::Ok, Some(vec![code]))
+ if balance >= limit {
+ (State::Nok, None)
+ } else {
+ tokenizer.consume(code);
+ (
+ State::Fn(Box::new(move |t, c| raw(t, c, balance + 1))),
+ None,
+ )
+ }
}
Code::Char(')') => {
- tokenizer.consume(code);
- (
- State::Fn(Box::new(move |t, c| raw(t, c, balance - 1))),
- None,
- )
- }
- Code::None
- | Code::CarriageReturnLineFeed
- | Code::VirtualSpace
- | Code::Char('\t' | '\r' | '\n' | ' ')
- if balance > 0 =>
- {
- (State::Nok, None)
+ if balance == 0 {
+ tokenizer.exit(TokenType::ChunkString);
+ tokenizer.exit(TokenType::DefinitionDestinationString);
+ tokenizer.exit(TokenType::DefinitionDestinationRaw);
+ tokenizer.exit(TokenType::DefinitionDestination);
+ (State::Ok, Some(vec![code]))
+ } else {
+ tokenizer.consume(code);
+ (
+ State::Fn(Box::new(move |t, c| raw(t, c, balance - 1))),
+ None,
+ )
+ }
}
Code::None
| Code::CarriageReturnLineFeed
| Code::VirtualSpace
| Code::Char('\t' | '\r' | '\n' | ' ') => {
- tokenizer.exit(TokenType::ChunkString);
- tokenizer.exit(TokenType::DefinitionDestinationString);
- tokenizer.exit(TokenType::DefinitionDestinationRaw);
- tokenizer.exit(TokenType::DefinitionDestination);
- (State::Ok, Some(vec![code]))
+ if balance > 0 {
+ (State::Nok, None)
+ } else {
+ tokenizer.exit(TokenType::ChunkString);
+ tokenizer.exit(TokenType::DefinitionDestinationString);
+ tokenizer.exit(TokenType::DefinitionDestinationRaw);
+ tokenizer.exit(TokenType::DefinitionDestination);
+ (State::Ok, Some(vec![code]))
+ }
}
Code::Char(char) if char.is_ascii_control() => (State::Nok, None),
Code::Char('\\') => {