Package com.google.common.jimfs
Class GlobToRegex
java.lang.Object
com.google.common.jimfs.GlobToRegex
Translates globs to regex patterns.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final GlobToRegex.State
State inside [brackets], but not at the first character inside the brackets.private static final GlobToRegex.State
State immediately following the reading of a [.private final StringBuilder
private static final GlobToRegex.State
State inside {curly braces}.private static final GlobToRegex.State
State following the reading of a single \.private final String
private int
private static final GlobToRegex.State
Normal state.private static final InternalCharMatcher
private final InternalCharMatcher
private final String
private static final GlobToRegex.State
State following the reading of a single *.private final Deque
<GlobToRegex.State> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
append
(char c) Appends the regex form of the given normal character or separator from the glob.private void
Appends the regex form of the end of a glob [] section.private void
Appends the regex form of the start of a glob [] section.private void
Appends the regex form of the end of a glob {} section.private void
Appends the regex form of the start of a glob {} section.private void
appendExact
(char c) Appends the given character as-is to the regex.private void
appendInBracket
(char c) Appends the regex form of the given character within a glob [] section.private void
Appends the regex form that matches anything except the separators for the path type.private void
appendNormal
(char c) Appends the regex form of the given normal character from the glob.private void
Appends the regex form of the glob ? character.private void
Appends the regex form matching the separators for the path type.private void
Appends the regex form of the glob * character.private void
Appends the regex form of the glob ** pattern.private void
Appends the regex form of the separator (,) within a glob {} section.private String
convert()
Converts the glob to a regex one character at a time.private GlobToRegex.State
Returns the current state.private void
popState()
Returns to the previous state.private void
pushState
(GlobToRegex.State state) Enters the given state.private PatternSyntaxException
syntaxError
(String desc) Throws aPatternSyntaxException
.static String
Converts the given glob to a regular expression pattern.
-
Field Details
-
REGEX_RESERVED
-
glob
-
separators
-
separatorMatcher
-
builder
-
states
-
index
private int index -
NORMAL
Normal state. -
ESCAPE
State following the reading of a single \. -
STAR
State following the reading of a single *. -
BRACKET_FIRST_CHAR
State immediately following the reading of a [. -
BRACKET
State inside [brackets], but not at the first character inside the brackets. -
CURLY_BRACE
State inside {curly braces}.
-
-
Constructor Details
-
GlobToRegex
-
-
Method Details
-
toRegex
Converts the given glob to a regular expression pattern. The given separators determine what characters the resulting expression breaks on for glob expressions such as * which should not cross directory boundaries.Basic conversions (assuming / as only separator):
? = [^/] * = [^/]* ** = .* [a-z] = [[^/]&&[a-z]] [!a-z] = [[^/]&&[^a-z]] {a,b,c} = (a|b|c)
-
convert
Converts the glob to a regex one character at a time. A state stack (states) is maintained, with the state at the top of the stack being the current state at any given time. The current state is always used to process the next character. When a state processes a character, it may pop the current state or push a new state as the current state. The resulting regex is written tobuilder
. -
pushState
Enters the given state. The current state becomes the previous state. -
popState
private void popState()Returns to the previous state. -
currentState
Returns the current state. -
syntaxError
Throws aPatternSyntaxException
. -
appendExact
private void appendExact(char c) Appends the given character as-is to the regex. -
append
private void append(char c) Appends the regex form of the given normal character or separator from the glob. -
appendNormal
private void appendNormal(char c) Appends the regex form of the given normal character from the glob. -
appendSeparator
private void appendSeparator()Appends the regex form matching the separators for the path type. -
appendNonSeparator
private void appendNonSeparator()Appends the regex form that matches anything except the separators for the path type. -
appendQuestionMark
private void appendQuestionMark()Appends the regex form of the glob ? character. -
appendStar
private void appendStar()Appends the regex form of the glob * character. -
appendStarStar
private void appendStarStar()Appends the regex form of the glob ** pattern. -
appendBracketStart
private void appendBracketStart()Appends the regex form of the start of a glob [] section. -
appendBracketEnd
private void appendBracketEnd()Appends the regex form of the end of a glob [] section. -
appendInBracket
private void appendInBracket(char c) Appends the regex form of the given character within a glob [] section. -
appendCurlyBraceStart
private void appendCurlyBraceStart()Appends the regex form of the start of a glob {} section. -
appendSubpatternSeparator
private void appendSubpatternSeparator()Appends the regex form of the separator (,) within a glob {} section. -
appendCurlyBraceEnd
private void appendCurlyBraceEnd()Appends the regex form of the end of a glob {} section.
-