Skip to content

Commit

Permalink
Replace an ASCII space check with a is_whitespace check in Atom::new
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrutar committed Dec 9, 2024
1 parent 387b17c commit 2989e66
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
34 changes: 18 additions & 16 deletions matcher/src/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,32 +171,34 @@ impl Atom {
let mut saw_backslash = false;
for mut c in chars::graphemes(needle) {
if saw_backslash {
if c == ' ' {
needle_.push(' ');
if c.is_whitespace() {
needle_.push(c);
saw_backslash = false;
continue;
} else {
needle_.push('\\');
}
}
saw_backslash = c == '\\';
match case {
#[cfg(feature = "unicode-casefold")]
CaseMatching::Ignore => c = chars::to_lower_case(c),
#[cfg(feature = "unicode-casefold")]
CaseMatching::Smart => {
ignore_case = ignore_case && !chars::is_upper_case(c)
if !saw_backslash {
match case {
#[cfg(feature = "unicode-casefold")]
CaseMatching::Ignore => c = chars::to_lower_case(c),
#[cfg(feature = "unicode-casefold")]
CaseMatching::Smart => {
ignore_case = ignore_case && !chars::is_upper_case(c)
}
CaseMatching::Respect => (),
}
CaseMatching::Respect => (),
}
match normalization {
#[cfg(feature = "unicode-normalization")]
Normalization::Smart => {
normalize = normalize && chars::normalize(c) == c;
match normalization {
#[cfg(feature = "unicode-normalization")]
Normalization::Smart => {
normalize = normalize && chars::normalize(c) == c;
}
Normalization::Never => (),
}
Normalization::Never => (),
needle_.push(c);
}
needle_.push(c);
}
} else {
let chars = chars::graphemes(needle).map(|mut c| {
Expand Down
5 changes: 5 additions & 0 deletions matcher/src/pattern/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ fn case_matching() {
fn escape() {
let pat = Atom::parse("foo\\ bar", CaseMatching::Smart, Normalization::Smart);
assert_eq!(pat.needle.to_string(), "foo bar");
let pat = Atom::parse("foö\\ bar", CaseMatching::Smart, Normalization::Smart);
assert_eq!(pat.needle.to_string(), "foö bar");
// escaped double-width IDEOGRAPHIC SPACE
let pat = Atom::parse("foo\\ bar", CaseMatching::Smart, Normalization::Smart);
assert_eq!(pat.needle.to_string(), "foo bar");
let pat = Atom::parse("\\!foo", CaseMatching::Smart, Normalization::Smart);
assert_eq!(pat.needle.to_string(), "!foo");
assert_eq!(pat.kind, AtomKind::Fuzzy);
Expand Down

0 comments on commit 2989e66

Please sign in to comment.