checkArgumentCount static method

void checkArgumentCount(
  1. String name,
  2. List<XPathExpression> arguments,
  3. int min, [
  4. int? max,
])

Checks the number of arguments passed to a XPath function.

Implementation

static void checkArgumentCount(
    String name, List<XPathExpression> arguments, int min,
    [int? max]) {
  final count = arguments.length;
  if (min <= count && count <= (max ?? min)) return;
  final buffer = StringBuffer('Function "$name" expects ');
  if (min == max || max == null) {
    buffer.write('$min arguments');
  } else if (max == unbounded) {
    buffer.write('at least $min arguments');
  } else {
    buffer.write('between $min and $max arguments');
  }
  buffer.write(', but got $count');
  throw XPathEvaluationException(buffer.toString());
}