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:46:06 UTC
svn commit: r1330316 -
/karaf/cellar/branches/cellar-2.2.x/core/src/main/java/org/apache/karaf/cellar/core/CellarSupport.java
Author: jbonofre
Date: Wed Apr 25 14:46:05 2012
New Revision: 1330316
URL: http://svn.apache.org/viewvc?rev=1330316&view=rev
Log:
[KARAF-1325] Refactore the wildcard matcher to use regex
Modified:
karaf/cellar/branches/cellar-2.2.x/core/src/main/java/org/apache/karaf/cellar/core/CellarSupport.java
Modified: karaf/cellar/branches/cellar-2.2.x/core/src/main/java/org/apache/karaf/cellar/core/CellarSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/core/src/main/java/org/apache/karaf/cellar/core/CellarSupport.java?rev=1330316&r1=1330315&r2=1330316&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/core/src/main/java/org/apache/karaf/cellar/core/CellarSupport.java (original)
+++ karaf/cellar/branches/cellar-2.2.x/core/src/main/java/org/apache/karaf/cellar/core/CellarSupport.java Wed Apr 25 14:46:05 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.
@@ -172,22 +174,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();
}