Package org.eclipse.jgit.ignore.internal
Class PathMatcher
- java.lang.Object
-
- org.eclipse.jgit.ignore.internal.AbstractMatcher
-
- org.eclipse.jgit.ignore.internal.PathMatcher
-
- All Implemented Interfaces:
IMatcher
public class PathMatcher extends AbstractMatcher
Matcher built by patterns consists of multiple path segments.This class is immutable and thread safe.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanbeginningprivate java.util.List<IMatcher>matchersprivate charslashprivate static WildMatcherWILD_NO_DIRECTORYprivate static WildMatcherWILD_ONLY_DIRECTORY-
Fields inherited from class org.eclipse.jgit.ignore.internal.AbstractMatcher
dirOnly, pattern
-
-
Constructor Summary
Constructors Modifier Constructor Description privatePathMatcher(java.lang.String pattern, java.lang.Character pathSeparator, boolean dirOnly)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.util.List<IMatcher>createMatchers(java.util.List<java.lang.String> segments, java.lang.Character pathSeparator, boolean dirOnly)private static IMatchercreateNameMatcher0(java.lang.String segment, java.lang.Character pathSeparator, boolean dirOnly, boolean lastSegment)static IMatchercreatePathMatcher(java.lang.String pattern, java.lang.Character pathSeparator, boolean dirOnly)Create path matcherprivate booleanisSimplePathWithSegments(java.lang.String path)private static booleanisWild(IMatcher matcher)private booleaniterate(java.lang.String path, int startIncl, int endExcl, boolean assumeDirectory, boolean pathMatch)private booleanmatches(int matcherIdx, java.lang.String path, int startIncl, int endExcl, boolean assumeDirectory, boolean pathMatch)booleanmatches(java.lang.String path, boolean assumeDirectory, boolean pathMatch)Matches entire given stringbooleanmatches(java.lang.String segment, int startIncl, int endExcl)Matches only part of given stringprivate booleansimpleMatch(java.lang.String path, boolean assumeDirectory, boolean pathMatch)private static java.lang.Stringtrim(java.lang.String pattern)Trim trailing spaces, unless they are escaped with backslash, see https://www.kernel.org/pub/software/scm/git/docs/gitignore.html-
Methods inherited from class org.eclipse.jgit.ignore.internal.AbstractMatcher
equals, hashCode, toString
-
-
-
-
Field Detail
-
WILD_NO_DIRECTORY
private static final WildMatcher WILD_NO_DIRECTORY
-
WILD_ONLY_DIRECTORY
private static final WildMatcher WILD_ONLY_DIRECTORY
-
matchers
private final java.util.List<IMatcher> matchers
-
slash
private final char slash
-
beginning
private final boolean beginning
-
-
Constructor Detail
-
PathMatcher
private PathMatcher(java.lang.String pattern, java.lang.Character pathSeparator, boolean dirOnly) throws InvalidPatternException- Throws:
InvalidPatternException
-
-
Method Detail
-
isSimplePathWithSegments
private boolean isSimplePathWithSegments(java.lang.String path)
-
createMatchers
private static java.util.List<IMatcher> createMatchers(java.util.List<java.lang.String> segments, java.lang.Character pathSeparator, boolean dirOnly) throws InvalidPatternException
- Throws:
InvalidPatternException
-
createPathMatcher
public static IMatcher createPathMatcher(java.lang.String pattern, java.lang.Character pathSeparator, boolean dirOnly) throws InvalidPatternException
Create path matcher- Parameters:
pattern- a patternpathSeparator- if this parameter isn't null then this character will not match at wildcards(* and ? are wildcards).dirOnly- a boolean.- Returns:
- never null
- Throws:
InvalidPatternException
-
trim
private static java.lang.String trim(java.lang.String pattern)
Trim trailing spaces, unless they are escaped with backslash, see https://www.kernel.org/pub/software/scm/git/docs/gitignore.html- Parameters:
pattern- non null- Returns:
- trimmed pattern
-
createNameMatcher0
private static IMatcher createNameMatcher0(java.lang.String segment, java.lang.Character pathSeparator, boolean dirOnly, boolean lastSegment) throws InvalidPatternException
- Throws:
InvalidPatternException
-
matches
public boolean matches(java.lang.String path, boolean assumeDirectory, boolean pathMatch)Matches entire given string- Parameters:
path- string which is not null, but might be emptyassumeDirectory- true to assume this path as directory (even if it doesn't end with a slash)pathMatch-trueif the match is for the full path: prefix-only matches are not allowed- Returns:
- true if this matcher pattern matches given string
-
simpleMatch
private boolean simpleMatch(java.lang.String path, boolean assumeDirectory, boolean pathMatch)
-
matches
public boolean matches(java.lang.String segment, int startIncl, int endExcl)Matches only part of given string- Parameters:
segment- string which is not null, but might be emptystartIncl- start index, inclusiveendExcl- end index, exclusive- Returns:
- true if this matcher pattern matches given string
-
iterate
private boolean iterate(java.lang.String path, int startIncl, int endExcl, boolean assumeDirectory, boolean pathMatch)
-
matches
private boolean matches(int matcherIdx, java.lang.String path, int startIncl, int endExcl, boolean assumeDirectory, boolean pathMatch)
-
isWild
private static boolean isWild(IMatcher matcher)
-
-