| 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.StringCollator; |
| 12 |
import net.sf.saxon.lib.SubstringMatcher; |
| 13 |
import net.sf.saxon.om.Sequence; |
| 14 |
import net.sf.saxon.trans.XPathException; |
| 15 |
import net.sf.saxon.value.StringValue; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public class SubstringBefore extends CollatingFunctionFixed { |
| 22 |
|
| 23 |
@Override |
| 24 |
public boolean isSubstringMatchingFunction() { |
| 25 |
return true; |
| 26 |
} |
| 27 |
|
| 28 |
private static StringValue substringBefore(StringValue arg0, StringValue arg1, SubstringMatcher collator) { |
| 29 |
String s0 = arg0.getStringValue(); |
| 30 |
String s1 = arg1.getStringValue(); |
| 31 |
StringValue result = new StringValue(collator.substringBefore(s0, s1)); |
| 32 |
if (arg0.isKnownToContainNoSurrogates()) { |
| 33 |
result.setContainsNoSurrogates(); |
| 34 |
} |
| 35 |
return result; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public StringValue call(XPathContext context, Sequence[] arguments) throws XPathException { |
| 48 |
StringValue arg1 = (StringValue) arguments[1].head(); |
| 49 |
if (arg1 == null || arg1.isZeroLength()) { |
| 50 |
return StringValue.EMPTY_STRING; |
| 51 |
} |
| 52 |
|
| 53 |
StringValue arg0 = (StringValue) arguments[0].head(); |
| 54 |
if (arg0 == null || arg0.isZeroLength()) { |
| 55 |
return StringValue.EMPTY_STRING; |
| 56 |
} |
| 57 |
|
| 58 |
StringCollator collator = getStringCollator(); |
| 59 |
return substringBefore(arg0, arg1, (SubstringMatcher)collator); |
| 60 |
} |
| 61 |
|
| 62 |
public String getCompilerName() { |
| 63 |
return "SubstringBeforeCompiler"; |
| 64 |
} |
| 65 |
|
| 66 |
} |
| 67 |
|