diff options
author | dana <dana@dana.is> | 2017-11-16 16:20:16 -0600 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2017-11-22 06:56:03 -0500 |
commit | 679198e71aaa33b777405924110a96cf594aef12 (patch) | |
tree | 381a866f86d328c3601e13c34d6600085a8212db /globset | |
parent | 2c84825ccbe2d42e0648b56a7d3289c5f5bcb9e5 (diff) |
Support both [^...] and [!...] for globset class negation
Adds support for [^...] class negation in globs for parity with git, &al.
Fixes #663
Diffstat (limited to 'globset')
-rw-r--r-- | globset/src/glob.rs | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/globset/src/glob.rs b/globset/src/glob.rs index 84e3156b..b081a21e 100644 --- a/globset/src/glob.rs +++ b/globset/src/glob.rs @@ -840,12 +840,15 @@ impl<'a> Parser<'a> { Ok(()) } } - let mut negated = false; let mut ranges = vec![]; - if self.chars.peek() == Some(&'!') { - assert!(self.bump() == Some('!')); - negated = true; - } + let negated = match self.chars.peek() { + Some(&'!') | Some(&'^') => { + let bump = self.bump(); + assert!(bump == Some('!') || bump == Some('^')); + true + } + _ => false, + }; let mut first = true; let mut in_range = false; loop { @@ -1073,6 +1076,8 @@ mod tests { syntax!(cls17, "[a-z0-9]", vec![rclass(&[('a', 'z'), ('0', '9')])]); syntax!(cls18, "[!0-9a-z]", vec![rclassn(&[('0', '9'), ('a', 'z')])]); syntax!(cls19, "[!a-z0-9]", vec![rclassn(&[('a', 'z'), ('0', '9')])]); + syntax!(cls20, "[^a]", vec![classn('a', 'a')]); + syntax!(cls21, "[^a-z]", vec![classn('a', 'z')]); syntaxerr!(err_rseq1, "a**", ErrorKind::InvalidRecursive); syntaxerr!(err_rseq2, "**a", ErrorKind::InvalidRecursive); @@ -1162,6 +1167,7 @@ mod tests { matches!(matchrange9, "[-a-c]", "b"); matches!(matchrange10, "[a-c-]", "b"); matches!(matchrange11, "[-]", "-"); + matches!(matchrange12, "a[^0-9]b", "a_b"); matches!(matchpat1, "*hello.txt", "hello.txt"); matches!(matchpat2, "*hello.txt", "gareth_says_hello.txt"); @@ -1234,6 +1240,9 @@ mod tests { nmatches!(matchnot25, "*.c", "mozilla-sha1/sha1.c", SLASHLIT); nmatches!(matchnot26, "**/m4/ltoptions.m4", "csharp/src/packages/repositories.config", SLASHLIT); + nmatches!(matchnot27, "a[^0-9]b", "a0b"); + nmatches!(matchnot28, "a[^0-9]b", "a9b"); + nmatches!(matchnot29, "[^-]", "-"); macro_rules! extract { ($which:ident, $name:ident, $pat:expr, $expect:expr) => { |