int i = 0; while (i < globPattern.length()) { char c = globPattern.charAt(i++); switch (c) { case'\\': // escape special characters if (i == globPattern.length()) { thrownew PatternSyntaxException("No character to escape",
globPattern, i - 1);
} char next = globPattern.charAt(i++); if (isGlobMeta(next) || isRegexMeta(next)) {
regex.append('\\');
}
regex.append(next); break; case'/': if (isDos) {
regex.append("\\\\");
} else {
regex.append(c);
} break; case'[': // don't match name separator in class if (isDos) {
regex.append("[[^\\\\]&&[");
} else {
regex.append("[[^/]&&[");
} if (next(globPattern, i) == '^') { // escape the regex negation char if it appears
regex.append("\\^");
i++;
} else { // negation if (next(globPattern, i) == '!') {
regex.append('^');
i++;
} // hyphen allowed at start if (next(globPattern, i) == '-') {
regex.append('-');
i++;
}
} boolean hasRangeStart = false; char last = 0; while (i < globPattern.length()) {
c = globPattern.charAt(i++); if (c == ']') { break;
} if (c == '/' || (isDos && c == '\\')) { thrownew PatternSyntaxException("Explicit 'name separator' in class",
globPattern, i - 1);
} // TBD: how to specify ']' in a class? if (c == '\\' || c == '[' ||
c == '&' && next(globPattern, i) == '&') { // escape '\', '[' or "&&" for regex class
regex.append('\\');
}
regex.append(c);
if (c == '-') { if (!hasRangeStart) { thrownew PatternSyntaxException("Invalid range",
globPattern, i - 1);
} if ((c = next(globPattern, i++)) == EOL || c == ']') { break;
} if (c < last) { thrownew PatternSyntaxException("Invalid range",
globPattern, i - 3);
}
regex.append(c);
hasRangeStart = false;
} else {
hasRangeStart = true;
last = c;
}
} if (c != ']') { thrownew PatternSyntaxException("Missing ']", globPattern, i - 1);
}
regex.append("]]"); break; case'{': if (inGroup) { thrownew PatternSyntaxException("Cannot nest groups",
globPattern, i - 1);
}
regex.append("(?:(?:");
inGroup = true; break; case'}': if (inGroup) {
regex.append("))");
inGroup = false;
} else {
regex.append('}');
} break; case',': if (inGroup) {
regex.append(")|(?:");
} else {
regex.append(',');
} break; case'*': if (next(globPattern, i) == '*') { // crosses directory boundaries
regex.append(".*");
i++;
} else { // within directory boundary if (isDos) {
regex.append("[^\\\\]*");
} else {
regex.append("[^/]*");
}
} break; case'?': if (isDos) {
regex.append("[^\\\\]");
} else {
regex.append("[^/]");
} break;
default: if (isRegexMeta(c)) {
regex.append('\\');
}
regex.append(c);
}
}
if (inGroup) { thrownew PatternSyntaxException("Missing '}", globPattern, i - 1);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.