Skip to content

Commit

Permalink
Merge branch 'refactor-extract-fn' into 'master'
Browse files Browse the repository at this point in the history
Extract fn

See merge request mkjeldsen/commitmsgfmt!42
  • Loading branch information
commonquail committed Sep 22, 2023
2 parents b35e8b9 + ba23769 commit e0a0bc1
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,13 @@ pub fn parse(input: &str, comment_char: char) -> Vec<Token> {
} else if trailer.is_match(line) {
toks.push(Token::Trailer(line));
} else if let Some(y) = match toks.last_mut() {
Some(&mut Token::Footnote(_, ref mut b)) => {
b.push(' ');
b.push_str(line.trim());
None
}
Some(&mut Token::Paragraph(ref mut b)) => {
b.push(' ');
b.push_str(line.trim());
None
}
Some(&mut Token::Footnote(_, ref mut b)) => extend_prose_buffer_with_line(b, line),
Some(&mut Token::Paragraph(ref mut b)) => extend_prose_buffer_with_line(b, line),
Some(&mut Token::ListItem(_, _, ref mut b)) => {
if list_item.is_match(line) {
Some(list_item_from_line(&list_item, line))
} else {
b.push(' ');
b.push_str(line.trim());
None
extend_prose_buffer_with_line(b, line)
}
}
_ => {
Expand Down Expand Up @@ -180,6 +170,12 @@ fn list_item_from_line<'a>(pat: &Regex, line: &str) -> Token<'a> {
)
}

fn extend_prose_buffer_with_line(ref mut buf: &mut String, line: &str) -> Option<Token<'static>> {
buf.push(' ');
buf.push_str(line.trim());
None
}

#[cfg(test)]
mod tests {
use super::Token::*;
Expand Down

0 comments on commit e0a0bc1

Please sign in to comment.