2 ms·
Here's the code to do it: https://github.com/skeeto/branchless-utf8/blob/master/utf8.h https://github.com/skeeto/branchless-utf8/blob/master/utf8.h It's pretty
by loeg 9y ago
Here's the code to do it: https://github.com/skeeto/branchless-utf8/blob/master/utf8.h https://github.com/skeeto/branchless-utf8/blob/master/utf8.h
It's pretty straightforward. He uses a lookup table for the first byte ("lengths") and then later checks that subsequent bytes have the correct continuation prefix (0xc0 mask / 0x2a value).
I think it checks all of the same conditions as your Lua code.