Skip to content

Commit abc58c9

Browse files
committed
*Improved the algorithm to split unicode text.
1 parent d876473 commit abc58c9

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/libs/beGUI/beGUI_Utils.lua

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,34 @@ local function split(txt, sep)
5454
for line in string.gmatch(txt, '[^\n]*') do
5555
if sep == nil then
5656
for str in string.gmatch(line, '[\33-\127\192-\255]+[\128-\191]*') do
57-
table.insert(result, str)
57+
local codes = { }
58+
for _, v in utf8.codes(str) do
59+
table.insert(codes, v)
60+
end
61+
local j = nil
62+
for i = #codes, 1, -1 do
63+
if codes[i] <= 255 then
64+
break
65+
end
66+
j = i
67+
end
68+
if j == nil then
69+
table.insert(result, str)
70+
else
71+
local first, second = '', ''
72+
for k = 1, j - 1, 1 do
73+
first = first .. utf8.char(codes[k])
74+
end
75+
for k = j, #codes, 1 do
76+
second = second .. utf8.char(codes[k])
77+
end
78+
if first ~= '' then
79+
table.insert(result, first)
80+
end
81+
if second ~= '' then
82+
table.insert(result, second)
83+
end
84+
end
5885
end
5986
else
6087
for str in string.gmatch(line, '([^' .. sep .. ']+)') do

0 commit comments

Comments
 (0)