mirror of
https://github.com/pyrollo/display_modpack.git
synced 2024-08-20 04:34:05 +02:00
Rewrited split_lines to avoid a string.split bug if first line empty
This commit is contained in:
parent
95c9da849d
commit
06d35ec9bf
@ -55,17 +55,17 @@ local function char_to_codepoint(str)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Split multiline text into array of lines, with <maxlines> maximum lines.
|
-- Split multiline text into array of lines, with <maxlines> maximum lines.
|
||||||
|
-- Can not use minetest string.split as it has bug if first line(s) empty
|
||||||
local function split_lines(text, maxlines)
|
local function split_lines(text, maxlines)
|
||||||
local splits = text:split("\n")
|
local lines = {}
|
||||||
if maxlines then
|
local pos = 1
|
||||||
local lines = {}
|
repeat
|
||||||
for num = 1,maxlines do
|
local found = string.find(text, "\n", pos)
|
||||||
lines[num] = splits[num]
|
found = found or #text + 1
|
||||||
end
|
lines[#lines + 1] = string.sub(text, pos, found - 1)
|
||||||
return lines
|
pos = found + 1
|
||||||
else
|
until (maxlines and (#lines >= maxlines)) or (pos > (#text + 1))
|
||||||
return splits
|
return lines
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user