getFunction method
Looks up an XPath function with the given name and optional arity.
Implementation
XPathFunctionItem getFunction(XmlName name, [int? arity]) {
if (name.prefix != null && name.namespaceUri == null) {
throw XPathEvaluationException(
XPathErrorCode.XPST0081,
'Cannot expand namespace prefix: ${name.prefix}',
);
}
final function = functions[name];
if (function != null) {
if (arity != null && function is XPathOverloadedFunction) {
final specific = function.getForArity(arity);
if (specific != null) return specific;
throw XPathEvaluationException(
XPathErrorCode.XPST0017,
'Function "$name" does not support arity $arity',
);
}
if (arity != null && !function.isVariadic && function.arity != arity) {
throw XPathEvaluationException(
XPathErrorCode.XPST0017,
'Function "$name" does not support arity $arity',
);
}
if (arity != null && function.isVariadic && arity < function.arity) {
throw XPathEvaluationException(
XPathErrorCode.XPST0017,
'Function "$name" expects at least ${function.arity} arguments, but got $arity',
);
}
return function;
}
throw XPathEvaluationException(
XPathErrorCode.XPST0017,
'Unknown function: $name',
);
}