FANDOM


local hc = require('Module:Paramtest').has_content
-- <pre>
local p = {}
 
-- stringmap
local sm = {
	[1] = '1',
	[2] = '2',
	[3] = '3',
	[4] = '4',
	[5] = '5',
	[6] = '6',
	[7] = '7',
	[8] = '8',
	[9] = '9',
	[0] = ''
}
 
function p.main(frame)
	local args = frame:getParent().args
 
	if not hc(args.l) and not hc(args.h) then
		return ''
	end
 
	-- lower, higher tier
	local _l,_h = args.l,args.h
 
	_l = tonumber(_l) or 0
	_h = tonumber(_h) or 999
 
	-- just in case someone switches them backwards
	if _l > _h then
		_l,_h = _h,_l
	end
 
	-- digit tables
	-- left pad lower
	local l = tostring(_l)
	if #l == 1 then
		l = '00'..l
	elseif #l == 2 then
		l = '0'..l
	end
 
	-- left pad higher
	local h = tostring(_h)
	if #h == 1 then
		h = '00'..h
	elseif #h == 2 then
		h = '0'..h
	end
 
	-- add digits
	l = mw.text.split(l,'')
	h = mw.text.split(h,'')
 
	-- turn all into numbers
	for i, v in ipairs(l) do
		l[i] = tonumber(v)
	end
 
	for i, v in ipairs(h) do
		h[i] = tonumber(v)
	end
 
	-- helper function for ranges
	local function range(a,b,c,d)
		a = tonumber(a) or 0
		b = tonumber(b) or 9
		if a > b then
			a,b = b,a
		end
		if a == b then
			return a
		else
			return string.format('[%s-%s]',a,b)
		end
	end
 
	-- create regex for numbers
	-- TODO: EFFICIENCY!
 
	-- statement in "Tier (regex) equipment"
	local regex
	-- if hundreds values match
	if l[1] == h[1] then
		-- if tens values match
		if l[2] == h[2] then
			-- if ones values match (the whole number matches)
			if l[3] == h[3] then
				regex = string.format('%s%s%s',sm[l[1]],sm[l[2]],sm[l[3]])
			-- if ones don't match
			else
				regex = string.format('%s%s[%s-%s]',l[1],l[2],l[3],h[3])
			end
		-- if tens don't match
		else
			-- if 10 higher
			if h[2] == (l[2] + 1) then
				regex = string.format('%s(%s%s|%s%s)',
					sm[l[1]],
					sm[l[2]],range(l[3]),
					sm[h[2]],range(_,h[3]))
			-- if bigger difference
			else
				regex = string.format('%s(%s%s|%s[0-9]|%s%s)',
					sm[l[1]],
					sm[l[2]],range(l[3]),
					range(l[2]+1,h[2]-1),
					sm[h[2]],range(_,h[3]))
			end
		end
	-- hundreds don't match
	else
		-- only figure the max is t1xx
		if l[2] == 9 then
			-- up to 10x
			if h[2] == 0 then
				regex = string.format('(9%s|10%s)',
					range(l[3]),
					range(h[3]))
			-- 1xx
			else
				regex = string.format('(9%s|1%s[0-9]|1%s%s)',
					range(l[3]),
					range(_,h[2]-1),
					h[2],range(_,h[3]))
			end
		-- if l > 9
		elseif l[2] ~= 0 then
			-- up to 10x
			if h[2] == 0 then
				-- lower ends in 0
				if l[3] == 0 then
					regex = string.format('(%s[0-9]|10%s)',
						range(l[2]),
						range(_,h[3]))
				-- lower doesn't end in 0
				else
					regex = string.format('(%s%s|%s[0-9]|10%s)',
						l[2],range(l[3]),
						range(l[2]+1),
						range(_,h[3]))
				end
			-- 1xx
			else
				-- lower ends in 0
				if l[3] == 0 then
					regex = string.format('(%s[0-9]|1%s[0-9]|1%s%s)',
						range(l[2]),
						range(_,h[2]-1),
						h[2],range(_,h[3]))
				-- lower doesn't end in 0
				else
					regex = string.format('(%s%s|%s[0-9]|1%s[0-9]|1%s%s)',
						l[2],range(l[3]),
						range(l[2]+1),
						range(_,h[2]-1),
						h[2],range(_,h[3]))
				end
			end
		-- if l < 10
		else
			-- up to 10x
			if h[2] == 0 then
				regex = string.format('([0-9]|[0-9][0-9]|10%s)',
					range(_,h[3]))
			-- 1xx
			else
				regex = string.format('(%s|[1-9][0-9]|1%s[0-9]|1%s%s)',
					range(l[3]),
					range(_,h[2]-1),
					h[2],range(_,h[3]))
			end
		end
	end
 
	return string.format('Tier %s equipment',regex)
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.