moveNext 方法

bool moveNext()
override

移动到下一个代码点。

如果有下一个代码点,返回 true 并更新 current。否则返回 false,此时没有当前代码点。

实现

bool moveNext() {
  _position = _nextPosition;
  if (_position == string.length) {
    _currentCodePoint = -1;
    return false;
  }
  int codeUnit = string.codeUnitAt(_position);
  int nextPosition = _position + 1;
  if (_isLeadSurrogate(codeUnit) && nextPosition < string.length) {
    int nextCodeUnit = string.codeUnitAt(nextPosition);
    if (_isTrailSurrogate(nextCodeUnit)) {
      _nextPosition = nextPosition + 1;
      _currentCodePoint = _combineSurrogatePair(codeUnit, nextCodeUnit);
      return true;
    }
  }
  _nextPosition = nextPosition;
  _currentCodePoint = codeUnit;
  return true;
}