@@ -87,30 +87,30 @@ local function unicode_to_utf8(srcstr)
8787 local unicode = tonumber (" 0x" .. str_sub (srcstr , i + 2 , i + 5 ))
8888 if not unicode then
8989 tb_result [# tb_result + 1 ] = substr
90- break
90+ i = i + 2
91+ else
92+
93+ i = i + 6
94+
95+ if unicode <= 0x007f then
96+ -- 0xxxxxxx
97+ tb_result [# tb_result + 1 ] = str_char (band (unicode , 0x7f ))
98+ elseif unicode >= 0x0080 and unicode <= 0x07ff then
99+ -- 110xxxxx 10xxxxxx
100+ tb_result [# tb_result + 1 ] = str_char (bor (0xc0 , band (rshift (
101+ unicode , 6 ), 0x1f )))
102+ tb_result [# tb_result + 1 ] = str_char (bor (0x80 , band (
103+ unicode , 0x3f )))
104+ elseif unicode >= 0x0800 and unicode <= 0xffff then
105+ -- 1110xxxx 10xxxxxx 10xxxxxx
106+ tb_result [# tb_result + 1 ] = str_char (bor (0xe0 , band (rshift (
107+ unicode , 12 ), 0x0f )))
108+ tb_result [# tb_result + 1 ] = str_char (bor (0x80 , band (rshift (
109+ unicode , 6 ), 0x3f )))
110+ tb_result [# tb_result + 1 ] = str_char (bor (0x80 , band (unicode ,
111+ 0x3f )))
112+ end
91113 end
92-
93- i = i + 6
94-
95- if unicode <= 0x007f then
96- -- 0xxxxxxx
97- tb_result [# tb_result + 1 ] = str_char (band (unicode , 0x7f ))
98- elseif unicode >= 0x0080 and unicode <= 0x07ff then
99- -- 110xxxxx 10xxxxxx
100- tb_result [# tb_result + 1 ] = str_char (bor (0xc0 , band (rshift (
101- unicode , 6 ), 0x1f )))
102- tb_result [# tb_result + 1 ] = str_char (bor (0x80 , band (
103- unicode , 0x3f )))
104- elseif unicode >= 0x0800 and unicode <= 0xffff then
105- -- 1110xxxx 10xxxxxx 10xxxxxx
106- tb_result [# tb_result + 1 ] = str_char (bor (0xe0 , band (rshift (
107- unicode , 12 ), 0x0f )))
108- tb_result [# tb_result + 1 ] = str_char (bor (0x80 , band (rshift (
109- unicode , 6 ), 0x3f )))
110- tb_result [# tb_result + 1 ] = str_char (bor (0x80 , band (unicode ,
111- 0x3f )))
112- end
113-
114114 else
115115 tb_result [# tb_result + 1 ] = str_char (numbyte )
116116 i = i + 1
0 commit comments