3 ms·
I'm not sure scanning backwards this helps. Running in reverse you still need to look for a newline scanning over an UTF-8 string which might plausibly contain
by marginalia_nu 3y ago
I'm not sure scanning backwards this helps. Running in reverse you still need to look for a newline scanning over an UTF-8 string which might plausibly contain a newline byte.
I'm no UTF-8 guru, but I think you might be possible to do this sort of a springboard for skipping over multi-byte codepoints, since as far as I understand the upper bits of the first byte encodes the length:
byte utfByte1 = (byte) (val & 0xF0);
if (utfByte1 == (byte) 0xF0) { // 4 byte codepoint
// ignore 3
}
else if (utfByte1 == (byte) 0xE0) { // 3 byte codepoint
// ignore 2
}
else if (utfByte1 == (byte) 0xC0) { // 2 byte codepoint
// ignore 1
}