peekCodePoint method

int? peekCodePoint()

Returns the Unicode code point immediately after position.

This works like peekChar, except that it automatically handles UTF-16 surrogate pairs. Specifically, if the next two code units form a surrogate pair, returns the corresponding Unicode code point.

If next two characters are not a surrogate pair, the next code unit is returned as-is, even if it's an unpaired surrogate.


int? peekCodePoint() {
  final first = peekChar();
  if (first == null || !isHighSurrogate(first)) return first;

  final next = peekChar(1);
  if (next == null || !isLowSurrogate(next)) return first;

  return decodeSurrogatePair(first, next);