lineLengths method
O(n). Length of every line in code units.
Implementation
List<int> lineLengths() {
final lengths = <int>[];
var current = 0;
var previousWasCarriageReturn = false;
_root.forEachLeaf((chunk) {
for (var i = 0; i < chunk.length; i++) {
final unit = chunk.codeUnitAt(i);
if (unit == 10) {
lengths.add(previousWasCarriageReturn ? current - 1 : current);
current = 0;
previousWasCarriageReturn = false;
} else {
current++;
previousWasCarriageReturn = unit == 13;
}
}
});
lengths.add(previousWasCarriageReturn ? current - 1 : current);
return lengths;
}