unread method

  1. @override
void unread()
override

Puts the one character back into the stream stream.

  • value A character to be pushed back.

Implementation

@override
void unread() {
  // Skip if we are at the beginning
  if (_position < -1) {
    return;
  }

  // Update the current position
  _position--;

  // Update line and columns (optimization)
  if (_column > 0) {
    _column--;
    return;
  }

  // Update line and columns (full version)
  _line = 1;
  _column = 0;

  var charBefore = StringScanner.Eof;
  var charAt = StringScanner.Eof;
  var charAfter = _charAt(0);

  for (var position = 0; position <= _position; position++) {
    charBefore = charAt;
    charAt = charAfter;
    charAfter = _charAt(position + 1);

    if (_isLine(charBefore, charAt, charAfter)) {
      _line++;
      _column = 0;
    }
    if (_isColumn(charAt)) {
      _column++;
    }
  }
}