validLength

fnsize_t validLength(scope const(char)[] s, out bool hasCR) @nogc nothrow pure @trusted

The length of the longest prefix of s that is valid and complete UTF-8. hasCR tells if that prefix contains a '\r' (the tokenizer normalizes newlines): one pass for both. ASCII runs are checked 16 bytes at a time.