fix(match): fix warnings

This commit is contained in:
Federico Terzi 2021-10-05 22:06:39 +02:00
parent e112633509
commit 11fd7ce167
4 changed files with 27 additions and 23 deletions

View File

@ -91,10 +91,12 @@ where
"".to_string()
};
if let Event::Key { key: _, chars } = event {
if let Some(chars) = chars {
buffer.push_str(&chars);
}
if let Event::Key {
key: _,
chars: Some(chars),
} = event
{
buffer.push_str(&chars);
}
// Keep the buffer length in check
@ -259,13 +261,16 @@ mod tests {
RegexMatch::new(2, "multi\\((?P<name1>.*?),(?P<name2>.*?)\\)"),
],
RegexMatcherOptions {
max_buffer_size: 15
max_buffer_size: 15,
},
);
assert_eq!(
get_matches_after_str("say hello(mary)", &matcher),
vec![match_result(1, "hello(mary)", &[("name", "mary")])]
);
assert_eq!(get_matches_after_str("hello(very long name over buffer)", &matcher), vec![]);
assert_eq!(
get_matches_after_str("hello(very long name over buffer)", &matcher),
vec![]
);
}
}

View File

@ -203,10 +203,10 @@ impl<Id: Clone> RollingMatcher<Id> {
fn is_word_separator(&self, event: &Event) -> bool {
match event {
Event::Key { key, chars } => {
if self.key_word_separators.contains(&key) {
if self.key_word_separators.contains(key) {
true
} else if let Some(char) = chars {
self.char_word_separators.contains(&char)
self.char_word_separators.contains(char)
} else {
false
}

View File

@ -66,15 +66,13 @@ fn insert_items_recursively<Id>(id: Id, node: &mut MatcherTreeNode<Id>, items: &
return;
}
let item = items.get(0).unwrap();
if items.len() == 1 {
let item = items.get(0).unwrap();
match item {
RollingItem::WordSeparator => {
let mut new_matches = Vec::new();
if let Some(node_ref) = node.word_separators.take() {
if let MatcherTreeRef::Matches(matches) = node_ref {
new_matches.extend(matches);
}
if let Some(MatcherTreeRef::Matches(matches)) = node.word_separators.take() {
new_matches.extend(matches);
}
new_matches.push(id);
node.word_separators = Some(MatcherTreeRef::Matches(new_matches))
@ -125,7 +123,6 @@ fn insert_items_recursively<Id>(id: Id, node: &mut MatcherTreeNode<Id>, items: &
}
}
} else {
let item = items.get(0).unwrap();
match item {
RollingItem::WordSeparator => match node.word_separators.as_mut() {
Some(MatcherTreeRef::Node(next_node)) => {

View File

@ -30,16 +30,18 @@ pub(crate) fn extract_string_from_events(
let mut right_separator = None;
for (i, (event, is_word_separator)) in events.iter().enumerate() {
if let Event::Key { key: _, chars } = event {
if let Some(chars) = chars {
string.push_str(chars);
if let Event::Key {
key: _,
chars: Some(chars),
} = event
{
string.push_str(chars);
if *is_word_separator {
if i == 0 {
left_separator = Some(chars.clone());
} else if i == (events.len() - 1) {
right_separator = Some(chars.clone());
}
if *is_word_separator {
if i == 0 {
left_separator = Some(chars.clone());
} else if i == (events.len() - 1) {
right_separator = Some(chars.clone());
}
}
}