|
|||||||||
| Home >> All >> org >> apache >> oro >> [ text overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.oro.text
Class GlobCompiler

java.lang.Objectorg.apache.oro.text.GlobCompiler
- All Implemented Interfaces:
- org.apache.oro.text.regex.PatternCompiler
- public final class GlobCompiler
- extends java.lang.Object
- implements org.apache.oro.text.regex.PatternCompiler
- extends java.lang.Object
The GlobCompiler class will compile a glob expression into a Perl5Pattern that may be used to match patterns in conjunction with Perl5Matcher. Rather than create extra GlobMatcher and GlobPattern classes tailored to the task of matching glob expressions, we have simply reused the Perl5 regular expression classes from org.apache.oro.text.regex by making GlobCompiler translate a glob expression into a Perl5 expression that is compiled by a Perl5Compiler instance internal to the GlobCompiler.
Because there are various similar glob expression syntaxes, GlobCompiler
tries to provide a small amount of customization by providing the
STAR_CANNOT_MATCH_NULL_MASK 55
and QUESTION_MATCHES_ZERO_OR_ONE_MASK 55 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:
- * - Matches zero or more instances of any character. If the STAR_CANNOT_MATCH_NULL_MASK option is used, * matches one or more instances of any character.
- ? - Matches one instance of any character. If the QUESTION_MATCHES_ZERO_OR_ONE_MASK option is used, ? matches zero or one instances of any character.
- [...] - Matches any of characters enclosed by the brackets. * and ? lose their special meanings within a character class. Additionaly if the first character following the opening bracket is a ! or a ^, then any character not in the character class is matched. A - between two characters can be used to denote a range. A - at the beginning or end of the character class matches itself rather than referring to a range. A ] immediately following the opening [ matches itself rather than indicating the end of the character class, otherwise it must be escaped with a backslash to refer to itself.
- \ - A backslash matches itself in most situations. But when a special character such as a * follows it, a backslash escapes the character, indicating that the special chracter should be interpreted as a normal character instead of its special meaning.
- All other characters match themselves.
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:
- @version@
| Field Summary | |
private org.apache.oro.text.regex.Perl5Compiler |
__perl5Compiler
|
static int |
CASE_INSENSITIVE_MASK
A mask passed as an option to the compile 55 methods to indicate a compiled glob expression should be case insensitive. |
static int |
DEFAULT_MASK
The default mask for the compile 55 methods. |
static int |
QUESTION_MATCHES_ZERO_OR_ONE_MASK
A mask passed as an option to the compile 55 methods to indicate that a ? should not be allowed to match the null string. |
static int |
READ_ONLY_MASK
A mask passed as an option to the compile 55 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 compile 55 methods to indicate that a * should not be allowed to match the null string. |
| Constructor Summary | |
GlobCompiler()
The default GlobCompiler constructor. |
|
| Method Summary | |
private static boolean |
__isGlobMetaCharacter(char ch)
|
private static boolean |
__isPerl5MetaCharacter(char ch)
|
org.apache.oro.text.regex.Pattern |
compile(char[] pattern)
Same as calling compile(pattern, GlobCompiler.DEFAULT_MASK); |
org.apache.oro.text.regex.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. |
org.apache.oro.text.regex.Pattern |
compile(java.lang.String pattern)
Same as calling compile(pattern, GlobCompiler.DEFAULT_MASK); |
org.apache.oro.text.regex.Pattern |
compile(java.lang.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 java.lang.String |
globToPerl5(char[] pattern,
int options)
This static method is the basic engine of the Glob PatternCompiler implementation. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
DEFAULT_MASK
public static final int DEFAULT_MASK
- The default mask for the compile 55 methods.
It is equal to 0. The default behavior is for a glob expression to
be case sensitive unless it is compiled with the CASE_INSENSITIVE_MASK
option.
- See Also:
- Constant Field Values
CASE_INSENSITIVE_MASK
public static final int CASE_INSENSITIVE_MASK
- A mask passed as an option to the compile 55 methods
to indicate a compiled glob expression should be case insensitive.
- See Also:
- Constant Field Values
STAR_CANNOT_MATCH_NULL_MASK
public static final int STAR_CANNOT_MATCH_NULL_MASK
- A mask passed as an option to the compile 55 methods
to indicate that a * should not be allowed to match the null string.
The normal behavior of the * metacharacter is that it may match any
0 or more characters. This mask causes it to match 1 or more
characters of anything.
- See Also:
- Constant Field Values
QUESTION_MATCHES_ZERO_OR_ONE_MASK
public static final int QUESTION_MATCHES_ZERO_OR_ONE_MASK
- A mask passed as an option to the compile 55 methods
to indicate that a ? should not be allowed to match the null string.
The normal behavior of the ? metacharacter is that it may match any 1
character. This mask causes it to match 0 or 1 characters.
- See Also:
- Constant Field Values
READ_ONLY_MASK
public static final int READ_ONLY_MASK
- A mask passed as an option to the compile 55 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. Without this option, Perl5Matcher reserves the right
to store heuristic or other information in Perl5Pattern that might
accelerate future matches. When you use this option, Perl5Matcher will
not store or modify any information in a Perl5Pattern. Use this option
when you want to share a Perl5Pattern instance among multiple threads
using different Perl5Matcher instances.
- See Also:
- Constant Field Values
__perl5Compiler
private org.apache.oro.text.regex.Perl5Compiler __perl5Compiler
| Constructor Detail |
GlobCompiler
public GlobCompiler()
- The default GlobCompiler constructor. It initializes an internal
Perl5Compiler instance to compile translated glob expressions.
| Method Detail |
__isPerl5MetaCharacter
private static boolean __isPerl5MetaCharacter(char ch)
__isGlobMetaCharacter
private static boolean __isGlobMetaCharacter(char ch)
globToPerl5
public static java.lang.String globToPerl5(char[] pattern, int options)
- This static method is the basic engine of the Glob PatternCompiler
implementation. It takes a glob expression in the form of a character
array and converts it into a String representation of a Perl5 pattern.
The method is made public so that programmers may use it for their
own purposes. However, the GlobCompiler compile methods work by
converting the glob pattern to a Perl5 pattern using this method, and
then invoking the compile() method of an internally stored Perl5Compiler
instance.
compile
public org.apache.oro.text.regex.Pattern compile(char[] pattern, int options) throws org.apache.oro.text.regex.MalformedPatternException
- Compiles a Glob expression into a Perl5Pattern instance that
can be used by a Perl5Matcher object to perform pattern matching.
- Specified by:
compilein interfaceorg.apache.oro.text.regex.PatternCompiler
compile
public org.apache.oro.text.regex.Pattern compile(char[] pattern) throws org.apache.oro.text.regex.MalformedPatternException
- Same as calling compile(pattern, GlobCompiler.DEFAULT_MASK);
- Specified by:
compilein interfaceorg.apache.oro.text.regex.PatternCompiler
compile
public org.apache.oro.text.regex.Pattern compile(java.lang.String pattern) throws org.apache.oro.text.regex.MalformedPatternException
- Same as calling compile(pattern, GlobCompiler.DEFAULT_MASK);
- Specified by:
compilein interfaceorg.apache.oro.text.regex.PatternCompiler
compile
public org.apache.oro.text.regex.Pattern compile(java.lang.String pattern, int options) throws org.apache.oro.text.regex.MalformedPatternException
- Compiles a Glob expression into a Perl5Pattern instance that
can be used by a Perl5Matcher object to perform pattern matching.
- Specified by:
compilein interfaceorg.apache.oro.text.regex.PatternCompiler
|
|||||||||
| Home >> All >> org >> apache >> oro >> [ text overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.apache.oro.text.GlobCompiler