movePrevious method Null safety

bool movePrevious ()
override

Move back to the previous element.

Returns true and updates current if successful. Returns false and updates current to an implementation defined state if there is no previous element

Implementation

bool movePrevious() {
  _nextPosition = _position;
  if (_position == 0) {
    _currentCodePoint = -1;
    return false;
  }
  int position = _position - 1;
  int codeUnit = string.codeUnitAt(position);
  if (_isTrailSurrogate(codeUnit) && position > 0) {
    int prevCodeUnit = string.codeUnitAt(position - 1);
    if (_isLeadSurrogate(prevCodeUnit)) {
      _position = position - 1;
      _currentCodePoint = _combineSurrogatePair(prevCodeUnit, codeUnit);
      return true;
    }
  }
  _position = position;
  _currentCodePoint = codeUnit;
  return true;
}