/**
* Evaluate in a general context
*/
public Item evaluateItem(XPathContext c) throws XPathException {
AtomicValue sv;
if (argument.length == 0) {
final Item contextItem = c.getContextItem();
if (contextItem == null) {
dynamicError("The context item for string-length() is not set", "XPDY0002", c);
return null;
}
sv = StringValue.makeStringValue(contextItem.getStringValueCS());
} else {
sv = (AtomicValue)argument[0].evaluateItem(c);
}
if (sv==null) {
return Int64Value.ZERO;
}
// if (shortcut) {
// CharSequence s = sv.getStringValueCS();
// return (s.length()>0 ? Int64Value.PLUS_ONE : Int64Value.ZERO);
// } else
if (sv instanceof StringValue) {
return Int64Value.makeIntegerValue(((StringValue)sv).getStringLength());
} else {
CharSequence s = sv.getStringValueCS();
return Int64Value.makeIntegerValue(StringValue.getStringLength(s));
}
}