@@ -31,6 +31,7 @@ public class Name implements ResourceSelector {
private String regex = null;
private String pattern;
private boolean cs = true;
private boolean handleDirSep = false;
// caches for performance reasons
private RegularExpression reg;
@@ -61,6 +62,7 @@ public class Name implements ResourceSelector {
/**
* Set the regular expression to compare names against.
* @param r the regex to set.
* @since Ant 1.8.0
*/
public void setRegex(String r) {
regex = r;
@@ -70,6 +72,7 @@ public class Name implements ResourceSelector {
/**
* Get the regular expression used by this Name ResourceSelector.
* @return the String selection pattern.
* @since Ant 1.8.0
*/
public String getRegex() {
return regex;
@@ -91,6 +94,26 @@ public class Name implements ResourceSelector {
return cs;
}
/**
* Attribute specifing whether to ignore the difference
* between / and \ (the two common directory characters).
* @param handleDirSep a boolean, default is false.
* @since Ant 1.8.0
*/
public void setHandleDirSep(boolean handleDirSep) {
this.handleDirSep = handleDirSep;
}
/**
* Whether the difference between / and \ (the two common
* directory characters) is ignored.
*
* @since Ant 1.8.0
*/
public boolean doesHandledirSep() {
return handleDirSep;
}
/**
* Return true if this Resource is selected.
* @param r the Resource to check.
@@ -107,7 +130,7 @@ public class Name implements ResourceSelector {
private boolean matches(String name) {
if (pattern != null) {
return SelectorUtils.match(pattern, name, cs);
return SelectorUtils.match(modify( pattern) , modify( name) , cs);
} else {
if (reg == null) {
reg = new RegularExpression();
@@ -118,7 +141,14 @@ public class Name implements ResourceSelector {
if (!cs) {
options |= Regexp.MATCH_CASE_INSENSITIVE;
}
return expression.matches(name, options);
return expression.matches(modify(name), options);
}
}
private String modify(String s) {
if (s == null || !handleDirSep || s.indexOf("\\") == -1) {
return s;
}
return s.replace('\\', '/');
}
}