movePrevious method

bool movePrevious()

Move back to the previous code point.

Returns true and updates current if there is a previous code point. Returns false otherwise, and then there is no current code point.

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;
}