Latest revision |
Your text |
Line 1: |
Line 1: |
| -- Created by @Sqwishyish on discord
| |
| -- Contact me for any issues
| |
|
| |
| local getArgs = require('Module:Arguments').getArgs
| |
|
| |
| local p = {} | | local p = {} |
|
| |
|
| local function makeInvokeFunc(funcName)
| | p.split_list = function (input_string, template) |
| return function (frame)
| |
| local args = getArgs(frame)
| |
| return p[funcName](args)
| |
| end
| |
| end
| |
| | |
| p.split_list = makeInvokeFunc('_split_list') | |
| p._split_list = function (args)
| |
| -- Get arguments passed from function call
| |
| local input_string = args[1] -- List string to modify
| |
| local template = args[2] -- String to put at each {split}
| |
| local missing_string = args[3] -- String to return when either the template or the input is nil
| |
| local new_string = '' | | local new_string = '' |
| | | |
| -- Check if input string exists
| | if type(input_string) == table then |
| if input_string == nil or template == nil then | | table.concat(input_string, '') |
| return missing_string | | end |
| | for split in string.gmatch(input_string, '([^, ]+)') do |
| | new_string = new_string .. template:gsub('{split}', split) .. ', ' |
| end | | end |
| | | return new_string:sub(1, -3) |
| -- Check if input string is not 'None'
| |
| if input_string == 'None' then
| |
| return 'None'
| |
| end
| |
|
| |
| -- Split string by commas and append the template at each {split} point
| |
| for split in string.gmatch(input_string , '([^,]+)') do
| |
| new_string = new_string .. template:gsub('{split}', split:match('^%s*(.-)%s*$')) .. ' '
| |
| end
| |
|
| |
| -- Remove comma on end of list
| |
| if template:sub(-1) == ',' then
| |
| new_string = new_string:sub(1, -3)
| |
| elseif template:sub(-2) == ', ' then
| |
| new_string = new_string:sub(1, -4)
| |
| end
| |
|
| |
| -- Return the new string to the list
| |
| return new_string
| |
| end | | end |
| return p | | return p |