From 55fc27067b1b2a11de81ad9aa33322cbb20e925b Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Sat, 19 Mar 2022 13:53:57 +0100 Subject: [PATCH] Simplify use of `endswith` --- src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fb1b2d4..fadb1a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -343,11 +343,11 @@ fn join_words<'a, I: Iterator>(mut words: I) -> String { match words.next() { None => String::new(), Some(word) => { - // Closure to determine whether a character ends a sentence. - let is_sentence_end = |c: char| c == '.' || c == '!' || c == '?'; + // Punctuation characters which ends a sentence. + let sentence_end = &['.', '!', '?']; let mut sentence = capitalize(word); - let mut needs_cap = sentence.ends_with(is_sentence_end); + let mut needs_cap = sentence.ends_with(sentence_end); // Add remaining words. for word in words { @@ -359,11 +359,11 @@ fn join_words<'a, I: Iterator>(mut words: I) -> String { sentence.push_str(word); } - needs_cap = word.ends_with(is_sentence_end); + needs_cap = word.ends_with(sentence_end); } // Ensure the sentence ends with either one of ".!?". - if !sentence.ends_with(is_sentence_end) { + if !sentence.ends_with(sentence_end) { // Trim all trailing punctuation characters to avoid // adding '.' after a ',' or similar. let idx = sentence.trim_end_matches(is_ascii_punctuation).len();