vtgl

terminal emulator implemented in OpenGL
git clone anongit@rnpnr.xyz:vtgl.git
Log | Files | Refs | Feed | LICENSE

utf8_decode.c (1488B)


      1 static const u8 utf8d[] = {
      2 	/* The first part of the table maps bytes to character classes that
      3 	 * to reduce the size of the transition table and create bitmasks. */
      4 	 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
      5 	 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
      6 	 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
      7 	 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
      8 	 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,  9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
      9 	 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,  7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
     10 	 8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2,  2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
     11 	10,3,3,3,3,3,3,3,3,3,3,3,3,4,3,3, 11,6,6,6,5,8,8,8,8,8,8,8,8,8,8,8,
     12 
     13 	/* The second part is a transition table that maps a combination
     14 	 * of a state of the automaton and a character class to a state. */
     15 	 0,12,24,36,60,96,84,12,12,12,48,72, 12,12,12,12,12,12,12,12,12,12,12,12,
     16 	12, 0,12,12,12,12,12, 0,12, 0,12,12, 12,24,12,12,12,12,12,24,12,24,12,12,
     17 	12,12,12,12,12,12,12,24,12,12,12,12, 12,24,12,12,12,12,12,12,12,24,12,12,
     18 	12,12,12,12,12,12,12,36,12,36,12,12, 12,36,12,12,12,12,12,36,12,36,12,12,
     19 	12,36,12,12,12,12,12,12,12,12,12,12,
     20 };
     21 
     22 #define UTF8_ACCEPT 0
     23 #define UTF8_REJECT 1
     24 
     25 static u32
     26 utf8_decode(u32 *state, u32 *cp, u8 byte)
     27 {
     28 	u8 type = utf8d[byte];
     29 
     30 	*cp = (*state != UTF8_ACCEPT) ?
     31 	         (byte & 0x3fu) | (*cp << 6) :
     32 	         (0xff >> type) & (byte);
     33 
     34 	*state = utf8d[256 + *state + type];
     35 	return *state;
     36 }