Modulo:String: differenze tra le versioni

aggiornato come da https://it.wikipedia.org/w/index.php?title=Modulo:String&oldid=117811788
(scopiazzato da https://it.wikipedia.org/w/index.php?title=Modulo:String&oldid=109037778)
 
(aggiornato come da https://it.wikipedia.org/w/index.php?title=Modulo:String&oldid=117811788)
 
Riga 533:
name = par_name,
base_name = mw.ustring.gsub(par_name, ' ?#', '', 1),
alt = alt_name or ''
}, Param)
end
Riga 547:
function Param:get_first_value(args, index, base_index)
function value_or_nil (s)
if s and s ~= '' then return s end
return nil
end
Riga 555:
end
if index == base_index then
return value_or_nil(args[mw.ustring.gsub(self.name, '#', tostring(index), 1)]) or
value_or_nil(args[self.base_name]) or value_or_nil(args[self.alt]) or '', false
else
return value_or_nil(args[mw.ustring.gsub(self.name, '#', tostring(index), 1)]) or
value_or_nil(args[self.alt]) or '', false
end
Riga 655:
while true do
local par_name = base_args['par' .. index] or (index == 1 and base_args['par']) or ''
if par_name == '' then break end;
--carico eventuale nome alternativo per il primo parametro
local alt_name = base_args['altpar' .. index] or (index == 1 and base_args['altpar']) or ''nil
params[index] = Param(par_name, alt_name)
index = index + 1
Riga 822:
end
return pre .. mw.text.listToText(elements, separatore, congiunzione) .. post
end
 
--[[
Identifica se il valore passato è un IP
source: https://stackoverflow.com/questions/10975935/lua-function-check-if-ipv4-or-ipv6-or-string
 
--]]
function str.checkIP(frame)
 
local ip = frame.args[1] or ''
 
-- check for format 1.11.111.111 for ipv4
local chunks = {ip:match("^(%d+)%.(%d+)%.(%d+)%.(%d+)$")}
if #chunks == 4 then
for _,v in pairs(chunks) do
if tonumber(v) > 255 then return '' end
end
return ip
end
 
-- check for ipv6 format, should be 8 'chunks' of numbers/letters
-- without leading/trailing chars
-- or fewer than 8 chunks, but with only one `::` group
local chunks = {ip:match("^"..(("([a-fA-F0-9]*):"):rep(8):gsub(":$","$")))}
if #chunks == 8 or #chunks < 8 and ip:match('::') and not ip:gsub("::","",1):match('::') then
for _,v in pairs(chunks) do
if #v > 0 and tonumber(v, 16) > 65535 then
return ''
end
end
return ip
end
return ''
end
 
Line 937 ⟶ 904:
-- 07/05/2013 aggiunta funzione rep da en:module:String versione 552254999 del 26 aprile 2013
-- 19/08/2013 aggiunta funzione arraytostring
-- 14/6/2019 aggiunta funzione checkIP