ORO, Inc. Logo  All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.oroinc.text.GlobCompiler

java.lang.Object
   |
   +----com.oroinc.text.GlobCompiler

public final class GlobCompiler
extends Object
implements PatternCompiler
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 com.oroinc.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 and 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.

Copyright © 1997 Original Resuable Objects, Inc. All rights reserved.

See Also:
PatternCompiler, Perl5Matcher

Variable Index

 o CASE_INSENSITIVE_MASK
A mask passed as an option to the compile methods to indicate a compiled glob expression should be case insensitive.
 o DEFAULT_MASK
The default mask for the compile methods.
 o QUESTION_MATCHES_ZERO_OR_ONE_MASK
A mask passed as an option to the compile methods to indicate that a ? should not be allowed to match the null string.
 o STAR_CANNOT_MATCH_NULL_MASK
A mask passed as an option to the compile methods to indicate that a * should not be allowed to match the null string.

Constructor Index

 o GlobCompiler()
The default GlobCompiler constructor.

Method Index

 o compile(char[])
Same as calling compile(pattern, GlobCompiler.DEFAULT_MASK);

 o compile(char[], int)
Compiles a Glob expression into a Perl5Pattern instance that can be used by a Perl5Matcher object to perform pattern matching.
 o compile(String)
Same as calling compile(pattern, GlobCompiler.DEFAULT_MASK);

 o compile(String, int)
Compiles a Glob expression into a Perl5Pattern instance that can be used by a Perl5Matcher object to perform pattern matching.
 o globToPerl5(char[], int)
This static method is the basic engine of the Glob PatternCompiler implementation.

Variables

 o DEFAULT_MASK
 public static final int DEFAULT_MASK
The default mask for the compile 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.

 o CASE_INSENSITIVE_MASK
 public static final int CASE_INSENSITIVE_MASK
A mask passed as an option to the compile methods to indicate a compiled glob expression should be case insensitive.

 o STAR_CANNOT_MATCH_NULL_MASK
 public static final int STAR_CANNOT_MATCH_NULL_MASK
A mask passed as an option to the compile 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.

 o 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 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.

Constructors

 o GlobCompiler
 public GlobCompiler()
The default GlobCompiler constructor. It initializes an internal Perl5Compiler instance to compile translated glob expressions.

Methods

 o globToPerl5
 public static 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.

Parameters:
pattern - A character array representation of a Glob pattern.
Returns:
A String representation of a Perl5 pattern equivalent to the Glob pattern.
 o compile
 public Pattern compile(char pattern[],
                        int options) throws MalformedPatternException
Compiles a Glob expression into a Perl5Pattern instance that can be used by a Perl5Matcher object to perform pattern matching.

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.
 o compile
 public Pattern compile(char pattern[]) throws MalformedPatternException
Same as calling compile(pattern, GlobCompiler.DEFAULT_MASK);

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.
 o compile
 public Pattern compile(String pattern) throws MalformedPatternException
Same as calling compile(pattern, GlobCompiler.DEFAULT_MASK);

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.
 o compile
 public Pattern compile(String pattern,
                        int options) throws MalformedPatternException
Compiles a Glob expression into a Perl5Pattern instance that can be used by a Perl5Matcher object to perform pattern matching.

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.

ORO, Inc. Logo  All Packages  Class Hierarchy  This Package  Previous  Next  Index