Permalink
Browse files

removing ? as a pattern character

  • Loading branch information...
1 parent 88d759b commit acce14631ba2eefdeb022dbc2b9bc8a5672f912b @jhjaggars jhjaggars committed with bstansberry Dec 6, 2012
@@ -26,20 +26,17 @@
import java.util.StringTokenizer;
/**
- * Simple wildcard matcher for * and ?
+ * Simple wildcard matcher for *
* @author csams@redhat.com
* Date: 11/6/12
*/
public class WildcardPattern {
- private static final String WILDCARDS = "?*";
+ private static final String WILDCARDS = "*";
private final String[] tokens;
public WildcardPattern(String pattern){
- if (pattern.startsWith("?")) {
- throw new IllegalArgumentException("Patterns may not start with ?");
- }
if (!pattern.startsWith("*")) {
pattern = "*" + pattern;
@@ -61,11 +58,6 @@ public boolean matches(final String target){
int tokenEnd = tokens.length;
while(tokenIdx < tokenEnd && targetIdx < targetEnd && targetIdx > -1){
- if("?".equals(tokens[tokenIdx])){
- targetIdx++;
- tokenIdx++;
- }
- else
if("*".equals(tokens[tokenIdx])){
if(tokenIdx == (tokenEnd - 1)){
targetIdx = targetEnd;
@@ -98,17 +98,25 @@ public void testWildcardFilterPrefixGlob() throws Exception {
VirtualFileFilter filter = Filters.wildcard("*.txt");
VirtualFile good = VFS.getChild("/this/is/a/test.txt");
VirtualFile bad = VFS.getChild("/this/is/a/test.xml");
+ VirtualFile wingood = VFS.getChild("/C:/this/is/a/test.txt");
+ VirtualFile winbad = VFS.getChild("/C:/this/is/a/test.xml");
assertTrue(filter.accepts(good));
assertFalse(filter.accepts(bad));
+ assertTrue(filter.accepts(wingood));
+ assertFalse(filter.accepts(winbad));
}
@Test
public void testWildcardFilterSuffixGlob() throws Exception {
VirtualFileFilter filter = Filters.wildcard("/this/is*");
VirtualFile good = VFS.getChild("/this/is/a/test.txt");
VirtualFile bad = VFS.getChild("/that/is/a/test.txt");
+ VirtualFile wingood = VFS.getChild("/C:/this/is/a/test.txt");
+ VirtualFile winbad = VFS.getChild("/C:/that/is/a/test.txt");
assertTrue(filter.accepts(good));
assertFalse(filter.accepts(bad));
+ assertTrue(filter.accepts(wingood));
+ assertFalse(filter.accepts(winbad));
}
@Test
@@ -117,46 +125,12 @@ public void testWildcardFilterMiddleGlob() throws Exception {
VirtualFile good = VFS.getChild("/this/is/a/test.txt");
VirtualFile bad1 = VFS.getChild("/that/is/a/test.txt");
VirtualFile bad2 = VFS.getChild("/this/is/a/test.xml");
+ VirtualFile win = VFS.getChild("/C:/this/is/a/test.txt");
+ VirtualFile winbad = VFS.getChild("/C:/this/is/a/test.xml");
assertTrue(filter.accepts(good));
+ assertTrue(filter.accepts(win));
assertFalse(filter.accepts(bad1));
assertFalse(filter.accepts(bad2));
- }
-
- @Test(expected=IllegalArgumentException.class)
- public void testWildcardFilterPrefixSingle() throws Exception {
- VirtualFileFilter filter = Filters.wildcard("?this/is/a/test.txt");
- VirtualFileFilter filter2 = Filters.wildcard("?????/is/a/test.txt");
- }
-
- @Test
- public void testWildcardFilterPostfixSingle() throws Exception {
- VirtualFileFilter filter1 = Filters.wildcard("/this/is/a/test.tx?");
- VirtualFile good1 = VFS.getChild("/this/is/a/test.txt");
- VirtualFile bad1 = VFS.getChild("/that/is/a/test.dat");
- assertTrue(filter1.accepts(good1));
- assertFalse(filter1.accepts(bad1));
-
- VirtualFileFilter filter2 = Filters.wildcard("/this/is/a/test.???");
- VirtualFile good2 = VFS.getChild("/this/is/a/test.txt");
- VirtualFile bad2 = VFS.getChild("/that/is/a/blah.txt");
- assertTrue(filter2.accepts(good2));
- assertFalse(filter2.accepts(bad2));
-
- }
-
- @Test
- public void testWildcardFilterMiddleSingle() throws Exception {
- VirtualFileFilter filter1 = Filters.wildcard("/this/???/a/test.txt");
- VirtualFile good1 = VFS.getChild("/this/iss/a/test.txt");
- VirtualFile bad1 = VFS.getChild("/that/was/no/test.dat");
- assertTrue(filter1.accepts(good1));
- assertFalse(filter1.accepts(bad1));
-
- VirtualFileFilter filter2 = Filters.wildcard("/????/is/a/????.txt");
- VirtualFile good2 = VFS.getChild("/this/is/a/test.txt");
- VirtualFile bad2 = VFS.getChild("/that/is/no/test.txt");
- assertTrue(filter2.accepts(good2));
- assertFalse(filter2.accepts(bad2));
-
+ assertFalse(filter.accepts(winbad));
}
}

0 comments on commit acce146

Please sign in to comment.