2 ms·
If that bothers you, there's this approach: #define VALIDTAB (0x7f00ffff) #define LENTAB (0x000000003a550000) inline bool isvalidutf8start(char c
by Animats 9y ago
If that bothers you, there's this approach:
#define VALIDTAB (0x7f00ffff)
#define LENTAB (0x000000003a550000)
inline bool isvalidutf8start(char c)
{ return((VALIDTAB >> (c>>3)) & 1); }
inline unsigned utf8length(char c)
{ return(1+((LENTAB >> ((c>>3)*2)) & 2)); }
The 32-entry table of lengths can be coded up as a 64-bit value. The
"is valid" table is stored as a separate constant.