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;
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations