First version of highlight after refacto

This commit is contained in:
Clémentine Urquizar 2021-05-06 18:31:41 +02:00
parent a03d9d496e
commit 60f6d1c373
No known key found for this signature in database
GPG Key ID: D8E7CC7422E77E1A

View File

@ -308,7 +308,7 @@ impl<'a, A: AsRef<[u8]>> Highlighter<'a, A> {
) -> Value { ) -> Value {
match value { match value {
Value::String(old_string) => { Value::String(old_string) => {
let value = self.format_string(old_string, need_to_crop, need_to_highlight); let value = self.format_string(old_string, matcher, need_to_crop, need_to_highlight);
Value::String(value) Value::String(value)
} }
Value::Array(values) => Value::Array( Value::Array(values) => Value::Array(
@ -326,19 +326,28 @@ impl<'a, A: AsRef<[u8]>> Highlighter<'a, A> {
value => value, value => value,
} }
} }
fn format_string(&self, s: String, need_to_crop: Option<u32>, need_to_highlight: bool) -> String { fn format_string(&self, s: String, matcher: &impl Matcher, need_to_crop: Option<u32>, need_to_highlight: bool) -> String {
let analyzed = self.analyzer.analyze(&s);
let word_iter: Box<dyn Iterator<Item = (String, bool)>> = if let Some(_crop_len) = need_to_crop { let word_iter: Box<dyn Iterator<Item = (String, bool)>> = if let Some(_crop_len) = need_to_crop {
// cropping iterator // cropping iterator
todo!() todo!()
} else { } else {
// normal Iterator Box::new(analyzed.reconstruct().map(|(word, token)| {
todo!() if token.is_word() && matcher.matches(token.text()){
(word.to_string(), true)
} else {
(word.to_string(), false)
}
}))
}; };
word_iter.map(|(word, is_match)| { word_iter.map(|(word, is_match)| {
if need_to_highlight && is_match { if need_to_highlight && is_match {
// highlight word let mut new_word = String::new();
todo!() new_word.push_str(&self.marks.0);
new_word.push_str(&word);
new_word.push_str(&self.marks.1);
new_word
} else { } else {
word word
} }