/**
* Evaluate the function
*/
public Item evaluateItem(XPathContext context) throws XPathException {
StringValue arg1 = (StringValue)argument[0].evaluateItem(context);
StringValue arg2 = (StringValue)argument[1].evaluateItem(context);
if (arg1 == null) {
arg1 = StringValue.EMPTY_STRING;
}
if (arg2 == null) {
arg2 = StringValue.EMPTY_STRING;
}
if (arg2.isZeroLength()) {
return arg1;
}
if (arg1.isZeroLength()) {
return StringValue.EMPTY_STRING;
}
String s1 = arg1.getStringValue();
String s2 = arg2.getStringValue();
String result = null;
if (stringCollator instanceof CodepointCollator) {
// fast path for this common case
int i = s1.indexOf(s2);
if (i < 0) {
result = "";
} else {
result = s1.substring(i + s2.length());
}
} else {
StringCollator collator = getCollator(2, context);
if (collator instanceof NamedCollation &&
((NamedCollation)collator).getCollation() instanceof RuleBasedCollator) {
collator = new RuleBasedSubstringMatcher((RuleBasedCollator)((NamedCollation)collator).getCollation());
}
if (collator instanceof SubstringMatcher) {
result = ((SubstringMatcher)collator).substringAfter(s1, s2);
} else {
dynamicError("The collation requested for " + getDisplayName() +
" does not support substring matching", "FOCH0004", context);
}
}
StringValue s = StringValue.makeStringValue(result);
if (arg1.isKnownToContainNoSurrogates()) {
s.setContainsNoSurrogates();
}
return s;
}