Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #82 from chrisbrookes/fix-81
Browse files Browse the repository at this point in the history
Fix for #81, fixed logic in match method
  • Loading branch information
ysb33r authored Aug 22, 2018
2 parents e6b358b + c3bc4b9 commit d1f62a8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
*/

package org.ysb33r.groovy.dsl.vfs.impl.ant;
package org.ysb33r.groovy.dsl.vfs.impl.ant



Expand All @@ -45,20 +45,20 @@ package org.ysb33r.groovy.dsl.vfs.impl.ant;
* <p>This is a Singleton.</p>
*
*/
final class SelectorUtils {
final class SelectorUtils {

/**
* The pattern that matches an arbitrary number of directories.
*
* @since Ant 1.8.0
*/
static final String DEEP_TREE_MATCH = "**"
/**
* The pattern that matches an arbitrary number of directories.
*
* @since Ant 1.8.0
*/
static final String DEEP_TREE_MATCH = "**"

/**
* Core implementation of matchPath. It is isolated so that it
* can be called from TokenizedPattern.
*/
static boolean matchPath(String[] tokenizedPattern, String[] strDirs, boolean isCaseSensitive) {
static boolean matchPath(String[] tokenizedPattern, String[] strDirs, boolean isCaseSensitive) {
int patIdxStart = 0
int patIdxEnd = tokenizedPattern.length - 1
int strIdxStart = 0
Expand Down Expand Up @@ -159,7 +159,7 @@ package org.ysb33r.groovy.dsl.vfs.impl.ant;
strIdxStart = foundIdx + patLength
}

!((patIdxStart..patIdxEnd).any { tokenizedPattern[it] != DEEP_TREE_MATCH } )
!((patIdxStart..patIdxEnd).any { tokenizedPattern[it] != DEEP_TREE_MATCH } )
}

/**
Expand All @@ -177,7 +177,7 @@ package org.ysb33r.groovy.dsl.vfs.impl.ant;
* @return <code>true</code> if the string matches against the pattern,
* or <code>false</code> otherwise.
*/
static boolean match(String pattern, String str, boolean caseSensitive) {
static boolean match(String pattern, String str, boolean caseSensitive) {
Character[] patArr = pattern.toCharArray()
Character[] strArr = str.toCharArray()
int patIdxStart = 0
Expand Down Expand Up @@ -271,7 +271,7 @@ package org.ysb33r.groovy.dsl.vfs.impl.ant;

if (patIdxTmp == patIdxStart + 1) {
// Two stars next to each other, skip the first one.
patIdxStart = patIdxStart++
patIdxStart++
continue
}

Expand All @@ -284,13 +284,9 @@ package org.ysb33r.groovy.dsl.vfs.impl.ant;
for (int i = 0; i <= strLength - patLength; i++) {
for (int j = 0; j < patLength; j++) {
ch = patArr[patIdxStart + j + 1]
if (!ch == '?') {
if (different(caseSensitive, ch, strArr[strIdxStart + i + j])) {
continue strLoop
}

if (ch != '?' && different(caseSensitive, ch, strArr[strIdxStart + i + j])) {
continue strLoop
}

}

foundIdx = strIdxStart + i
Expand Down Expand Up @@ -321,7 +317,7 @@ package org.ysb33r.groovy.dsl.vfs.impl.ant;
/**
* Same as {@link #tokenizePath tokenizePath} but hopefully faster.
*/
static String[] tokenizePathAsArray(final String path) {
static String[] tokenizePathAsArray(final String path) {
path.split('/').findAll { it.size() } as String []
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ class AntPatternSelectorSpec extends Specification {
]
],

'Select files by multiple *-wildcard' : [
filter : {
include 'subdirA/subdirB/*ile7*.txt'
},
included : [
'subdirA/subdirB/file777.txt'
]
],

'Select files in wildcarded subfolder by *-wildcard' : [
filter : {
include 'subdirA/*dir*/*.txt'
},
included : [
'subdirA/subdirB/file5.txt',
'subdirA/subdirB/file6.txt',
'subdirA/subdirB/file777.txt'
]
],

'Select everything recursively' : [
filter : {
include '**'
Expand Down

0 comments on commit d1f62a8

Please sign in to comment.