Module:ISO 3166: Difference between revisions

Jump to navigation Jump to search
Sharing "strip" function
(Display name options)
(Sharing "strip" function)
Line 11:
return mw.html.create("span"):addClass("error"):wikitext("Error in [[Module:ISO 3166]]: "..errortext)
end
end
 
local function strip(text)
text = mw.ustring.upper(text) --Case insensitivity
text = string.gsub(text,"^THE ","") --Remove definite article
text = string.gsub(text,"[%s%-%,%.%(%)%/%\']","") --Remove spacing and punctuation
local accents = {["À"]="A",["Á"]="A",["Â"]="A",["Ã"]="A",["Ä"]="A",["Å"]="A",["Ç"]="C",["È"]="E",["É"]="E",
["Ê"]="E",["Ë"]="E",["Ì"]="I",["Í"]="I",["Î"]="I",["Ï"]="I",["Ñ"]="N",["Ò"]="O",["Ó"]="O",
["Ô"]="O",["Õ"]="O",["Ö"]="O",["Ø"]="O",["Ù"]="U",["Ú"]="U",["Û"]="U",["Ü"]="U",["Ý"]="Y"}
text = mw.ustring.gsub(text,"[À-Ý]",accents) --Deaccent
return text
end
 
local function findname(code,cdata,qry)
local sqry = p.strip(qry)
if cdata["name"] and sqry==p.strip(cdata["name"])
or cdata["isoname"] and sqry==p.strip(cdata["isoname"])
or sqry==code or sqry==cdata["alpha3"] or sqry==cdata["numeric"]
then
Line 33 ⟶ 22:
end
for _,tname in pairs(cdata["altnames"] or {}) do
if sqry==p.strip(tname) then
return true
end
end
return false
end
 
local function p.strip(text)
text = mw.ustring.upper(text) --Case insensitivity
text = string.gsub(text,"^THE ","") --Remove definite article
text = string.gsub(text,"[%s%-%,%.%(%)%/%\']","") --Remove spacing and punctuation
local accents = {["À"]="A",["Á"]="A",["Â"]="A",["Ã"]="A",["Ä"]="A",["Å"]="A",["Ç"]="C",["È"]="E",["É"]="E",
["Ê"]="E",["Ë"]="E",["Ì"]="I",["Í"]="I",["Î"]="I",["Ï"]="I",["Ñ"]="N",["Ò"]="O",["Ó"]="O",
["Ô"]="O",["Õ"]="O",["Ö"]="O",["Ø"]="O",["Ù"]="U",["Ú"]="U",["Û"]="U",["Ü"]="U",["Ý"]="Y"}
text = mw.ustring.gsub(text,"[À-Ý]",accents) --Deaccent
return text
end
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu