org.apache.oro.text
public final class GlobCompiler extends Object implements PatternCompiler
Because there are various similar glob expression syntaxes, GlobCompiler tries to provide a small amount of customization by providing the {@link #STAR_CANNOT_MATCH_NULL_MASK} and {@link #QUESTION_MATCHES_ZERO_OR_ONE_MASK} compilation options.
The GlobCompiler expression syntax is based on Unix shell glob expressions but should be usable to simulate Win32 wildcards. The following syntax is supported:
Please remember that the when you construct a Java string in Java code, the backslash character is itself a special Java character, and it must be double backslashed to represent single backslash in a regular expression.
Since: 1.0
Version: 2.0.8
See Also: PatternCompiler Perl5Matcher
Field Summary | |
---|---|
static int | CASE_INSENSITIVE_MASK
A mask passed as an option to the {@link #compile compile} methods
to indicate a compiled glob expression should be case insensitive. |
static int | DEFAULT_MASK
The default mask for the {@link #compile compile} methods.
|
static int | QUESTION_MATCHES_ZERO_OR_ONE_MASK
A mask passed as an option to the {@link #compile compile} methods
to indicate that a ? |
static int | READ_ONLY_MASK
A mask passed as an option to the {@link #compile compile} methods
to indicate that the resulting Perl5Pattern should be treated as a
read only data structure by Perl5Matcher, making it safe to share
a single Perl5Pattern instance among multiple threads without needing
synchronization. |
static int | STAR_CANNOT_MATCH_NULL_MASK
A mask passed as an option to the {@link #compile compile} methods
to indicate that a * should not be allowed to match the null string.
|
Constructor Summary | |
---|---|
GlobCompiler()
The default GlobCompiler constructor. |
Method Summary | |
---|---|
Pattern | compile(char[] pattern, int options)
Compiles a Glob expression into a Perl5Pattern instance that
can be used by a Perl5Matcher object to perform pattern matching.
|
Pattern | compile(char[] pattern)
Same as calling compile(pattern, GlobCompiler.DEFAULT_MASK);
|
Pattern | compile(String pattern)
Same as calling compile(pattern, GlobCompiler.DEFAULT_MASK);
|
Pattern | compile(String pattern, int options)
Compiles a Glob expression into a Perl5Pattern instance that
can be used by a Perl5Matcher object to perform pattern matching.
|
static String | globToPerl5(char[] pattern, int options)
This static method is the basic engine of the Glob PatternCompiler
implementation. |
Parameters: pattern A Glob expression to compile. options A set of flags giving the compiler instructions on
how to treat the glob expression. The flags
are a logical OR of any number of the 3 MASK
constants. For example:
regex =
compiler.compile(pattern, GlobCompiler.
CASE_INSENSITIVE_MASK |
GlobCompiler.STAR_CANNOT_MATCH_NULL_MASK);
This says to compile the pattern so that *
cannot match the null string and to perform
matches in a case insensitive manner.
Returns: A Pattern instance constituting the compiled expression. This instance will always be a Perl5Pattern and can be reliably casted to a Perl5Pattern.
Throws: MalformedPatternException If the compiled expression is not a valid Glob expression.
Parameters: pattern A regular expression to compile.
Returns: A Pattern instance constituting the compiled regular expression. This instance will always be a Perl5Pattern and can be reliably casted to a Perl5Pattern.
Throws: MalformedPatternException If the compiled expression is not a valid Glob expression.
Parameters: pattern A regular expression to compile.
Returns: A Pattern instance constituting the compiled regular expression. This instance will always be a Perl5Pattern and can be reliably casted to a Perl5Pattern.
Throws: MalformedPatternException If the compiled expression is not a valid Glob expression.
Parameters: pattern A Glob expression to compile. options A set of flags giving the compiler instructions on
how to treat the glob expression. The flags
are a logical OR of any number of the 3 MASK
constants. For example:
regex =
compiler.compile("*.*", GlobCompiler.
CASE_INSENSITIVE_MASK |
GlobCompiler.STAR_CANNOT_MATCH_NULL_MASK);
This says to compile the pattern so that *
cannot match the null string and to perform
matches in a case insensitive manner.
Returns: A Pattern instance constituting the compiled expression. This instance will always be a Perl5Pattern and can be reliably casted to a Perl5Pattern.
Throws: MalformedPatternException If the compiled expression is not a valid Glob expression.
Parameters: pattern A character array representation of a Glob pattern.
Returns: A String representation of a Perl5 pattern equivalent to the Glob pattern.