getLine method Null safety

int getLine(
  1. int offset
)

Gets the 0-based line corresponding to offset.

Implementation

int getLine(int offset) {
  if (offset < 0) {
    throw RangeError('Offset may not be negative, was $offset.');
  } else if (offset > length) {
    throw RangeError('Offset $offset must not be greater than the number '
        'of characters in the file, $length.');
  }

  if (offset < _lineStarts.first) return -1;
  if (offset >= _lineStarts.last) return _lineStarts.length - 1;

  if (_isNearCachedLine(offset)) return _cachedLine!;

  _cachedLine = _binarySearch(offset) - 1;
  return _cachedLine!;
}