position property

int position
inherited

The current position of the scanner in the string, in characters.

Implementation

int get position => _position;
void position= (int newPosition)
override

Implementation

set position(int newPosition) {
  var oldPosition = position;
  super.position = newPosition;

  if (newPosition > oldPosition) {
    var newlines = _newlinesIn(string.substring(oldPosition, newPosition));
    _line += newlines.length;
    if (newlines.isEmpty) {
      _column += newPosition - oldPosition;
    } else {
      _column = newPosition - newlines.last.end;
    }
  } else {
    var newlines = _newlinesIn(string.substring(newPosition, oldPosition));
    if (_betweenCRLF) newlines.removeLast();

    _line -= newlines.length;
    if (newlines.isEmpty) {
      _column -= oldPosition - newPosition;
    } else {
      _column =
          newPosition - string.lastIndexOf(_newlineRegExp, newPosition) - 1;
    }
  }
}