fastParse method

  1. @override
bool fastParse(
  1. State<StringReader> state
)
override

Parses the input and returns true if successful, false otherwise.

Implementation

@override
bool fastParse(State<StringReader> state) {
  if (m > n) {
    throw RangeError.range(m, 0, n, 'm');
  }

  final input = state.input;
  final pos = state.pos;
  var count = 0;
  while (count < n && state.pos < input.length) {
    final c = input.readChar(state.pos);
    final v = f(c);
    if (!v) {
      break;
    }

    state.pos += input.count;
    count++;
  }

  if (count >= m) {
    return true;
  }

  final failPos = state.pos;
  state.pos = pos;
  state.failAt<Object?>(failPos, const ErrorUnexpectedCharacter());
  return false;
}