get_summarytext_by_raw: drop leading and trailing whitespace

Also remove unnecessary use of regexp.
This commit is contained in:
Alexander Krotov
2020-09-20 23:51:52 +03:00
parent 97b1a1c392
commit fc0e88539a

View File

@@ -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<String> = None;