Modul:String: Unterschied zwischen den Versionen

p.split2() zu p.split
(fix c.split2())
(p.split2() zu p.split)
Zeile 35: Zeile 35:
function p.split2(s, delimiter)
function p.split2(s, delimiter)
-- same as p.split(), but with emptiness-check
-- same as p.split(), but with emptiness-check
-- if empty, then an empty table would be returned
-- to do: merge with p.split()
-- to do: merge with p.split()
-- 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 c.isEmpty(s) then
delimiter = delimiter or " "
result = p.split(s, delimiter)
    local start = 1
    local delim_start, delim_end = string.find(s, delimiter, start, true)  -- true = plain find (keine Patterns)
 
    while delim_start do
        table.insert(result, string.sub(s, start, delim_start - 1))
        start = delim_end + 1
        delim_start, delim_end = string.find(s, delimiter, start, true)
    end
    table.insert(result, string.sub(s, start))
     end
     end
-- mw.logObject(result)
-- mw.logObject(result)
return result
return result