Package com.ms.util Previous
Previous
Contents
Contents
Index
Index
Next
Next

Class WildcardExpression

Constructors , Methods

public class WildcardExpression implements java.io.FilenameFilter {
  // Constructors
  public WildcardExpression (String expr)
  public WildcardExpression ()
  public WildcardExpression (String expr, boolean escape, boolean ignoresep, boolean extended, boolean casesensitive)
  // Methods
  public synchronized boolean compile (String expr, boolean escape, boolean ignoresep, boolean extended, boolean casesensitive)
  public void disassemble (java.io.PrintStream o)
  public String toString ()
  public boolean match (String s)
  public int matchex (String s)
  public int resume (String s)
  public static int matchOne (WildcardExpression[] exprs, String s)
  public boolean accept (java.io.File dir, String name)
  public boolean equals (Object obj)
}

This class implements wildcard expression matching. For performance, nothing in this class is synchronized. The typical use is that an expression is compiled once (by the constructor). Compile is the only operation that modifies the state of the expression and should be synchronized with the other operations by the caller.


Constructors


WildcardExpression

public WildcardExpression (String expr)

Creates an expression following the typical wildcard convention.


WildcardExpression

public WildcardExpression ()

Creates an empty expression. An expression must be compiled before matches can be made.

See Also: compile


WildcardExpression

public WildcardExpression (String expr, boolean escape, boolean ignoresep, boolean extended, boolean casesensitive)

Creates an expression using the extended form.

See Also: compile


Methods


accept

public boolean accept (java.io.File dir, String name)

Finds files that match a wildcard string in a directory.

Return Value:

Returns a boolean value indicating whether the wildcard matches any file in the directory.

ParameterDescription
dir The file directory to search.
name The wildcard expression to match.


compile

public synchronized boolean compile (String expr, boolean escape, boolean ignoresep, boolean extended, boolean casesensitive)

Compiles the expression for faster evaluation. The previously compiled expression is lost.

Return Value:

Returns true if the expression was compiled.

ParameterDescription
expr Expression to compile.
escape Allow escaped wildcards in expression (for example, \*).
ignoresep ? and * ignore path separators.
extended Extended syntax
*
Matches up to a / or \.
*+
Matches anything.
?
Matches single character, excluding a \ or /.

With ignoresep, * and *+ are synonymous and ? will match a \ or /.

casesensitive Do case-sensitive matching if true.

See Also: match


disassemble

public void disassemble (java.io.PrintStream o)

Displays the compiled expression code in human-readable form.

ParameterDescription
o Stream to print the compiled expression to.


equals

public boolean equals (Object obj)

Compares wildcard expressions.

Return Value:

Returns true if the parameter is a wildcard expression and matches this class's compiled expression; otherwise it returns false.

ParameterDescription
obj Wildcard expression to compare.


match

public boolean match (String s)

Evaluates the expression on the string.

Return Value:

Returns true if the expression accepts the string


matchex

public int matchex (String s)

Evaluates the expression on the string.

Return Value:

Returns subexpression number if the expression accepts the string, else -1 if the string was not accepted .


matchOne

public static int matchOne (WildcardExpression[] exprs, String s)

Evaluates a list of expressions on a string.

Return Value:

Returns index of the expression that matched, else -1.

ParameterDescription
exprs List of expressions.
s String to evaluate expressions on.


resume

public int resume (String s)

Resumes a previous match that stopped at a subexpression.


toString

public String toString ()

Reconstructs the original expression in extended, non-escaped form. Case-insensitive expressions are reconstituted in lower case.

Return Value:

Returns the original expression.



Top© 1997 Microsoft Corporation. All rights reserved. Legal Notices.