getOffset method

int getOffset(
  1. int line, [
  2. int? column
])

Gets the offset for a line and column.

column defaults to 0.

Implementation

int getOffset(int line, [int? column]) {
  column ??= 0;

  if (line < 0) {
    throw RangeError('Line may not be negative, was $line.');
  } else if (line >= lines) {
    throw RangeError('Line $line must be less than the number of '
        'lines in the file, $lines.');
  } else if (column < 0) {
    throw RangeError('Column may not be negative, was $column.');
  }

  final result = _lineStarts[line] + column;
  if (result > length ||
      (line + 1 < lines && result >= _lineStarts[line + 1])) {
    throw RangeError("Line $line doesn't have $column columns.");
  }

  return result;
}