15.082
Bearbeitungen
(+ list()) |
(+p.ilist()) |
||
| Zeile 33: | Zeile 33: | ||
end | end | ||
function p.list(table, | function p.list(table, separator) | ||
-- converts a table into a list with delimiters | -- converts a keyed table into a list with delimiters | ||
-- the indexes/keys gonna lost and the list may be unsorted | -- the indexes/keys gonna lost and the list may be unsorted | ||
-- it's the counterpart of split() | -- it's the counterpart of split() | ||
| Zeile 40: | Zeile 40: | ||
if not c.isEmpty(table) then | if not c.isEmpty(table) then | ||
if type(table) == "table" then | if type(table) == "table" then | ||
separator = separator or " " | |||
for _, v in pairs(table) do | for _, v in pairs(table) do | ||
if #list ~= 0 then | if #list ~= 0 then | ||
list = list .. | list = list .. separator | ||
end | |||
list = list .. v | |||
end | |||
else | |||
list = table | |||
end | |||
end | |||
-- mw.log(list) -- Debugging only | |||
return list | |||
end | |||
function p.ilist(table, separator) | |||
-- converts a indexed table into a list with delimiters | |||
-- the indexes gonna lost | |||
-- it's the counterpart of split() | |||
local list = "" | |||
if not c.isEmpty(table) then | |||
if type(table) == "table" then | |||
separator = separator or " " | |||
for _, v in ipairs(table) do | |||
if #list ~= 0 then | |||
list = list .. separator | |||
end | end | ||
list = list .. v | list = list .. v | ||