parseOn method
Primitive method doing the actual parsing.
The method is overridden in concrete subclasses to implement the
parser specific logic. The methods takes a parse context
and
returns the resulting context, which is either a Success or
Failure context.
Implementation
@override
@noBoundsChecks
Result<String> parseOn(Context context) {
final buffer = context.buffer;
final position = context.position;
if (position < buffer.length) {
var codeUnit = buffer.codeUnitAt(position);
var nextPosition = position + 1;
if (_isLeadSurrogate(codeUnit) && nextPosition < buffer.length) {
final nextCodeUnit = buffer.codeUnitAt(nextPosition);
if (_isTrailSurrogate(nextCodeUnit)) {
codeUnit = _combineSurrogatePair(codeUnit, nextCodeUnit);
nextPosition++;
}
}
if (predicate.test(codeUnit)) {
return context.success(
buffer.substring(position, nextPosition),
nextPosition,
);
}
}
return context.failure(message);
}