lineOfUtf16 method
Index of the line containing UTF-16 offset offset (the last line for
the end of the source).
Implementation
int lineOfUtf16(int offset) {
final hint = _lineHint;
if (hint < lineCount && lineStartUtf16(hint) <= offset) {
if (hint + 1 >= lineCount || offset < lineStartUtf16(hint + 1)) {
return hint;
}
if (hint + 2 >= lineCount || offset < lineStartUtf16(hint + 2)) {
return _lineHint = hint + 1;
}
}
var lo = 0, hi = lineCount - 1;
while (lo < hi) {
final mid = (lo + hi + 1) >> 1;
if (lineStartUtf16(mid) <= offset) {
lo = mid;
} else {
hi = mid - 1;
}
}
return _lineHint = lo;
}