Module:AeroWikiListTools: Difference between revisions
From Aeronautica Official Wiki
More actions
Sqwishyish (talk | contribs) Undo revision 521 by Sqwishyish (talk) Tag: Undo |
Sqwishyish (talk | contribs) m Added comma detection for the end of the string. |
||
Line 20: | Line 20: | ||
end | end | ||
for split in string.gmatch(input_string, '([^, ]+)') do | for split in string.gmatch(input_string , '([^,]+)') do | ||
new_string = new_string .. template:gsub('{split}', split) | new_string = new_string .. template:gsub('{split}', split:match('^%s*(.-)%s*$')) | ||
end | end | ||
mw.log(template:sub(-1)) | |||
if template:sub(-1) == ',' then | |||
new_string = new_string:sub(1, -2) | |||
elseif template:sub(-2) == ', ' then | |||
new_string = new_string:sub(1, -3) | |||
end | |||
return new_string | |||
end | end | ||
return p | return p |
Revision as of 07:38, 29 April 2025
Documentation for this module may be created at Module:AeroWikiListTools/doc
local getArgs = require('Module:Arguments').getArgs
local p = {}
local function makeInvokeFunc(funcName)
return function (frame)
local args = getArgs(frame)
return p[funcName](args)
end
end
p.split_list = makeInvokeFunc('_split_list')
p._split_list = function (args)
local input_string = args[1]
local template = args[2]
local new_string = ''
if type(input_string) == table then
input_string = table.concat(input_string, '')
end
for split in string.gmatch(input_string , '([^,]+)') do
new_string = new_string .. template:gsub('{split}', split:match('^%s*(.-)%s*$'))
end
mw.log(template:sub(-1))
if template:sub(-1) == ',' then
new_string = new_string:sub(1, -2)
elseif template:sub(-2) == ', ' then
new_string = new_string:sub(1, -3)
end
return new_string
end
return p