lineLengths method
Implementation
List<int> lineLengths() {
final lengths = <int>[];
var current = 0;
var previousWasCarriageReturn = false;
void consume(String chunk) {
for (var i = 0; i < chunk.length; i++) {
final codeUnit = chunk.codeUnitAt(i);
if (codeUnit == 10) {
lengths.add(previousWasCarriageReturn ? current - 1 : current);
current = 0;
previousWasCarriageReturn = false;
continue;
}
current++;
previousWasCarriageReturn = codeUnit == 13;
if (codeUnit >= 0xd800 &&
codeUnit <= 0xdbff &&
i + 1 < chunk.length &&
chunk.codeUnitAt(i + 1) >= 0xdc00 &&
chunk.codeUnitAt(i + 1) <= 0xdfff) {
i++;
}
}
}
_root.forEachLeaf(consume);
lengths.add(previousWasCarriageReturn ? current - 1 : current);
return lengths;
}