if (lookBehind(sb) == '[' && isLetter(lookAhead(pattern, i))) in_char_class = true; sb.append(':'); if (lookAhead(pattern, i) == ']') sb.append('\\').append(c); else char lookAhead = lookAhead(pattern, i); if (lookAhead == ']' || lookAhead == '[') ignoreLastBracket = true; } else { char lookAhead = lookAhead(pattern, i); if (lookAhead != '\\' && lookAhead != '[' && lookAhead != '?' && lookAhead != '*' && lookAhead != ' ' && lookBehind(sb) != '\\') { break; char lookBehind = lookBehind(sb); if ((lookBehind == '[' && !ignoreLastBracket) || lookBehind == '^') { } else { in_char_class = false; String charCl = checkPosixCharClass(charClass); reset(charClass);
private static IMatcher createNameMatcher0(String segment, Character pathSeparator, boolean dirOnly, boolean lastSegment) throws InvalidPatternException { // check if we see /** or ** segments => double star pattern if (WildMatcher.WILDMATCH.equals(segment) || WildMatcher.WILDMATCH2.equals(segment)) return dirOnly && lastSegment ? WILD_ONLY_DIRECTORY : WILD_NO_DIRECTORY; PatternState state = checkWildCards(segment); switch (state) { case LEADING_ASTERISK_ONLY: return new LeadingAsteriskMatcher(segment, pathSeparator, dirOnly); case TRAILING_ASTERISK_ONLY: return new TrailingAsteriskMatcher(segment, pathSeparator, dirOnly); case COMPLEX: return new WildCardMatcher(segment, pathSeparator, dirOnly); default: return new NameMatcher(segment, pathSeparator, dirOnly, true); } }
WildCardMatcher(String pattern, Character pathSeparator, boolean dirOnly) throws InvalidPatternException { super(pattern, pathSeparator, dirOnly, false); p = convertGlob(subPattern); }
private boolean isSimplePathWithSegments(String path) { return !isWildCard(path) && path.indexOf('\\') < 0 && count(path, slash, true) > 0; }
NameMatcher(String pattern, Character pathSeparator, boolean dirOnly, boolean deleteBackslash) { super(pattern, dirOnly); slash = getPathSeparator(pathSeparator); if (deleteBackslash) { pattern = Strings.deleteBackslash(pattern); } beginning = pattern.length() == 0 ? false : pattern.charAt(0) == slash; if (!beginning) { this.subPattern = pattern; } else { this.subPattern = pattern.substring(1); } }
private PathMatcher(String pattern, Character pathSeparator, boolean dirOnly) throws InvalidPatternException { super(pattern, dirOnly); slash = getPathSeparator(pathSeparator); beginning = pattern.indexOf(slash) == 0; if (isSimplePathWithSegments(pattern)) matchers = null; else matchers = createMatchers(split(pattern, slash), pathSeparator, dirOnly); }
dirOnly = isDirectoryPattern(pattern); if (dirOnly) { pattern = stripTrailingWhitespace(pattern); pattern = stripTrailing(pattern, PATH_SEPARATOR); if (pattern.length() == 0) { this.matcher = NO_MATCH;
static boolean isWildCard(String pattern) { return pattern.indexOf('*') != -1 || isComplexWildcard(pattern); }
private static boolean isComplexWildcard(String pattern) { int idx1 = pattern.indexOf('['); if (idx1 != -1) { return true; } if (pattern.indexOf('?') != -1) { return true; } else { // check if the backslash escapes one of the glob special characters // if not, backslash is not part of a regex and treated literally int backSlash = pattern.indexOf('\\'); if (backSlash >= 0) { int nextIdx = backSlash + 1; if (pattern.length() == nextIdx) { return false; } char nextChar = pattern.charAt(nextIdx); if (escapedByBackslash(nextChar)) { return true; } else { return false; } } } return false; }
/** * Create path matcher * * @param pattern * a pattern * @param pathSeparator * if this parameter isn't null then this character will not * match at wildcards(* and ? are wildcards). * @param dirOnly * a boolean. * @return never null * @throws org.eclipse.jgit.errors.InvalidPatternException */ public static IMatcher createPathMatcher(String pattern, Character pathSeparator, boolean dirOnly) throws InvalidPatternException { pattern = trim(pattern); char slash = Strings.getPathSeparator(pathSeparator); // ignore possible leading and trailing slash int slashIdx = pattern.indexOf(slash, 1); if (slashIdx > 0 && slashIdx < pattern.length() - 1) return new PathMatcher(pattern, pathSeparator, dirOnly); return createNameMatcher0(pattern, pathSeparator, dirOnly, true); }
int count = count(pattern, slash, true); if (count < 1) throw new IllegalStateException(
dirOnly = isDirectoryPattern(pattern); if (dirOnly) { pattern = stripTrailingWhitespace(pattern); pattern = stripTrailing(pattern, PATH_SEPARATOR); if (pattern.length() == 0) { this.matcher = NO_MATCH;
private PathMatcher(String pattern, Character pathSeparator, boolean dirOnly) throws InvalidPatternException { super(pattern, dirOnly); slash = getPathSeparator(pathSeparator); beginning = pattern.indexOf(slash) == 0; if (isSimplePathWithSegments(pattern)) matchers = null; else matchers = createMatchers(split(pattern, slash), pathSeparator, dirOnly); }
private boolean isSimplePathWithSegments(String path) { return !isWildCard(path) && path.indexOf('\\') < 0 && count(path, slash, true) > 0; }
NameMatcher(String pattern, Character pathSeparator, boolean dirOnly, boolean deleteBackslash) { super(pattern, dirOnly); slash = getPathSeparator(pathSeparator); if (deleteBackslash) { pattern = Strings.deleteBackslash(pattern); } beginning = pattern.length() == 0 ? false : pattern.charAt(0) == slash; if (!beginning) this.subPattern = pattern; else this.subPattern = pattern.substring(1); }
static PatternState checkWildCards(String pattern) { if (isComplexWildcard(pattern)) return PatternState.COMPLEX; int startIdx = pattern.indexOf('*'); if (startIdx < 0) return PatternState.NONE; if (startIdx == pattern.length() - 1) return PatternState.TRAILING_ASTERISK_ONLY; if (pattern.lastIndexOf('*') == 0) return PatternState.LEADING_ASTERISK_ONLY; return PatternState.COMPLEX; }
static String deleteBackslash(String s) { if (s.indexOf('\\') < 0) { return s; } StringBuilder sb = new StringBuilder(s.length()); for (int i = 0; i < s.length(); i++) { char ch = s.charAt(i); if (ch == '\\') { if (i + 1 == s.length()) { continue; } char next = s.charAt(i + 1); if (next == '\\') { sb.append(ch); i++; continue; } if (!escapedByBackslash(next)) { continue; } } sb.append(ch); } return sb.toString(); }
/** * * @param pattern * @param pathSeparator * if this parameter isn't null then this character will not * match at wildcards(* and ? are wildcards). * @param dirOnly * @return never null * @throws InvalidPatternException */ public static IMatcher createPathMatcher(String pattern, Character pathSeparator, boolean dirOnly) throws InvalidPatternException { pattern = trim(pattern); char slash = Strings.getPathSeparator(pathSeparator); // ignore possible leading and trailing slash int slashIdx = pattern.indexOf(slash, 1); if (slashIdx > 0 && slashIdx < pattern.length() - 1) return new PathMatcher(pattern, pathSeparator, dirOnly); return createNameMatcher0(pattern, pathSeparator, dirOnly); }
int count = count(pattern, slash, true); if (count < 1) throw new IllegalStateException(
if (lookBehind(sb) == '[' && isLetter(lookAhead(pattern, i))) in_char_class = true; sb.append(':'); if (lookAhead(pattern, i) == ']') sb.append('\\').append(c); else char lookAhead = lookAhead(pattern, i); if (lookAhead == ']' || lookAhead == '[') ignoreLastBracket = true; } else { char lookAhead = lookAhead(pattern, i); if (lookAhead != '\\' && lookAhead != '[' && lookAhead != '?' && lookAhead != '*' && lookAhead != ' ' && lookBehind(sb) != '\\') { break; char lookBehind = lookBehind(sb); if ((lookBehind == '[' && !ignoreLastBracket) || lookBehind == '^') { } else { in_char_class = false; String charCl = checkPosixCharClass(charClass); reset(charClass);