FileDocCategorySizeDatePackage
JakartaRegexpMatcher.javaAPI DocApache Ant 1.704925Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.util.regexp

JakartaRegexpMatcher

public class JakartaRegexpMatcher extends Object implements RegexpMatcher
Implementation of RegexpMatcher for Jakarta-Regexp.

Fields Summary
private String
pattern
Constructors Summary
Methods Summary
protected org.apache.regexp.REgetCompiledPattern(int options)
Compile the pattern.

param
options the ant regexp options
return
a compiled pattern
exception
BuildException if an error occurs

        int cOptions = getCompilerOptions(options);
        try {
            RE reg = new RE(pattern);
            reg.setMatchFlags(cOptions);
            return reg;
        } catch (RESyntaxException e) {
            throw new BuildException(e);
        }
    
protected intgetCompilerOptions(int options)
Convert the generic options to the regex compiler specific options.

param
options the generic options
return
the specific options

        int cOptions = RE.MATCH_NORMAL;

        if (RegexpUtil.hasFlag(options, MATCH_CASE_INSENSITIVE)) {
            cOptions |= RE.MATCH_CASEINDEPENDENT;
        }
        if (RegexpUtil.hasFlag(options, MATCH_MULTILINE)) {
            cOptions |= RE.MATCH_MULTILINE;
        }
        if (RegexpUtil.hasFlag(options, MATCH_SINGLELINE)) {
            cOptions |= RE.MATCH_SINGLELINE;
        }

        return cOptions;
    
public java.util.VectorgetGroups(java.lang.String argument)
Returns a Vector of matched groups found in the argument using default options.

Group 0 will be the full match, the rest are the parenthesized subexpressions

.

param
argument the string to match against
return
the vector of groups
throws
BuildException on error

        return getGroups(argument, MATCH_DEFAULT);
    
public java.util.VectorgetGroups(java.lang.String input, int options)
Returns a Vector of matched groups found in the argument.

Group 0 will be the full match, the rest are the parenthesized subexpressions

.

param
input the string to match against
param
options the regex options to use
return
the vector of groups
throws
BuildException on error

        RE reg = getCompiledPattern(options);
        if (!matches(input, reg)) {
            return null;
        }
        Vector v = new Vector();
        int cnt = reg.getParenCount();
        for (int i = 0; i < cnt; i++) {
            String match = reg.getParen(i);
            // treat non-matching groups as empty matches
            if (match == null) {
                match = "";
            }
            v.addElement(match);
        }
        return v;
    
public java.lang.StringgetPattern()
Get a String representation of the regexp pattern

return
the pattern

        return pattern;
    
public booleanmatches(java.lang.String argument)
Does the given argument match the pattern?

param
argument the string to match against
return
true if the pattern matches
throws
BuildException on error

        return matches(argument, MATCH_DEFAULT);
    
public booleanmatches(java.lang.String input, int options)
Does the given argument match the pattern?

param
input the string to match against
param
options the regex options to use
return
true if the pattern matches
throws
BuildException on error

        return matches(input, getCompiledPattern(options));
    
private booleanmatches(java.lang.String input, org.apache.regexp.RE reg)

        return reg.match(input);
    
public voidsetPattern(java.lang.String pattern)
Set the regexp pattern from the String description.

param
pattern the pattern to match

        this.pattern = pattern;