position property

int position
inherited

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

Implementation

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

Implementation

@override
set position(int newPosition) {
  final oldPosition = position;
  super.position = newPosition;

  if (newPosition > oldPosition) {
    final newlines = _newlinesIn(string.substring(oldPosition, newPosition));
    _line += newlines.length;
    if (newlines.isEmpty) {
      _column += newPosition - oldPosition;
    } else {
      _column = newPosition - newlines.last.end;
    }
  } else {
    final 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;
    }
  }
}