Vai al contenuto

Modulo:Valido in corsivo/sandbox

Da Wikipedia, l'enciclopedia libera.
Versione del 23 ott 2017 alle 11:29 di Sakretsu (discussione | contributi) (chiamato da modulo, restituisce true/false; chiamato da template, restituisce sì/no o nulla se il parametro non è compilato)
local i = {}

-- Funzione per l'utilizzo da altro modulo
i._IsLatin = function(args)
	local txt = args[1]
	if txt == '' then return false end
	
	local len = mw.ustring.len(txt)
	local pos = 1
	while (pos <= len) do
		charval = mw.ustring.codepoint(mw.ustring.sub(txt, pos))
		if charval >= 880 and charval < 8192 then
			return false
		elseif charval >= 8448 then
			return false
		end
		pos = pos + 1
	end
	return true
end

-- Funzione per il template IsLatin
i.IsLatin = function(frame)
	if frame.args[1] == '' then return end
	
	return i._IsLatin(frame.args) and 'sì' or 'no'
end

return i