FELIX-1801 - Case insensitive grep outputs all uppercase in match results
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@829458 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/karaf/shell/commands/src/main/java/org/apache/felix/karaf/shell/commands/GrepAction.java b/karaf/shell/commands/src/main/java/org/apache/felix/karaf/shell/commands/GrepAction.java
index 0cfb0c1..e30e505 100644
--- a/karaf/shell/commands/src/main/java/org/apache/felix/karaf/shell/commands/GrepAction.java
+++ b/karaf/shell/commands/src/main/java/org/apache/felix/karaf/shell/commands/GrepAction.java
@@ -100,11 +100,15 @@
} else {
regexp = ".*" + regexp + ".*";
}
+ Pattern p;
+ Pattern p2;
if (ignoreCase) {
- regexp = regexp.toUpperCase();
+ p = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE);
+ p2 = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
+ } else {
+ p = Pattern.compile(regexp);
+ p2 = Pattern.compile(regex);
}
- Pattern p = Pattern.compile(regexp);
- Pattern p2 = Pattern.compile(regex);
try {
boolean firstPrint = true;
int nb = 0;
@@ -113,14 +117,13 @@
int lineMatch = 0;
Reader r = new InputStreamReader(System.in);
while ((line = readLine(r)) != null) {
- String pattern = ignoreCase ? line.toUpperCase() : line;
- if (p.matcher(pattern).matches() ^ invertMatch) {
+ if (p.matcher(line).matches() ^ invertMatch) {
if (!count && lineNumber) {
System.out.print(String.format("%6d ", lineno++));
}
- Matcher matcher2 = p2.matcher(pattern);
+ Matcher matcher2 = p2.matcher(line);
StringBuffer sb = new StringBuffer();
while (matcher2.find()) {
if (!invertMatch && color != ColorOption.never) {