Skip to content

Commit 2989e66

Browse files
committed
Replace an ASCII space check with a is_whitespace check in Atom::new
1 parent 387b17c commit 2989e66

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

Diff for: matcher/src/pattern.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -171,32 +171,34 @@ impl Atom {
171171
let mut saw_backslash = false;
172172
for mut c in chars::graphemes(needle) {
173173
if saw_backslash {
174-
if c == ' ' {
175-
needle_.push(' ');
174+
if c.is_whitespace() {
175+
needle_.push(c);
176176
saw_backslash = false;
177177
continue;
178178
} else {
179179
needle_.push('\\');
180180
}
181181
}
182182
saw_backslash = c == '\\';
183-
match case {
184-
#[cfg(feature = "unicode-casefold")]
185-
CaseMatching::Ignore => c = chars::to_lower_case(c),
186-
#[cfg(feature = "unicode-casefold")]
187-
CaseMatching::Smart => {
188-
ignore_case = ignore_case && !chars::is_upper_case(c)
183+
if !saw_backslash {
184+
match case {
185+
#[cfg(feature = "unicode-casefold")]
186+
CaseMatching::Ignore => c = chars::to_lower_case(c),
187+
#[cfg(feature = "unicode-casefold")]
188+
CaseMatching::Smart => {
189+
ignore_case = ignore_case && !chars::is_upper_case(c)
190+
}
191+
CaseMatching::Respect => (),
189192
}
190-
CaseMatching::Respect => (),
191-
}
192-
match normalization {
193-
#[cfg(feature = "unicode-normalization")]
194-
Normalization::Smart => {
195-
normalize = normalize && chars::normalize(c) == c;
193+
match normalization {
194+
#[cfg(feature = "unicode-normalization")]
195+
Normalization::Smart => {
196+
normalize = normalize && chars::normalize(c) == c;
197+
}
198+
Normalization::Never => (),
196199
}
197-
Normalization::Never => (),
200+
needle_.push(c);
198201
}
199-
needle_.push(c);
200202
}
201203
} else {
202204
let chars = chars::graphemes(needle).map(|mut c| {

Diff for: matcher/src/pattern/tests.rs

+5
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ fn case_matching() {
8787
fn escape() {
8888
let pat = Atom::parse("foo\\ bar", CaseMatching::Smart, Normalization::Smart);
8989
assert_eq!(pat.needle.to_string(), "foo bar");
90+
let pat = Atom::parse("foö\\ bar", CaseMatching::Smart, Normalization::Smart);
91+
assert_eq!(pat.needle.to_string(), "foö bar");
92+
// escaped double-width IDEOGRAPHIC SPACE
93+
let pat = Atom::parse("foo\\ bar", CaseMatching::Smart, Normalization::Smart);
94+
assert_eq!(pat.needle.to_string(), "foo bar");
9095
let pat = Atom::parse("\\!foo", CaseMatching::Smart, Normalization::Smart);
9196
assert_eq!(pat.needle.to_string(), "!foo");
9297
assert_eq!(pat.kind, AtomKind::Fuzzy);

0 commit comments

Comments
 (0)