Modul:parameters/lite/list suffix
< Modul:parameters | lite
- Modul ini kekurangan sublaman pendokumenan. Sila mencipta laman pendokumenan berkaitan.
- Pautan berguna: laman akar • sublaman • pautan • transklusi • kes ujian • kotak pasir
local function clean(x) return x and #x > 0 and x or nil end
-- implements a list parameter with suffix, somewhat
return function (args, param, suffix, allow_holes, allow_empty)
local results = {}
local maximum_index = 0
local pattern = "^" .. require("Module:string/pattern escape")(param) .. "([0-9]+)" .. require("Module:string/pattern escape")(suffix) .. "$"
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 = 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