Modulo:String/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Moroboshi (discussione | contributi)
Nessun oggetto della modifica
rimuovo funzione incompleta e rimpiazzata da Modulo:IP validator
 
(15 versioni intermedie di 2 utenti non mostrate)
Riga 148:
 
]]
function str.match( frame )
return str._match(frame.args)
local new_args = str._getParameters( frame.args, {'s', 'pattern', 'start', 'match', 'plain', 'nomatch'} );
end
 
--[[
Entry point per chiamata diretta da un modulo
]]
function str._match( args )
local new_args = str._getParameters( args, {'s', 'pattern', 'start', 'match', 'plain', 'nomatch'} );
local s = new_args['s'] or '';
local start = tonumber( new_args['start'] ) or 1;
Line 422 ⟶ 429:
 
--[[
Funzione per normalizzaresemplificare unastringhe stringacon unicode in forma NFC o NFDdiacritici
vedi: https://en.wikipedia.org/wiki/Unicode_equivalence
]]
 
function str.normalizzarecollate( frame )
 
local collation = {
local new_args = str._getParameters(frame.args, {'source', 'form'})
{ '[áàăắằẵẳâấầẫẩǎåǻäǟãȧǡąāảȁȃạặậḁⱥᶏᴂɐᶐɒ]' , 'a'},
{'[ÁÀĂẮẰẴẲÂẤẦẪẨǍÅÅǺÄǞÃȦǠĄĀẢȀȂẠẶẬḀȺᴁ]', 'A'},
{'[ḃḅḇbƀɓ]', 'b'},
{'[ḂḄḆɃ]', 'B'},
{'[ćĉčċçḉȼƈ]', 'c'},
{'[ĆĈČĊÇḈȻƇ]', 'C'},
{'[đḍḓḏðď]', 'd'},
{'[ĐḌḒḎÐĎ]', 'D'},
{'[éèèêếềễểěëẽėȩḝęēḗḕẻȅȇẹệḙḛǝ]', 'e'},
{'[ÉÈÈÊẾỀỄỂĚËẼĖȨḜĘĒḖḔẺȄȆẸỆḘḚƎ]', 'E'},
{'[ḟⅎ]', 'f'},
{'[ḞℲ]', 'F'},
{'[ǵğĝǧġģḡᵹɠ]', 'g'},
{'[ǴĞĜǦĠĢḠƓ]', 'G'},
{'[ĥȟḧḣḩħḥḫẖ]', 'h'},
{'[ĤȞḦḢḨĦḤḪ]', 'H'},
{'[íìĭîǐïḯĩįīỉȉȋịḭı]', 'i'},
{'[ÍÌĬÎǏÏḮĨĮĪỈȈȊỊḬİ]', 'I'},
{'[ĵǰ]', 'j'},
{'[Ĵ]', 'J'},
{'[ḱǩķ]', 'k'},
{'[ḰǨĶ]', 'K'},
{'[ĺľļłḷḹḽḻl·l·ŀƚⱡ]', 'l'},
{'[ĹĽĻŁḶḸḼḺL·L·ĿȽⱠ]', 'L'},
{'[ḿṁṃ]', 'm'},
{'[ḾṀṂ]', 'M'},
{'[ńǹňñṅņṇṋṉ]', 'n'},
{'[ŃǸŇÑṄŅṆṊṈ]', 'N'},
{'[óòŏôốồỗổǒöȫőõṍṏȭȯȱøǿǫǭōṓṑỏȍȏơớờỡởợọộ]', 'o'},
{'[ÓÒŎÔỐỒỖỔǑÖȪŐÕṌṎȬȮȰØǾǪǬŌṒṐỎȌȎƠỚỜỠỞỢỌỘ]', 'O'},
{'[ṕṗ]', 'p'},
{'[ṔṖ]', 'P'},
{'[ŕřṙŗȑȓṛṝṟ]', 'r'},
{'[ŔŘṘŖȐȒṚṜṞ]', 'R'},
{'[śṥŝšṧṡşṣṩș]', 's'},
{'[ŚṤŜŠṦṠŞṢṨȘ]', 'S'},
{'[ťṫẗţṭțṱṯ]', 't'},
{'[ŤṪŢṬȚṰṮ]', 'T'},
{'[úùŭûǔůüǘǜǚǖűũṹųūṻủȕȗưứừữửựụṳṷṵʉ]', 'u'},
{'[ÚÙŬÛǓŮÜǗǛǙǕŰŨṸŲŪṺỦȔȖƯỨỪỮỬỰỤṲṶṴɄ]', 'U'},
{'[ṽṿʋ]', 'v'},
{'[ṼṾƲ]', 'V'},
{'[ẃẁŵẘẅẇẉⱳ]', 'w'},
{'[ẂẀŴ̊ẄẆẈⱲ]', 'W'},
{'[ýỳŷẙÿỹẏȳỷỵɏƴ]', 'y'},
{'[ÝỲŶ̊ŸỸẎȲỶỴɎƳ]', 'Y'},
{'[źẑžżẓẕƶȥʐⱬ]', 'z'},
{'[ŹẐŽŻẒẔƵȤʐⱫ]', 'Z'},
}
 
local new_args = str._getParameters(frame.args, {'source'})
local source = new_args['source'] or ''
--local formsource = new_args['enctype'] or 'NFC'mw.ustring.toNFC(source)
 
if form == 'NFC' then
for _, el in ipairs(collation) do
return mw.ustring.toNFC(source, form)
source = mw.ustring.gsub( source, el[1], el[2])
elseif form == 'NFD' then
end
return mw.ustring.toNFD(source, form)
return source
end
 
--[[
Funzione per estrarre da un titolo la stringa adatta all'ordinamento alfabetico.
]]
 
function str.titolo_alfa(frame)
-- Evito "I", "A", "Die"... che darebbero molte false corrispondenze in lingue diverse
local articoli = {"Il ", "Lo ", "La ", "L'", "Gli ", "Le ", "Un ", "Uno ", "Una ", "Un'", "The ", "An ", "Les ", "El ", "Los ", "Las ", "Der ", "Das "}
 
local source = frame.args[1]
if not source or source == '' then
source = mw.title.getCurrentTitle().text
end
if not source or source == '' then
return ''
end
source = mw.ustring.gsub(source, ' %(.*%)$', '')
source = str.collate( { args = { source } } )
source = mw.ustring.gsub(source, "^['%(%.¡¿ ]*", '')
for _,article in ipairs(articoli) do
source = mw.ustring.gsub(source, "^(" .. article .. ")(.*)$", "%2, %1")
end
source = mw.ustring.gsub(source, '^%l', mw.ustring.upper)
return str._error( 'Valore del parametro form "' .. form .. '" non valido')
source = mw.text.trim(source)
return source
end
 
Line 544 ⟶ 626:
pre: eventuale stringa che precede l'unione delle stringhe
post: eventuale stringa che segue l'unione delle stringhe
indentazione: una stringa da ripetere cumulativamente per ogni messaggio (tipicamente '&nbsp')
lista: se valorizzata a:
'puntata' imposta i parametri per una lista puntata
'ordinata' imposta i aprametriparametri per una lista ordinata
'infobox' imposta l'unione come una lista, eccetto che nel caso ci sia
solo un elemento
Line 588 ⟶ 671:
local index = tonumber(base_args.Nmin) or tonumber(base_args.nmin) or base_index
local Nobbligatori = tonumber(base_args.Nobbligatori) or tonumber(base_args.nobbligatori) or base_index-1
local indentazione = base_args.indentazione or nil
local args = frame:getParent().args
-- estraggo il primo valore
Line 620 ⟶ 704:
if #elements == 0 then return '' end
-- carico separatori, congiunzione, pre e postazione
local pre, post, separatore, congiunzione, indent = '', '', '', '', ''
local lista = base_args.lista or ''
if lista == 'puntata' or (lista =='infobox' and #elements >1) then
Line 637 ⟶ 721:
separatore = base_args.separatore or ''
congiunzione = base_args.congiunzione or separatore
end
if indentazione then
local current_indentazione = indentazione
for i, msg in ipairs(elements) do
elements[i] = current_indentazione .. elements[i]
current_indentazione = current_indentazione .. indentazione
end
end
return pre .. mw.text.listToText(elements, separatore, congiunzione) .. post
Line 732 ⟶ 823:
return pre .. mw.text.listToText(elements, separatore, congiunzione) .. post
end
 
 
--[[