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 RangeError('Offset may not be negative, was $offset.');
} else if (offset > length) {
throw 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 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.');
}
final lineStart = _lineStarts[line];
if (lineStart > offset) {
throw RangeError('Line $line comes after offset $offset.');
}
return offset - lineStart;
}