Modul:String: Unterschied zwischen den Versionen

splitAndStrip() optimiert
(+ splitAndStrip())
(splitAndStrip() optimiert)
Zeile 83: Zeile 83:


function p.splitAndStrip(s, delimiter)
function p.splitAndStrip(s, delimiter)
-- combination of p.split2 and p.strip
-- combination of p.split and p.strip
-- transforms (string)list to table with the list elements
-- spaces before and after the list elements will be removed (stripped)
-- if list element is empty, no entry will be added to table
-- if list has no content, table will be empty
delimiter = delimiter or " "
s = s .. delimiter
     local result = {}
     local result = {}
     if not com.isEmpty(s) then
     local start = 1
local split = p.split2(s, delimiter)
    repeat
for _, v in ipairs(split) do
    local delim_start, delim_end = string.find(s, delimiter, start, true) -- true = plain find (keine Patterns)
v = p.strip(v)
    if delim_start ~= nil then
if v ~= "" then
    local element = p.strip(string.sub(s, start, delim_start - 1))
table.insert(result, v)
    if element ~= "" then
end
        table.insert(result, element)
end
        end
     end
        start = delim_end + 1
    end
     until delim_start == nil
-- mw.logObject(result)
-- mw.logObject(result)
return result
    return result
end
end


return p
return p