Changed lume.wordwrap() to better retain existing whitespace

This commit is contained in:
rxi 2015-05-05 19:12:41 +01:00
parent a6744d4ab3
commit b25fee071f

View File

@ -565,20 +565,26 @@ function lume.wordwrap(str, limit)
check = limit check = limit
end end
local rtn = {} local rtn = {}
for j, line in ipairs(lume.split(str, "\n")) do local line = ""
local str for word, spaces in str:gmatch("(%S+)(%s*)") do
for i, word in ipairs(lume.split(line)) do local str = line .. word
local s = (str and (str .. " ") or "") .. word if check(str) then
if check(s) then table.insert(rtn, line .. "\n")
rtn[#rtn + 1] = str line = word
str = word
else else
str = s line = str
end
for c in spaces:gmatch(".") do
if c == "\n" then
table.insert(rtn, line .. "\n")
line = ""
else
line = line .. c
end end
end end
rtn[#rtn + 1] = str
end end
return table.concat(rtn, "\n") table.insert(rtn, line)
return table.concat(rtn)
end end