diff --git a/src/index/value.rs b/src/index/value.rs index b712476..2dc2493 100644 --- a/src/index/value.rs +++ b/src/index/value.rs @@ -1,4 +1,5 @@ use chrono::{DateTime, Utc}; +use voca_rs::Voca; /// The `Index` value pub struct Value { @@ -41,32 +42,19 @@ impl Value { } fn filter_name(value: Option) -> Option { - value.map(crop) + value.map(filter) } fn filter_list(value: Option>) -> Option> { - value.map(|f| { - f.into_iter() - .map(|(n, l)| (crop(sanitize(&n)), l)) - .collect() - }) + value.map(|f| f.into_iter().map(|(n, l)| (filter(n), l)).collect()) } /// Crop long values (prevents unexpected memory pool usage) -fn crop(value: String) -> String { +fn filter(value: String) -> String { const C: usize = 125; // + 3 for `...` offset, 128 chars max @TODO optional - if value.chars().count() > C { - format!( - "{}...", - sanitize(&value.chars().take(C).collect::()) - ) - } else { - value + let s = value._strip_bom()._strip_tags(); + if s.chars().count() > C { + return format!("{}...", s.chars().take(C).collect::()); } -} - -/// Strip tags & bom chars from string -fn sanitize(value: &str) -> String { - use voca_rs::strip::*; - strip_tags(&strip_bom(value)) + s }