From fc0e88539aa1e7c7abd0805d33dd14903555a235 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Sun, 20 Sep 2020 23:51:52 +0300 Subject: [PATCH] get_summarytext_by_raw: drop leading and trailing whitespace Also remove unnecessary use of regexp. --- src/message.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/message.rs b/src/message.rs index 215e11581..e4311c3aa 100644 --- a/src/message.rs +++ b/src/message.rs @@ -2,7 +2,7 @@ use async_std::path::{Path, PathBuf}; use deltachat_derive::{FromSql, ToSql}; -use lazy_static::lazy_static; +use itertools::Itertools; use serde::{Deserialize, Serialize}; use crate::chat::{self, Chat, ChatId}; @@ -20,10 +20,6 @@ use crate::param::*; use crate::pgp::*; use crate::stock::StockMessage; -lazy_static! { - static ref UNWRAP_RE: regex::Regex = regex::Regex::new(r"\s+").unwrap(); -} - // In practice, the user additionally cuts the string themselves // pixel-accurate. const SUMMARY_CHARACTERS: usize = 160; @@ -1402,7 +1398,7 @@ pub async fn get_summarytext_by_raw( prefix }; - UNWRAP_RE.replace_all(&summary, " ").to_string() + summary.split_whitespace().join(" ") } // as we do not cut inside words, this results in about 32-42 characters. @@ -1842,7 +1838,7 @@ mod tests { let d = test::TestContext::new().await; let ctx = &d.ctx; - let some_text = Some("bla bla".to_string()); + let some_text = Some(" bla \t\n\tbla\n\t".to_string()); let empty_text = Some("".to_string()); let no_text: Option = None;