mirror of
https://github.com/pyrollo/digiterms.git
synced 2025-01-09 17:10:20 +01:00
Rewrote push_text to handle utf8 and avoid crashes
This commit is contained in:
parent
0cbffd0753
commit
fc8040ff38
@ -47,16 +47,31 @@ end
|
|||||||
|
|
||||||
local function push_text(lines, text, maxlines, maxcolumns)
|
local function push_text(lines, text, maxlines, maxcolumns)
|
||||||
local pos = 1
|
local pos = 1
|
||||||
repeat
|
local column = 0
|
||||||
local found = text:find("\n", pos) or #text + 1
|
local start = 1
|
||||||
local line = text:sub(pos, found - 1)
|
while pos <= #text do
|
||||||
for index = 1, math.ceil(line:len() / maxcolumns) do
|
local b = text:byte(pos)
|
||||||
local part = line:sub((index-1)*maxcolumns+1, index*maxcolumns)
|
column = column + 1
|
||||||
push_line(lines, part, maxlines)
|
if b == 0x0A then
|
||||||
end
|
push_line(lines, text:sub(start, pos - 1), maxlines)
|
||||||
pos = found + 1
|
start = pos + 1
|
||||||
until (pos > (#text + 1))
|
column = 0
|
||||||
end
|
end
|
||||||
|
if column > maxcolumns then
|
||||||
|
push_line(lines, text:sub(start, pos - 1), maxlines)
|
||||||
|
start = pos
|
||||||
|
column = 1
|
||||||
|
end
|
||||||
|
if b < 0x80 then pos = pos + 1
|
||||||
|
elseif b >= 0xF0 then pos = pos + 4
|
||||||
|
elseif b >= 0xE0 then pos = pos + 3
|
||||||
|
elseif b >= 0xC2 then pos = pos + 2
|
||||||
|
else pos = pos + 1 end-- Invalid char
|
||||||
|
end
|
||||||
|
if pos - 1 > start then
|
||||||
|
push_line(lines, text:sub(start, pos - 1), maxlines)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function digimons.push_text_on_screen(pos, text)
|
function digimons.push_text_on_screen(pos, text)
|
||||||
local lines = get_lines(pos)
|
local lines = get_lines(pos)
|
||||||
|
Loading…
Reference in New Issue
Block a user