Module:Text count

From Omniversalis

Documentation for this module may be created at Module:Text count/doc

local z = {}

function z.main(frame)
	local config = frame.args
	
	local errors = {}
	if not config.text then
		table.insert(errors, "no text argument. Please provide the text that you wish to count strings in.")
	end
	if not config.pattern then
		table.insert(errors, "no pattern argument. Please provide the string you wish to search for.")
	end
	
	if table.maxn(errors) == 0 then
		local temp, count = mw.ustring.gsub(config.text, config.pattern, "%0")
		return count
	else
		return table.concat(errors, " ")
	end
end

return z