15.082
Bearbeitungen
(+ splitAndStrip()) |
(splitAndStrip() optimiert) |
||
| Zeile 83: | Zeile 83: | ||
function p.splitAndStrip(s, delimiter) | function p.splitAndStrip(s, delimiter) | ||
-- combination of p. | -- 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 = {} | ||
local start = 1 | |||
repeat | |||
local delim_start, delim_end = string.find(s, delimiter, start, true) -- true = plain find (keine Patterns) | |||
if delim_start ~= nil then | |||
local element = p.strip(string.sub(s, start, delim_start - 1)) | |||
if element ~= "" then | |||
table.insert(result, element) | |||
end | |||
start = delim_end + 1 | |||
end | |||
until delim_start == nil | |||
-- mw.logObject(result) | -- mw.logObject(result) | ||
return result | |||
end | end | ||
return p | return p | ||