Author: ccustine
Date: Sat Oct 24 22:26:15 2009
New Revision: 829458

URL: http://svn.apache.org/viewvc?rev=829458&view=rev
Log:
FELIX-1801 - Case insensitive grep outputs all uppercase in match results

Modified:
    
felix/trunk/karaf/shell/commands/src/main/java/org/apache/felix/karaf/shell/commands/GrepAction.java

Modified: 
felix/trunk/karaf/shell/commands/src/main/java/org/apache/felix/karaf/shell/commands/GrepAction.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/karaf/shell/commands/src/main/java/org/apache/felix/karaf/shell/commands/GrepAction.java?rev=829458&r1=829457&r2=829458&view=diff
==============================================================================
--- 
felix/trunk/karaf/shell/commands/src/main/java/org/apache/felix/karaf/shell/commands/GrepAction.java
 (original)
+++ 
felix/trunk/karaf/shell/commands/src/main/java/org/apache/felix/karaf/shell/commands/GrepAction.java
 Sat Oct 24 22:26:15 2009
@@ -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) {


Reply via email to