Module:Util

-- 	Additional functions that are common to other modules. Although they could	be called into templates the overhead call into lua would generally greater	than using a built in mediawiki parser function where one exists.	When calling in to another module, use 'local util = require( "Module:Util")'	This will ensure consistency between modules.

local util = {}

-- return pagename without any disambiguation title function util.corename(frame, title) if frame ~= nil and util.exists(frame.args[1]) then result = mw.ustring.gsub(frame.args[1], '%s%(.*', )   else    	if util.exists(title) then    		result =  mw.ustring.gsub(title, '%s%(.*', ) else result = mw.ustring.gsub(mw.title.getCurrentTitle.subpageText, '%s%(.*', '')   	end	end	return result end

-- Added this function in as a common method to check if a variable is 	populated. Old code was making this check multiple times in different forms.	The child parameter is to check if a row exists when object is a table. function util.exists(object, child) if object ~= nil and object ~= '' then if child ~= nil then if object[child] ~= nil and object[child] ~= '' then return true else return false end else return true end else return false end end

--Trim function from http://lua-users.org/wiki/StringTrim function util.trim(s) return s:match'^%s*$' and '' or s:match'^%s*(.*%S)' end

function util.inner(frame) title = frame.args[1] return util.corename(nil, frame.args[1]) end

return util