in base/src/com/google/idea/blaze/base/lang/buildfile/globbing/UnixGlob.java [160:205]
private static Pattern makePatternFromWildcard(String pattern) {
StringBuilder regexp = new StringBuilder();
for (int i = 0, len = pattern.length(); i < len; i++) {
char c = pattern.charAt(i);
switch (c) {
case '*':
int toIncrement = 0;
if (len > i + 1 && pattern.charAt(i + 1) == '*') {
// The pattern '**' is interpreted to match 0 or more directory separators, not 1 or
// more. We skip the next * and then find a trailing/leading '/' and get rid of it.
toIncrement = 1;
if (len > i + 2 && pattern.charAt(i + 2) == '/') {
// We have '**/' -- skip the '/'.
toIncrement = 2;
} else if (len == i + 2 && i > 0 && pattern.charAt(i - 1) == '/') {
// We have '/**' -- remove the '/'.
regexp.delete(regexp.length() - 1, regexp.length());
}
}
regexp.append(".*");
i += toIncrement;
break;
case '?':
regexp.append('.');
break;
// escape the regexp special characters that are allowed in wildcards
case '^':
case '$':
case '|':
case '+':
case '{':
case '}':
case '[':
case ']':
case '\\':
case '.':
regexp.append('\\');
regexp.append(c);
break;
default:
regexp.append(c);
break;
}
}
return Pattern.compile(regexp.toString());
}