Skip to content

Commit

Permalink
Merge pull request #23 from orium/fix-star-in-input
Browse files Browse the repository at this point in the history
Fix bug where a `*` in the pattern would be considered a literal `*` if the current char in the input was also a `*`.
  • Loading branch information
becheran authored May 22, 2024
2 parents f00871d + dfb50bd commit 406461f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ impl<const MULTI_WILDCARD: char, const SINGLE_WILDCARD: char>

loop {
if pattern_idx < self.pattern.len()
&& self.pattern[pattern_idx] == MULTI_WILDCARD
{
start_idx = pattern_idx;
matched = input_chars.clone();
pattern_idx += 1;
} else if pattern_idx < self.pattern.len()
&& (self.pattern[pattern_idx] == SINGLE_WILDCARD
|| self.pattern[pattern_idx] == input_char)
{
Expand All @@ -126,12 +132,6 @@ impl<const MULTI_WILDCARD: char, const SINGLE_WILDCARD: char>
} else {
break;
}
} else if pattern_idx < self.pattern.len()
&& self.pattern[pattern_idx] == MULTI_WILDCARD
{
start_idx = pattern_idx;
matched = input_chars.clone();
pattern_idx += 1;
} else if start_idx != NONE {
pattern_idx = start_idx + 1;
if let Some(next_char) = matched.next() {
Expand Down Expand Up @@ -292,6 +292,7 @@ mod tests {
#[test_case("*cat*", "d&(*og_cat_dog")]
#[test_case("*?*", "d&(*og_cat_dog")]
#[test_case("*a*", "d&(*og_cat_dog")]
#[test_case("a*b", "a*xb")]
#[test_case("*", "*")]
#[test_case("*", "?")]
#[test_case("?", "?")]
Expand Down

0 comments on commit 406461f

Please sign in to comment.