Package org.eclipse.jgit.fnmatch
Class FileNameMatcher
java.lang.Object
org.eclipse.jgit.fnmatch.FileNameMatcher
This class can be used to match filenames against fnmatch like patterns. It
is not thread save.
Supported are the wildcard characters * and ? and groups with:
- characters e.g. [abc]
- ranges e.g. [a-z]
- the following character classes
- [:alnum:]
- [:alpha:]
- [:blank:]
- [:cntrl:]
- [:digit:]
- [:graph:]
- [:lower:]
- [:print:]
- [:punct:]
- [:space:]
- [:upper:]
- [:word:]
- [:xdigit:]
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Pattern
{extendStringToMatchByOneCharacter(char)
needs a list for the new heads, allocating a new array would be bad for the performance, as the method gets called very often. -
Constructor Summary
ConstructorsModifierConstructorDescriptionFileNameMatcher
(String patternString, Character invalidWildgetCharacter) Constructor for FileNameMatcherprivate
FileNameMatcher
(List<Head> headsStartValue) private
FileNameMatcher
(List<Head> headsStartValue, List<Head> heads) FileNameMatcher
(FileNameMatcher other) A Copy Constructor which creates a newFileNameMatcher
with the same state and reset point likeother
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Append to the string which is matched against the patterns of this classboolean
Whether a match can be appendedcreateHeadsStartValues
(String patternString, Character invalidWildgetCharacter) Create aFileNameMatcher
instance which uses the same pattern like this matcher, but has the current state of this matcher as reset and start pointprivate static List<AbstractHead>
createSimpleHeads
(String patternPart, Character invalidWildgetCharacter) private static AbstractHead
createWildCardHead
(Character invalidWildgetCharacter, boolean star) private boolean
private static int
findGroupEnd
(int indexOfStartBracket, String pattern) private static int
indexOfUnescaped
(String searchString, char ch, int fromIndex) boolean
isMatch()
Whether the matcher matchesprivate static List<AbstractHead>
parseHeads
(String pattern, Character invalidWildgetCharacter) void
reset()
Resets this matcher to it's state right after construction.
-
Field Details
-
EMPTY_HEAD_LIST
-
characterClassStartPattern
-
headsStartValue
-
heads
-
listForLocalUseage
{extendStringToMatchByOneCharacter(char)
needs a list for the new heads, allocating a new array would be bad for the performance, as the method gets called very often.
-
-
Constructor Details
-
FileNameMatcher
- Parameters:
headsStartValue
- must be a list which will never be modified.
-
FileNameMatcher
- Parameters:
headsStartValue
- must be a list which will never be modified.heads
- a list which will be cloned and then used as current head list.
-
FileNameMatcher
public FileNameMatcher(String patternString, Character invalidWildgetCharacter) throws InvalidPatternException Constructor for FileNameMatcher- Parameters:
patternString
- must contain a pattern which fnmatch would accept.invalidWildgetCharacter
- if this parameter isn't null then this character will not match at wildcards(* and ? are wildcards).- Throws:
InvalidPatternException
- if the patternString contains a invalid fnmatch pattern.
-
FileNameMatcher
A Copy Constructor which creates a newFileNameMatcher
with the same state and reset point likeother
.- Parameters:
other
- anotherFileNameMatcher
instance.
-
-
Method Details
-
createHeadsStartValues
private static List<Head> createHeadsStartValues(String patternString, Character invalidWildgetCharacter) throws InvalidPatternException - Throws:
InvalidPatternException
-
findGroupEnd
private static int findGroupEnd(int indexOfStartBracket, String pattern) throws InvalidPatternException - Throws:
InvalidPatternException
-
parseHeads
private static List<AbstractHead> parseHeads(String pattern, Character invalidWildgetCharacter) throws InvalidPatternException - Throws:
InvalidPatternException
-
createSimpleHeads
private static List<AbstractHead> createSimpleHeads(String patternPart, Character invalidWildgetCharacter) -
createWildCardHead
-
extendStringToMatchByOneCharacter
private boolean extendStringToMatchByOneCharacter(char c) - Parameters:
c
- new character to append- Returns:
- true to continue, false if the matcher can stop appending
-
indexOfUnescaped
-
append
Append to the string which is matched against the patterns of this class- Parameters:
stringToMatch
- extends the string which is matched against the patterns of this class.
-
reset
public void reset()Resets this matcher to it's state right after construction. -
createMatcherForSuffix
Create aFileNameMatcher
instance which uses the same pattern like this matcher, but has the current state of this matcher as reset and start point- Returns:
- a
FileNameMatcher
instance which uses the same pattern like this matcher, but has the current state of this matcher as reset and start point.
-
isMatch
public boolean isMatch()Whether the matcher matches- Returns:
- whether the matcher matches
-
canAppendMatch
public boolean canAppendMatch()Whether a match can be appended- Returns:
- a boolean.
-