local p =
--split|source_string|pattern|count|plain}}
Parameters: source: The string to return a subset of pattern: The pattern or string to split on count: The nth substring based on the pattern to return plain: A flag indicating if the pattern should be understood as plain text, defaults to true.
function p.split(frame) local new_args = p._getParameters(frame.args,) local source_str = new_args['source'] or ; local pattern = new_args['pattern'] or ; if source_strthen return source_str; end local l_plain = p._getBoolean(new_args['plain'] or true); if l_plain then pattern = p._escapePattern(pattern); end local plain = false; pattern = "[" .. pattern .. "]" local ret_count = tonumber(new_args['count']) or 1; local start = 1; local iter = mw.ustring.find(source_str, pattern, start, plain); if iter
1 then return mw.ustring.sub(source_str, start, iter); end for i=2, ret_count do start = iter+1; iter = mw.ustring.find(source_str, pattern, start, plain); if iter
-- Argument list helper function, as per Module:Stringfunction p._getParameters(frame_args, arg_list) local new_args = ; local index = 1; local value; for i, arg in ipairs(arg_list) do value = frame_args[arg] if value
-- Escape Pattern helper function so that all charecters are treated as plain text, as per Module:Stringfunction p._escapePattern(pattern_str) return mw.ustring.gsub(pattern_str, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1");end
-- Helper Function to interpret boolean strings, as per Module:Stringfunction p._getBoolean(boolean_str) local boolean_value; if type(boolean_str)
'false' or boolean_str
'O' or boolean_str
'boolean' then boolean_value = boolean_str; else error('No boolean value found'); end return boolean_valueend
return p