scanChar method

bool scanChar(
  1. int character
)

If the next character in the string is character, consumes it.

If character is a Unicode code point in a supplementary plane, this will consume two code units. Dart's string representation is UTF-16, which represents supplementary-plane code units as two code units.

Returns whether or not character was consumed.

Implementation

bool scanChar(int character) {
  if (inSupplementaryPlane(character)) {
    if (_position + 1 >= string.length ||
        string.codeUnitAt(_position) != highSurrogate(character) ||
        string.codeUnitAt(_position + 1) != lowSurrogate(character)) {
      return false;
    } else {
      _position += 2;
      return true;
    }
  } else {
    if (isDone) return false;
    if (string.codeUnitAt(_position) != character) return false;
    _position++;
    return true;
  }
}