15.082
Bearbeitungen
Keine Bearbeitungszusammenfassung |
(+ list()) |
||
| Zeile 1: | Zeile 1: | ||
local p = {} | local p = {} | ||
local c = require("Module:Common") | |||
function p.replace(s, old, new, count) | function p.replace(s, old, new, count) | ||
| Zeile 14: | Zeile 15: | ||
function p.split(s, delimiter) | function p.split(s, delimiter) | ||
-- splits string s into pieces with delimiter and returns table | |||
-- it's the counterpart of list() | |||
delimiter = delimiter or " " | delimiter = delimiter or " " | ||
local result = {} | local result = {} | ||
| Zeile 26: | Zeile 29: | ||
table.insert(result, string.sub(s, start)) | table.insert(result, string.sub(s, start)) | ||
-- | -- mw.logObject(result) -- Debugging only | ||
return result | return result | ||
end | |||
function p.list(table, delimiter) | |||
-- converts a table into a list with delimiters | |||
-- the indexes/keys gonna lost and the list may be unsorted | |||
-- it's the counterpart of split() | |||
local list = "" | |||
if not c.isEmpty(table) then | |||
if type(table) == "table" then | |||
delimiter = delimiter or " " | |||
for _, v in pairs(table) do | |||
if #list ~= 0 then | |||
list = list .. delimiter | |||
end | |||
list = list .. v | |||
end | |||
else | |||
list = table | |||
end | |||
end | |||
-- mw.log(list) -- Debugging only | |||
return list | |||
end | end | ||