Modulo:String/sandbox: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
completo fino alla z |
rimuovo funzione incompleta e rimpiazzata da Modulo:IP validator |
||
(13 versioni intermedie di 2 utenti non mostrate) | |||
Riga 148:
]]
function str.match(
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(
local s = new_args['s'] or '';
local start = tonumber( new_args['start'] ) or 1;
Line 420 ⟶ 427:
return mw.uri.decode(source, enc_type)
end
▲--[[
▲]]
--[[
Line 431 ⟶ 434:
function str.collate( frame )
local collation = {
{ '[áàăắằẵẳâấầẫẩǎåǻäǟãȧǡąāảȁȃạặậḁⱥᶏᴂɐᶐɒ]' , 'a'},
{'[ÁÀĂẮẰẴẲÂẤẦẪẨǍÅÅǺÄǞÃȦǠĄĀẢȀȂẠẶẬḀȺᴁ]', 'A'},
Line 438 ⟶ 441:
{'[ćĉčċçḉȼƈ]', 'c'},
{'[ĆĈČĊÇḈȻƇ]', 'C'},
{'[
{'[
{'[éèèêếềễểěëẽėȩḝęēḗḕẻȅȇẹệḙḛǝ]', 'e'},
{'[ÉÈÈÊẾỀỄỂĚËẼĖȨḜĘĒḖḔẺȄȆẸỆḘḚƎ]', 'E'},
Line 448 ⟶ 451:
{'[ĥȟḧḣḩħḥḫẖ]', 'h'},
{'[ĤȞḦḢḨĦḤḪ]', 'H'},
{'[
{'[
{'[ĵǰ]', 'j'},
{'[Ĵ]', 'J'},
{'[ḱǩķ]', 'k'},
{'[ḰǨĶ]', 'K'},
{'[ĺľļłḷḹḽḻl·l·ŀƚⱡ]', 'l'},
{'[ĹĽĻŁḶḸḼḺL·L·ĿȽⱠ]', 'L'},
{'[ḿṁṃ]', 'm'},
{'[ḾṀṂ]', 'M'},
{'[ńǹňñṅņṇṋṉ]', 'n'},
{'[ŃǸŇÑṄŅṆṊṈ]', 'N'},
{'[óòŏôốồỗổǒöȫőõṍṏȭȯȱøǿǫǭōṓṑỏȍȏơớờỡởợọộ]', 'o'},
{'[ÓÒŎÔỐỒỖỔǑÖȪŐÕṌṎȬȮȰØǾǪǬŌṒṐỎȌȎƠỚỜỠỞỢỌỘ]', 'O'},
{'[ṕṗ]', '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 source = mw.ustring.toNFC(source)
for _, el in ipairs(collation) do
source = mw.ustring.gsub( source, el[1], el[2])
end
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)
source = mw.text.trim(source)
return source
end
Line 597 ⟶ 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 ' ')
lista: se valorizzata a:
'puntata' imposta i parametri per una lista puntata
'ordinata' imposta i
'infobox' imposta l'unione come una lista, eccetto che nel caso ci sia
solo un elemento
Line 641 ⟶ 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 673 ⟶ 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 690 ⟶ 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 785 ⟶ 823:
return pre .. mw.text.listToText(elements, separatore, congiunzione) .. post
end
--[[
|