| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.functions; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.XPathContext; |
| 11 |
import net.sf.saxon.lib.SubstringMatcher; |
| 12 |
import net.sf.saxon.om.Sequence; |
| 13 |
import net.sf.saxon.trans.XPathException; |
| 14 |
import net.sf.saxon.value.StringValue; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
public class SubstringAfter extends CollatingFunctionFixed { |
| 20 |
|
| 21 |
@Override |
| 22 |
public boolean isSubstringMatchingFunction() { |
| 23 |
return true; |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException { |
| 36 |
StringValue arg1 = (StringValue) arguments[0].head(); |
| 37 |
StringValue arg2 = (StringValue) arguments[1].head(); |
| 38 |
return substringAfter(arg1, arg2, (SubstringMatcher)getStringCollator()); |
| 39 |
} |
| 40 |
|
| 41 |
private static StringValue substringAfter(StringValue arg1, StringValue arg2, SubstringMatcher collator) { |
| 42 |
if (arg1 == null) { |
| 43 |
arg1 = StringValue.EMPTY_STRING; |
| 44 |
} |
| 45 |
if (arg2 == null) { |
| 46 |
arg2 = StringValue.EMPTY_STRING; |
| 47 |
} |
| 48 |
if (arg2.isZeroLength()) { |
| 49 |
return arg1; |
| 50 |
} |
| 51 |
if (arg1.isZeroLength()) { |
| 52 |
return StringValue.EMPTY_STRING; |
| 53 |
} |
| 54 |
|
| 55 |
String s1 = arg1.getStringValue(); |
| 56 |
String s2 = arg2.getStringValue(); |
| 57 |
|
| 58 |
String result = collator.substringAfter(s1, s2); |
| 59 |
StringValue s = StringValue.makeStringValue(result); |
| 60 |
if (arg1.isKnownToContainNoSurrogates()) { |
| 61 |
s.setContainsNoSurrogates(); |
| 62 |
} |
| 63 |
return s; |
| 64 |
} |
| 65 |
|
| 66 |
public String getCompilerName() { |
| 67 |
return "SubstringAfterCompiler"; |
| 68 |
} |
| 69 |
|
| 70 |
} |