aboutsummaryrefslogtreecommitdiffstats
path: root/src/construct/partial_title.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-05 13:03:09 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-05 13:03:09 +0200
commitfd860a975b84da9a79abfa247787e6adbd5ea34c (patch)
treebd9db168c57478f4f37c234eac4087c2d69a6445 /src/construct/partial_title.rs
parent0bc099f8f8b6541a962e604b7ac25445a2a9252a (diff)
downloadmarkdown-rs-fd860a975b84da9a79abfa247787e6adbd5ea34c.tar.gz
markdown-rs-fd860a975b84da9a79abfa247787e6adbd5ea34c.tar.bz2
markdown-rs-fd860a975b84da9a79abfa247787e6adbd5ea34c.zip
Refactor code style
Diffstat (limited to '')
-rw-r--r--src/construct/partial_title.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/construct/partial_title.rs b/src/construct/partial_title.rs
index caacb0d..010f554 100644
--- a/src/construct/partial_title.rs
+++ b/src/construct/partial_title.rs
@@ -102,6 +102,19 @@ impl Kind {
_ => unreachable!("invalid char"),
}
}
+ /// Turn [Code] into a kind.
+ ///
+ /// > 👉 **Note**: an opening paren must be used for `Kind::Paren`.
+ ///
+ /// ## Panics
+ ///
+ /// Panics if `code` is not `Code::Char('(' | '"' | '\'')`.
+ fn from_code(code: Code) -> Kind {
+ match code {
+ Code::Char(char) => Kind::from_char(char),
+ _ => unreachable!("invalid code"),
+ }
+ }
}
/// State needed to parse titles.
@@ -124,10 +137,10 @@ struct Info {
/// ```
pub fn start(tokenizer: &mut Tokenizer, code: Code, options: Options) -> StateFnResult {
match code {
- Code::Char(char) if char == '"' || char == '\'' || char == '(' => {
+ Code::Char('"' | '\'' | '(') => {
let info = Info {
connect: false,
- kind: Kind::from_char(char),
+ kind: Kind::from_code(code),
options,
};
tokenizer.enter(info.options.title.clone());
@@ -180,7 +193,7 @@ fn at_break(tokenizer: &mut Tokenizer, code: Code, mut info: Info) -> StateFnRes
begin(tokenizer, code, info)
}
Code::None => (State::Nok, None),
- Code::CarriageReturnLineFeed | Code::Char('\r' | '\n') => tokenizer.go(
+ Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => tokenizer.go(
space_or_tab_eol_with_options(EolOptions {
content_type: Some(ContentType::String),
connect: info.connect,
@@ -216,7 +229,7 @@ fn title(tokenizer: &mut Tokenizer, code: Code, info: Info) -> StateFnResult {
tokenizer.exit(TokenType::Data);
at_break(tokenizer, code, info)
}
- Code::None | Code::CarriageReturnLineFeed | Code::Char('\r' | '\n') => {
+ Code::None | Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => {
tokenizer.exit(TokenType::Data);
at_break(tokenizer, code, info)
}