Module:Array: Difference between revisions

Kwwxis (talk | contribs)
Add more features from Array module in zzz/wuwa wikis
No edit summary
 
(One intermediate revision by one other user not shown)
Line 127: Line 127:
-- join as sentence
-- join as sentence
if sentence ~= nil then
if sentence ~= nil then
if #array == 0 then return ""
if #array == 0 then return ''
elseif #array == 1 then return array[1]
elseif #array == 1 then result =  array[1]
elseif #array == 2 then return array[1] .. sentence_last .. array[2]
elseif #array == 2 then result =  array[1] .. sentence_last .. array[2]
else
else
local last = table.remove(array, #array)
local last = table.remove(array, #array)
Line 139: Line 139:
-- join with join string
-- join with join string
else
else
if string.find(join, "{newline}") then
result = table.concat(array, join):gsub('{newline}', '\n'):gsub('{space}', ' ')--in case joining string contains keyword
join = join:gsub("{newline}", "\n")
end
if string.find(join, "{space}") then
join = join:gsub("{space}", " ")
end
result = table.concat(array, join)
end
end
result = prefix .. result .. suffix
result = prefix .. result .. suffix