Module:Split

From Moegirlpedia
Jump to: navigation, search
Template-info.svg Module Documentation  [Create] [Refresh]
local module = {}

local getArgs = require('Module:Arguments').getArgs

function module._main(args, frame)
	local str = args['str'] or ''
	local ptn = args['ptn'] or ''
	ptn = mw.text.decode(mw.text.unstripNoWiki(ptn))
	local name = args['name'] or 'foo'
	if args['reg'] ~= 'on' then
		ptn = mw.ustring.gsub(ptn, '([%%%(%)%.%+%-%*%?%[%]%^%$])', '%%%1')
	end
	local datas = mw.text.split(str, ptn)
	for i, v in ipairs(datas) do
		v = mw.ustring.gsub(v, '^%s*(.+)%s*$', '%1')
		frame:callParserFunction( '#vardefine', name..i,  v)
	end
	frame:callParserFunction( '#vardefine', name..'.count',  #datas)
end

function module.main(frame)
	local args = getArgs(frame)
	return module._main(args, frame)
end


return module