Content deleted Content added
Made luaname() also use the new logic; substantial perf hit |
Try to handle strings more efficiently |
||
Line 65:
"PROVINCE OF","PROVINCE","TERRITORY"
}
local patterns = {
["
["|.+"]="",
["%(.-%)"]="",
["%..*"]="",
["^THE "]="",
["%_"]=" ",
["%d%d?%d?PX"]="",
}
text = mw.ustring.upper(text) -- Case insensitivity
text = mw.ustring.gsub(text,"[À-Ý]",accents) -- Deaccent▼
local capture = string.match(text, '[ -~]*'); -- Keep only ASCII printable characters
if capture ~= text then -- If same there are no Unicode characters
end▼
for pattern,value in pairs(patterns) do -- Follow patterns
end
for _,words in pairs(remove) do -- Remove unneeded words
end
-- Hyphen-sensitive
text =
return text
end
Line 100 ⟶ 109:
function p.luacode(args)
local hyphensplitresult = p.luacodeimpl(args) -- Prioritize splitting on hyphen (subdivision)▼
local hyphenPos = string.find(a1 or '', '-', 1, true)
if not hyphenPos then --No hyphen
return p.luacodeimpl(args)
end▼
args[1] = string.sub(a1, 1, hyphenPos-1) --Try splitting on hyphen
args[2] = string.sub(a1, hyphenPos+1)
if hyphensplitresult ~= nil and hyphensplitresult ~= '' then
return hyphensplitresult
end
▲ end
end
function p.luacodeimpl(args
local country, subdivision = args[1], args[2]
▲ end
▲ if country then country = p.strip(country) end
▲ if subdivision then subdivision = p.strip(subdivision) end
if args["codetype"]=="3" then
args["codetype"]="alpha3"
end
▲ local eot = args.error or ""
local catnocountry = (args.nocat and args.nocat == 'true') and ''
Line 207 ⟶ 211:
local code2 = ''
if hyphenPos ~= nil then
code1 = string.sub(code1, 1, hyphenPos-1)
end
if string.
if code2=="" then --3166-1 alpha-2 code
if data[code1] then
Line 261 ⟶ 267:
targs[1] = args[1] or ''
for i, v in pairs(args) do
if i == 'country' and not
local country = v
local k, region = 1, ''
|