You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2012/04/25 16:49:05 UTC

svn commit: r1330319 - /karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/CellarSupport.java

Author: jbonofre
Date: Wed Apr 25 14:49:04 2012
New Revision: 1330319

URL: http://svn.apache.org/viewvc?rev=1330319&view=rev
Log:
[KARAF-1325] Refactore the wildcard matcher to use regex

Modified:
    karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/CellarSupport.java

Modified: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/CellarSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/CellarSupport.java?rev=1330319&r1=1330318&r2=1330319&view=diff
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/CellarSupport.java (original)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/CellarSupport.java Wed Apr 25 14:49:04 2012
@@ -24,6 +24,8 @@ import java.util.Collection;
 import java.util.Dictionary;
 import java.util.HashSet;
 import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * Cellar support.
@@ -168,22 +170,13 @@ public class CellarSupport {
      * @return
      */
     protected boolean wildCardMatch(String item, String pattern) {
-        if (pattern == null || pattern.isEmpty()) {
-            return false;
-        }
-        String[] cards = pattern.split("\\*");
-        // Iterate over the cards.
-        for (String card : cards) {
-            int idx = item.indexOf(card);
-            // Card not detected in the text.
-            if (idx == -1) {
-                return false;
-            }
+        // update the pattern to have a valid regex pattern
+        pattern = pattern.replace("*", ".*");
+        // use the regex
+        Pattern p = Pattern.compile(pattern);
+        Matcher m = p.matcher(item);
 
-            // Move ahead, towards the right of the text.
-            item = item.substring(idx + card.length());
-        }
-        return true;
+        return m.matches();
     }