Skip to content

Commit

Permalink
fix: pattern with multiple same char does not match #18
Browse files Browse the repository at this point in the history
  • Loading branch information
Armin Becher authored and Armin Becher committed Mar 11, 2024
1 parent 88304ab commit e0b01ea
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ impl<const MULTI_WILDCARD: char, const SINGLE_WILDCARD: char>
}
let mut pattern_idx = 0;
const NONE: usize = usize::MAX;
let mut last_matched_char: Option<char> = None;
let mut last_wildcard_idx = NONE;
let mut questionmark_matches: Vec<char> = Vec::with_capacity(self.max_questionmarks);
for input_char in input.chars() {
Expand All @@ -153,15 +154,14 @@ impl<const MULTI_WILDCARD: char, const SINGLE_WILDCARD: char>
questionmark_matches.clear();
}
pattern_idx += 1;
last_matched_char = Some(input_char);
}
Some(p) if p.has_wildcard => {
if p.next_char == None {
return true;
}
}
Some(p) if p.has_wildcard => {}
_ => {
if last_wildcard_idx == NONE {
return false;
} else if last_matched_char == Some(input_char) {
continue;
}
if !questionmark_matches.is_empty() {
// Try to match a different set for questionmark
Expand Down Expand Up @@ -265,6 +265,10 @@ mod tests {
assert_false!(m.matches(expected))
}

#[test_case("*113", "1113")]
#[test_case("*113", "113")]
#[test_case("*113", "11113")]
#[test_case("*113", "111113")]
#[test_case("*???a", "bbbba")]
#[test_case("*???a", "bbbbba")]
#[test_case("*???a", "bbbbbba")]
Expand Down

0 comments on commit e0b01ea

Please sign in to comment.