| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.functions; |
| 9 |
|
| 10 |
import net.sf.saxon.Configuration; |
| 11 |
import net.sf.saxon.expr.XPathContext; |
| 12 |
import net.sf.saxon.om.Sequence; |
| 13 |
import net.sf.saxon.regex.RegularExpression; |
| 14 |
import net.sf.saxon.trans.XPathException; |
| 15 |
import net.sf.saxon.value.AtomicValue; |
| 16 |
import net.sf.saxon.value.BooleanValue; |
| 17 |
import net.sf.saxon.value.StringValue; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public class Matches extends RegexFunction { |
| 25 |
|
| 26 |
protected boolean allowRegexMatchingEmptyString() { |
| 27 |
return true; |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public boolean evalMatches(AtomicValue input, AtomicValue regex, CharSequence flags, XPathContext context) throws XPathException { |
| 42 |
RegularExpression re; |
| 43 |
|
| 44 |
if (regex == null) { |
| 45 |
return false; |
| 46 |
} |
| 47 |
|
| 48 |
try { |
| 49 |
String lang = "XP30"; |
| 50 |
if (context.getConfiguration().getXsdVersion() == Configuration.XSD11) { |
| 51 |
lang += "/XSD11"; |
| 52 |
} |
| 53 |
re = context.getConfiguration().compileRegularExpression( |
| 54 |
regex.getStringValueCS(), flags.toString(), lang, null); |
| 55 |
|
| 56 |
} catch (XPathException err) { |
| 57 |
XPathException de = new XPathException(err); |
| 58 |
de.maybeSetErrorCode("FORX0002"); |
| 59 |
de.setXPathContext(context); |
| 60 |
throw de; |
| 61 |
} |
| 62 |
return re.containsMatch(input.getStringValueCS()); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public BooleanValue call(XPathContext context, Sequence[] arguments) throws XPathException { |
| 75 |
RegularExpression re = getRegularExpression(arguments); |
| 76 |
StringValue arg = (StringValue)arguments[0].head(); |
| 77 |
CharSequence in = arg==null ? "" : arg.getStringValueCS(); |
| 78 |
boolean result = re.containsMatch(in); |
| 79 |
return BooleanValue.get(result); |
| 80 |
} |
| 81 |
|
| 82 |
public String getCompilerName() { |
| 83 |
return "MatchesCompiler"; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
} |
| 88 |
|