Search in sources :

Example 1 with RE

use of org.apache.regexp.RE in project ant by apache.

the class JakartaRegexpMatcher method getGroups.

/**
 * Returns a Vector of matched groups found in the argument.
 *
 * <p>Group 0 will be the full match, the rest are the
 * parenthesized subexpressions</p>.
 *
 * @param input the string to match against
 * @param options the regex options to use
 * @return the vector of groups
 * @throws BuildException on error
 */
@Override
public Vector<String> getGroups(String input, int options) throws BuildException {
    RE reg = getCompiledPattern(options);
    if (!matches(input, reg)) {
        return null;
    }
    Vector<String> 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.add(match);
    }
    return v;
}
Also used : RE(org.apache.regexp.RE) Vector(java.util.Vector)

Example 2 with RE

use of org.apache.regexp.RE in project ant by apache.

the class JakartaRegexpMatcher method getCompiledPattern.

/**
 * Compile the pattern.
 *
 * @param options the ant regexp options
 * @return a compiled pattern
 * @exception BuildException if an error occurs
 */
protected RE getCompiledPattern(int options) throws BuildException {
    int cOptions = getCompilerOptions(options);
    try {
        RE reg = new RE(pattern);
        reg.setMatchFlags(cOptions);
        return reg;
    } catch (RESyntaxException e) {
        throw new BuildException(e);
    }
}
Also used : RE(org.apache.regexp.RE) BuildException(org.apache.tools.ant.BuildException) RESyntaxException(org.apache.regexp.RESyntaxException)

Example 3 with RE

use of org.apache.regexp.RE in project ant by apache.

the class JakartaRegexpRegexp method substitute.

/**
 * Perform a substitution on the regular expression.
 * @param input The string to substitute on
 * @param argument The string which defines the substitution
 * @param options The list of options for the match and replace.
 * @return the result of the operation
 * @throws BuildException on error
 */
@Override
public String substitute(String input, String argument, int options) throws BuildException {
    Vector<String> v = getGroups(input, options);
    // replace \1 with the corresponding group
    StringBuilder result = new StringBuilder();
    for (int i = 0; i < argument.length(); i++) {
        char c = argument.charAt(i);
        if (c == '\\') {
            if (++i < argument.length()) {
                c = argument.charAt(i);
                int value = Character.digit(c, DECIMAL);
                if (value > -1) {
                    result.append(v.elementAt(value));
                } else {
                    result.append(c);
                }
            } else {
                // TODO - should throw an exception instead?
                result.append('\\');
            }
        } else {
            result.append(c);
        }
    }
    RE reg = getCompiledPattern(options);
    int sOptions = getSubsOptions(options);
    return reg.subst(input, result.toString(), sOptions);
}
Also used : RE(org.apache.regexp.RE)

Example 4 with RE

use of org.apache.regexp.RE in project convertigo by convertigo.

the class GenericRequester method findBrowserFromUserAgent.

private String findBrowserFromUserAgent(Project project, String userAgent) {
    XMLVector<XMLVector<String>> browserDefinitions = project.getBrowserDefinitions();
    if (browserDefinitions != null) {
        int len = browserDefinitions.size();
        String keyword, browser;
        RE regexp;
        for (int i = 0; i < len; i++) {
            browser = browserDefinitions.get(i).get(0);
            keyword = browserDefinitions.get(i).get(1);
            try {
                regexp = REUtil.createRE(keyword);
                if (regexp.match(userAgent)) {
                    return browser;
                }
            } catch (Exception e) {
                Engine.logContext.error("Unable to parse keyword regular expression for browser \"" + browser + "\"", e);
            }
        }
    }
    return Sheet.BROWSER_ALL;
}
Also used : XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) RE(org.apache.regexp.RE) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 5 with RE

use of org.apache.regexp.RE in project convertigo by convertigo.

the class Record method setBorType.

/**
 * Setter for property borType.
 * @param borType New value of property borType.
 */
public void setBorType(String borType) throws RESyntaxException {
    borRE = new RE(borType);
    this.borType = borType;
}
Also used : RE(org.apache.regexp.RE)

Aggregations

RE (org.apache.regexp.RE)10 RESyntaxException (org.apache.regexp.RESyntaxException)4 EngineException (com.twinsoft.convertigo.engine.EngineException)2 IOException (java.io.IOException)2 FindString (com.twinsoft.convertigo.beans.common.FindString)1 XMLVector (com.twinsoft.convertigo.beans.common.XMLVector)1 DevicePool (com.twinsoft.util.DevicePool)1 Rectangle (java.awt.Rectangle)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 NoSuchElementException (java.util.NoSuchElementException)1 Vector (java.util.Vector)1 RepositoryException (javax.jcr.RepositoryException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 BuildException (org.apache.tools.ant.BuildException)1 JahiaException (org.jahia.exceptions.JahiaException)1 EvaluatorException (org.mozilla.javascript.EvaluatorException)1 JavaScriptException (org.mozilla.javascript.JavaScriptException)1