Modulo:String: differenze tra le versioni
mediawiki>Yusur-kun vedi https://it.wikipedia.org/wiki/Modulo:String |
Creata pagina con "--[[ Questo modulo serve a fornire l'accesso alle funzioni stringa base. La maggior parte delle funzioni di questo modulo possono essere invocate con parametri con nome, senza nome o con un misto di entrambi. Quando vengono usati parametri con nome il software di Mediawiki rimuoverà ogni spazio iniziale o finale dal parametro. A seconda dell'uso che si vuole fare della funzione può essere vantaggioso conservare oppure rimuovere questi spazi. Opzioni globali igno..." |
||
Riga 1: | Riga 1: | ||
--[[ | --[[ | ||
Riga 438: | Riga 434: | ||
function str.collate( frame ) | function str.collate( frame ) | ||
local collation = { | local collation = { | ||
{'[ | { '[áàăắằẵẳâấầẫẩǎåǻäǟãȧǡąāảȁȃạặậḁⱥᶏᴂɐᶐɒ]' , 'a'}, | ||
{'[ | {'[ÁÀĂẮẰẴẲÂẤẦẪẨǍÅÅǺÄǞÃȦǠĄĀẢȀȂẠẶẬḀȺᴁ]', 'A'}, | ||
{'[ | {'[ḃḅḇbƀɓ]', 'b'}, | ||
{'[ḂḄḆɃ]', 'B'}, | {'[ḂḄḆɃ]', 'B'}, | ||
{'[ćĉčċçḉȼƈ]', 'c'}, | {'[ćĉčċçḉȼƈ]', 'c'}, | ||
{'[ĆĈČĊÇḈȻƇ]', 'C'}, | {'[ĆĈČĊÇḈȻƇ]', 'C'}, | ||
{'[ | {'[đḍḓḏðď]', 'd'}, | ||
{'[ | {'[ĐḌḒḎÐĎ]', 'D'}, | ||
{'[ | {'[éèèêếềễểěëẽėȩḝęēḗḕẻȅȇẹệḙḛǝ]', 'e'}, | ||
{'[ | {'[ÉÈÈÊẾỀỄỂĚËẼĖȨḜĘĒḖḔẺȄȆẸỆḘḚƎ]', 'E'}, | ||
{'[ḟⅎ]', 'f'}, | {'[ḟⅎ]', 'f'}, | ||
{'[ḞℲ]', 'F'}, | {'[ḞℲ]', 'F'}, | ||
Riga 467: | Riga 463: | ||
{'[ńǹňñṅņṇṋṉ]', 'n'}, | {'[ńǹňñṅņṇṋṉ]', 'n'}, | ||
{'[ŃǸŇÑṄŅṆṊṈ]', 'N'}, | {'[ŃǸŇÑṄŅṆṊṈ]', 'N'}, | ||
{'[ | {'[óòŏôốồỗổǒöȫőõṍṏȭȯȱøǿǫǭōṓṑỏȍȏơớờỡởợọộ]', 'o'}, | ||
{'[ | {'[ÓÒŎÔỐỒỖỔǑÖȪŐÕṌṎȬȮȰØǾǪǬŌṒṐỎȌȎƠỚỜỠỞỢỌỘ]', 'O'}, | ||
{'[ṕṗ]', 'p'}, | {'[ṕṗ]', 'p'}, | ||
{'[ṔṖ]', 'P'}, | {'[ṔṖ]', 'P'}, | ||
{'[ŕřṙŗȑȓṛṝṟ]', 'r'}, | {'[ŕřṙŗȑȓṛṝṟ]', 'r'}, | ||
{'[ŔŘṘŖȐȒṚṜṞ]', 'R'}, | {'[ŔŘṘŖȐȒṚṜṞ]', 'R'}, | ||
{'[ | {'[śṥŝšṧṡşṣṩș]', 's'}, | ||
{'[ | {'[ŚṤŜŠṦṠŞṢṨȘ]', 'S'}, | ||
{'[ťṫẗţṭțṱṯ]', 't'}, | {'[ťṫẗţṭțṱṯ]', 't'}, | ||
{'[ŤṪŢṬȚṰṮ]', 'T'}, | {'[ŤṪŢṬȚṰṮ]', 'T'}, | ||
Riga 537: | Riga 533: | ||
name = par_name, | name = par_name, | ||
base_name = mw.ustring.gsub(par_name, ' ?#', '', 1), | base_name = mw.ustring.gsub(par_name, ' ?#', '', 1), | ||
alt = alt_name | alt = alt_name or '' | ||
}, Param) | }, Param) | ||
end | end | ||
Riga 551: | Riga 547: | ||
function Param:get_first_value(args, index, base_index) | function Param:get_first_value(args, index, base_index) | ||
function value_or_nil (s) | function value_or_nil (s) | ||
if s and s ~= '' then return s end | if s and s~= '' then return s end | ||
return nil | return nil | ||
end | end | ||
Riga 559: | Riga 555: | ||
end | end | ||
if index == base_index then | if index == base_index then | ||
return value_or_nil(args[mw.ustring.gsub(self.name, '#', tostring(index), 1)]) or | 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 | value_or_nil(args[self.base_name]) or value_or_nil(args[self.alt]) or '', false | ||
else | else | ||
return value_or_nil(args[mw.ustring.gsub(self.name, '#', tostring(index), 1)]) or | return value_or_nil(args[mw.ustring.gsub(self.name, '#', tostring(index), 1)]) or | ||
value_or_nil(args[self.alt]) or '', false | value_or_nil(args[self.alt]) or '', false | ||
end | end | ||
Riga 659: | Riga 655: | ||
while true do | while true do | ||
local par_name = base_args['par' .. index] or (index == 1 and base_args['par']) or '' | local par_name = base_args['par' .. index] or (index == 1 and base_args['par']) or '' | ||
if par_name == '' then break end | if par_name == '' then break end; | ||
--carico eventuale nome alternativo per il primo parametro | --carico eventuale nome alternativo per il primo parametro | ||
local alt_name = base_args['altpar' .. index] or (index == 1 and base_args['altpar']) or | local alt_name = base_args['altpar' .. index] or (index == 1 and base_args['altpar']) or '' | ||
params[index] = Param(par_name, alt_name) | params[index] = Param(par_name, alt_name) | ||
index = index + 1 | index = index + 1 | ||
Riga 683: | Riga 679: | ||
local v, is_index = param:get_first_value(args, index, base_index) | local v, is_index = param:get_first_value(args, index, base_index) | ||
if (not(is_index) or base_index<=Nobbligatori) and v ~= '' then found = true end | if (not(is_index) or base_index<=Nobbligatori) and v ~= '' then found = true end | ||
message:add_value | message:add_value(v) | ||
end | end | ||
if found then | if found then | ||
Riga 697: | Riga 693: | ||
local v, is_index = param:get_other_value(args, index) | local v, is_index = param:get_other_value(args, index) | ||
if (not(is_index) or index<=Nobbligatori) and v ~= '' then found = true end | if (not(is_index) or index<=Nobbligatori) and v ~= '' then found = true end | ||
message:add_value | message:add_value(v) | ||
end | end | ||
if found then | if found then |