Module:Util

-- util local m_text = require('Module:Text') local p = {}

function p.nowrap(text) return ' ' .. text .. ' ' end

function p.escape(link) link = link or '' -- because of gsub not letting you have - unescaped link = string.gsub(link,'%-','%%%-') link = string.gsub(link,'%(','%%%(') link = string.gsub(link,'%)','%%%)') return link end

function p.dplEscape(link) link = link or '' link = string.gsub(link,'%(','\\%(') link = string.gsub(link,'%)','\\%)') return link end

function p.titleTable(title) local title = title or mw.title.getCurrentTitle.text return m_text.split(title,'/') end

function p.concatSubpage(base, extension) -- concatenate the two but don't add a / if the 2nd argument is empty or Overview if extension == 'Overview' or extension == '' or not extension then return base elseif base == '' or not base then return extension else return base .. '/' .. extension end end

function p.concatSubpageSystem(base, extension) local systems = mw.loadData('Module:Systems') return p.concatSubpage(base, systems[extension]) end

function p.concatSystemSubpage(base, extension) local systems = mw.loadData('Module:Systems') return p.concatSubpage(systems[base], extension) end

function p.concatSubpages(tbl, extension) for k, v in pairs(tbl) do		tbl[k] = p.concatSubpage(v, extension) end return end

function p.serializeNumber(N) local chr = tostring(N):sub(-1) local lookup = { ['1'] = 'st', ['2'] = 'nd', ['3'] = 'rd' } return chr .. (lookup[chr] or 'th') end

return p