Spec-Zone.ru › Dart 2

dart:core

Метод moveNext

bool moveNext()
override

Перемещает итератор к следующему элементу итерации.

Должен вызываться перед чтением current. Если вызов moveNext возвращает true, тогда current будет содержать следующий элемент итерации до тех пор, пока moveNext не будет вызван снова. Если вызов возвращает false, то больше элементов нет, и current больше не должен использоваться.

Безопасно вызывать moveNext после того, как он уже вернул false, но он должен продолжать возвращать false и не иметь никаких других последствий.

Вызов moveNext может вызвать исключение по различным причинам, включая одновременное изменение базовой коллекции. Если это произойдёт, итератор может оказаться в несогласованном состоянии, и любое дальнейшее поведение итератора не определено, включая влияние чтения current.

final colors = ['blue', 'yellow', 'red'];
final colorsIterator = colors.iterator;
print(colorsIterator.moveNext()); // true
print(colorsIterator.moveNext()); // true
print(colorsIterator.moveNext()); // true
print(colorsIterator.moveNext()); // 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;
}

© 2012 the Dart project authors
Licensed under the BSD 3-Clause "New" or "Revised" License.
https://api.dart.dev/stable/2.18.5/dart-core/RuneIterator/moveNext.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API