Module:Sond-roots

From Allocosm

Documentation for this module may be created at Module:Sond-roots/doc

export = {}

require("Module:sond-roots/data")

function export.replace(oper, str1, str2) 
	str1 = str1 or ''
	str2 = str2 or ''
	
	local rules = {}
	local output = ""
	local orig_oper = opers[oper]
	local orig_rules = orig_oper[1]
	local default = orig_oper[2]

	for k,v in pairs(orig_rules) do
		rules[string.gsub(k,"[12]",{["1"] = str1, ["2"] = str2})] = string.gsub(v,"[12]",{["1"] = str1, ["2"] = str2})
	end
	
	if type(default) == 'string' then 
		default = string.gsub(default,"[12]",{["1"] = str1, ["2"] = str2})
	elseif type(default) == 'function' then
		default = default(str1,str2)
	end

	output = rules[str1..str2] or default

	return output

end

return export