Modul:String: Unterschied zwischen den Versionen

- p.ilist()
(p.split2() zu p.split)
(- p.ilist())
Zeile 1: Zeile 1:
local p = {}
local p = {}
local c = require("Module:Common")
local com = require("Module:Common")


function p.replace(s, old, new, count)
function p.replace(s, old, new, count)
Zeile 39: Zeile 39:
-- mw.log("split2(" .. (s or "nil") .. ", " .. (delimiter or "nil") .. ")")
-- mw.log("split2(" .. (s or "nil") .. ", " .. (delimiter or "nil") .. ")")
     local result = {}
     local result = {}
     if not c.isEmpty(s) then
     if not com.isEmpty(s) then
result = p.split(s, delimiter)
result = p.split(s, delimiter)
     end
     end
Zeile 49: Zeile 49:
-- converts a keyed 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 p.split()
local list = ""
local list = ""
if not c.isEmpty(table) then
if not com.isEmpty(table) then
if type(table) == "table" then
if type(table) == "table" then
separator = separator or " "
separator = separator or " "
Zeile 64: Zeile 64:
end
end
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
  list = list .. v
end
else
list = table
end
end
-- mw.log(list) -- Debugging only
return list
return list
end
end