summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2016-11-28 17:57:26 -0500
committerAndrew Gallant <jamslam@gmail.com>2016-11-28 17:57:26 -0500
commit301a3fd71d3a923419d6d3e7604979b314121801 (patch)
tree9e473a9b2d7aea40ba0b9c78d10b0fb5243fb7a5
parentd12bdf35a57733184f5db897f685d8626a1a4b18 (diff)
Detect more uppercase literals for --smart-case.
This changes the uppercase literal detection for the "smart case" functionality. In particular, a character class is considered to have an uppercase literal if at least one of its ranges starts or stops with an uppercase literal. Fixes #229
-rw-r--r--grep/src/search.rs19
-rw-r--r--tests/tests.rs7
2 files changed, 25 insertions, 1 deletions
diff --git a/grep/src/search.rs b/grep/src/search.rs
index 4e4c48e9..850c8d62 100644
--- a/grep/src/search.rs
+++ b/grep/src/search.rs
@@ -318,12 +318,29 @@ impl<'b, 's> Iterator for Iter<'b, 's> {
fn has_uppercase_literal(expr: &Expr) -> bool {
use syntax::Expr::*;
+ fn byte_is_upper(b: u8) -> bool { b'A' <= b && b <= b'Z' }
match *expr {
Literal { ref chars, casei } => {
casei || chars.iter().any(|c| c.is_uppercase())
}
LiteralBytes { ref bytes, casei } => {
- casei || bytes.iter().any(|&b| b'A' <= b && b <= b'Z')
+ casei || bytes.iter().any(|&b| byte_is_upper(b))
+ }
+ Class(ref ranges) => {
+ for r in ranges {
+ if r.start.is_uppercase() || r.end.is_uppercase() {
+ return true;
+ }
+ }
+ false
+ }
+ ClassBytes(ref ranges) => {
+ for r in ranges {
+ if byte_is_upper(r.start) || byte_is_upper(r.end) {
+ return true;
+ }
+ }
+ false
}
Group { ref e, .. } => has_uppercase_literal(e),
Repeat { ref e, .. } => has_uppercase_literal(e),
diff --git a/tests/tests.rs b/tests/tests.rs
index 47169191..5c152b99 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -929,6 +929,13 @@ clean!(regression_228, "test", ".", |wd: WorkDir, mut cmd: Command| {
wd.assert_err(&mut cmd);
});
+// See: https://github.com/BurntSushi/ripgrep/issues/229
+clean!(regression_229, "[E]conomie", ".", |wd: WorkDir, mut cmd: Command| {
+ wd.create("foo", "economie");
+ cmd.arg("-S");
+ wd.assert_err(&mut cmd);
+});
+
// See: https://github.com/BurntSushi/ripgrep/issues/7
sherlock!(feature_7, "-fpat", "sherlock", |wd: WorkDir, mut cmd: Command| {
wd.create("pat", "Sherlock\nHolmes");