mirror of
https://github.com/pyrollo/display_modpack.git
synced 2024-12-12 16:03:14 +01:00
Rewrited split_lines to avoid a string.split bug if first line empty
This commit is contained in:
parent
b74407e11e
commit
1a50b59995
16
font.lua
16
font.lua
@ -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")
|
|
||||||
if maxlines then
|
|
||||||
local lines = {}
|
local lines = {}
|
||||||
for num = 1,maxlines do
|
local pos = 1
|
||||||
lines[num] = splits[num]
|
repeat
|
||||||
end
|
local found = string.find(text, "\n", pos)
|
||||||
|
found = found or #text + 1
|
||||||
|
lines[#lines + 1] = string.sub(text, pos, found - 1)
|
||||||
|
pos = found + 1
|
||||||
|
until (maxlines and (#lines >= maxlines)) or (pos > (#text + 1))
|
||||||
return lines
|
return lines
|
||||||
else
|
|
||||||
return splits
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user