getOffset method

int getOffset (int line, [ int column ])

Gets the offset for a line and column.

column defaults to 0.

Implementation

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

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

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

  return result;
}