跳转到内容

模組:Parameters/lite/list

維基詞典,自由的多語言詞典
local function clean(x) return x and #x > 0 and x or nil end

-- implements a list parameter, somewhat
return function (args, param, allow_holes, allow_empty)
	local results = {clean(args[param] and mw.text.trim(args[param]))}
	local maximum_index = 0
	local pattern = "^" .. require("Module:string/pattern escape")(param) .. "([0-9]+)$"
	
	for key, value in pairs(args) do
		local index = mw.ustring.match(key, pattern)
		if index then
			index = tonumber(index)
			if index and index > 0 then
				value = value and mw.text.trim(value)
				if not allow_empty then value = clean(value) end
				results[index] = value
				maximum_index = math.max(maximum_index, index)
			end
		end
	end
	
	if maximum_index > 0 then
		if not allow_holes then
			local i = 1
			local j = 1
			while i <= maximum_index do
				if results[i] then
					results[j] = results[i]
					if j < i then results[i] = nil end
					j = j + 1
				end
				i = i + 1
			end
		else
			results.maxindex = maximum_index
		end
	end
	
	return results
end
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy