* Evaluate the function
*/
public Item evaluateItem(XPathContext context) throws XPathException {
AtomicValue av = (AtomicValue)argument[0].evaluateItem(context);
if (av==null) {
return StringValue.EMPTY_STRING;
}
StringValue sv = (StringValue)av;
if (sv.isZeroLength()) {
return StringValue.EMPTY_STRING;
}
AtomicValue a1 = (AtomicValue)argument[1].evaluateItem(context);
NumericValue a = (NumericValue)a1;
if (argument.length==2) {
StringValue result = StringValue.makeStringValue(substring(sv, a));
if (sv.isKnownToContainNoSurrogates()) {
result.setContainsNoSurrogates();
}
return result;
} else {
AtomicValue b2 = (AtomicValue)argument[2].evaluateItem(context);
NumericValue b = (NumericValue)b2;
StringValue result = StringValue.makeStringValue(substring(sv, a, b, context));
if (sv.isKnownToContainNoSurrogates()) {
result.setContainsNoSurrogates();
}