decodeTextRow static method
Decodifica uma linha no formato texto do COPY (como as recebidas por
copyTo; o \n final é opcional) em uma lista de valores, com null
para \N.
Implementation
static List<String?> decodeTextRow(List<int> line,
{Encoding encoding = utf8}) {
var text = encoding.decode(line);
if (text.endsWith('\n')) text = text.substring(0, text.length - 1);
final values = <String?>[];
final current = StringBuffer();
var isNull = false;
for (var i = 0; i < text.length; i++) {
final c = text.codeUnitAt(i);
if (c == 0x09) {
values.add(isNull ? null : current.toString());
current.clear();
isNull = false;
} else if (c == 0x5C && i + 1 < text.length) {
final next = text[++i];
switch (next) {
case 'N':
isNull = true;
case 'n':
current.write('\n');
case 'r':
current.write('\r');
case 't':
current.write('\t');
case 'b':
current.write('\b');
case 'f':
current.write('\f');
case 'v':
current.write('\v');
default:
current.write(next);
}
} else {
current.writeCharCode(c);
}
}
values.add(isNull ? null : current.toString());
return values;
}