getColumn method
Gets the 0-based column corresponding to offset
.
If line
is passed, it's assumed to be the line containing offset
and
is used to more efficiently compute the column.
Implementation
int getColumn(int offset, {int line}) {
if (offset < 0) {
throw new RangeError("Offset may not be negative, was $offset.");
} else if (offset > length) {
throw new RangeError("Offset $offset must be not be greater than the "
"number of characters in the file, $length.");
}
if (line == null) {
line = getLine(offset);
} else 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.");
}
var lineStart = _lineStarts[line];
if (lineStart > offset) {
throw new RangeError("Line $line comes after offset $offset.");
}
return offset - lineStart;
}