use of org.exist.thirdparty.net.sf.saxon.functions.regex.RegexSyntaxException in project exist by eXist-db.
the class RegexUtil method translateRegexp.
/**
* Translates the Regular Expression from XPath3 syntax to Java regex
* syntax.
*
* @param context the context expression - used for error reporting
* @param pattern a String containing a regular expression in the syntax of XPath Functions and Operators 3.0.
* @param ignoreWhitespace true if whitespace is to be ignored ('x' flag)
* @param caseBlind true if case is to be ignored ('i' flag)
*
* @return The Java Regular Expression
*
* @throws XPathException if the XQuery Regular Expression is invalid.
*/
public static String translateRegexp(final Expression context, final String pattern, final boolean ignoreWhitespace, final boolean caseBlind) throws XPathException {
// convert pattern to Java regex syntax
try {
final int options = RegularExpression.XML11 | RegularExpression.XPATH30;
int flagbits = 0;
if (ignoreWhitespace) {
flagbits |= Pattern.COMMENTS;
}
if (caseBlind) {
flagbits |= Pattern.CASE_INSENSITIVE;
}
final List<RegexSyntaxException> warnings = new ArrayList<>();
return JDK15RegexTranslator.translate(pattern, options, flagbits, warnings);
} catch (final RegexSyntaxException e) {
throw new XPathException(context, ErrorCodes.FORX0002, "Conversion from XPath F&O 3.0 regular expression syntax to Java regular expression syntax failed: " + e.getMessage(), new StringValue(pattern), e);
}
}
Aggregations