Modulo:String/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Moroboshi (discussione | contributi)
test
rimuovo funzione incompleta e rimpiazzata da Modulo:IP validator
 
(12 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( frame.args, {'s', 'pattern', 'start', 'match', 'plain', 'nomatch'} );
local s = new_args['s'] or '';
local start = tonumber( new_args['start'] ) or 1;
Line 425 ⟶ 432:
]]
 
function _collatestr.collate(source frame )
 
local collation = {
{ '[áàăắằẵẳâấầẫẩǎåǻäǟãȧǡąāảȁȃạặậḁⱥᶏᴂɐᶐɒ]' , 'a'},
{'[ÁÀĂẮẰẴẲÂẤẦẪẨǍÅÅǺÄǞÃȦǠĄĀẢȀȂẠẶẬḀȺᴁ]', 'A'},
Line 433 ⟶ 441:
{'[ćĉčċçḉȼƈ]', 'c'},
{'[ĆĈČĊÇḈȻƇ]', 'C'},
{'[đḍḓḏðđḍḓḏðď]', 'd'},
{'[ĐḌḒḎÐĐḌḒḎÐĎ]', 'D'},
{'[éèèêếềễểěëẽėȩḝęēḗḕẻȅȇẹệḙḛǝ]', 'e'},
{'[ÉÈÈÊẾỀỄỂĚËẼĖȨḜĘĒḖḔẺȄȆẸỆḘḚƎ]', 'E'},
Line 443 ⟶ 451:
{'[ĥȟḧḣḩħḥḫẖ]', 'h'},
{'[ĤȞḦḢḨĦḤḪ]', 'H'},
{'[íìĭîǐïḯĩįīỉȉȋịḭíìĭîǐïḯĩįīỉȉȋịḭı]', 'i'},
{'[ÍÌĬÎǏÏḮĨĮĪỈȈȊỊḬÍÌĬÎǏÏḮĨĮĪỈȈȊỊḬİ]', 'I'},
{'[ĵǰ]', 'j'},
{'[Ĵ]', 'J'},
Line 458 ⟶ 466:
{'[ÓÒŎÔỐỒỖỔǑÖȪŐÕṌṎȬȮȰØǾǪǬŌṒṐỎȌȎƠỚỜỠỞỢỌỘ]', 'O'},
{'[ṕṗ]', 'p'},
{'[ṕṗṔṖ]', 'P'},
{'[ŕřṙŗȑȓṛṝṟ]', 'r'},
{'[ŔŘṘŖȐȒṚṜṞ]', 'R'},
Line 476 ⟶ 484:
{'[ŹẐŽŻẒẔƵȤʐⱫ]', '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])
Line 483 ⟶ 496:
 
--[[
Funzione per estrarre da un titolo la stringa adatta all'ordinamento alfabetico.
Funzione di interfaccia per _collate
]]
 
function str.collatetitolo_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 new_argssource = str._getParameters(frame.args, {'source'})[1]
local source = new_args['source'] or ''
--local source = mw.ustring.toNFC(source)
return _collate(source)
end
 
function p.titolo_alfa(frame)
local default_key = frame.args[1] or ''
if default_key ~= '' then
return default_key
end
local source = frame.args[2]
if not source or source == '' then
source = mw.title.getCurrentTitle().text
Line 507 ⟶ 511:
end
source = mw.ustring.gsub(source, ' %(.*%)$', '')
source = _collatestr.collate(s { args = { source } } )
source = mw.ustring.gsub(source, "^['%(%.¡¿ ]*", '')
for _,article in ipairs(articoli) do
source = mw.ustring.gsub(source, '^(.)', mw.ustring.upper())
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 617 ⟶ 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 661 ⟶ 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 693 ⟶ 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 710 ⟶ 721:
separatore = base_args.separatore or ''
congiunzione = base_args.congiunzione or separatore
end
if default_key ~= ''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 805 ⟶ 823:
return pre .. mw.text.listToText(elements, separatore, congiunzione) .. post
end
 
 
--[[