метод moveNext
Перемещает итератор к следующему элементу последовательности.
Этот метод следует вызвать перед чтением 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.19.6/dart-core/RuneIterator/moveNext.html