Module:Sandbox/Erutuon: Difference between revisions

Content deleted Content added
other type of tag not supported
place variant tags in array if there is more than one
Line 356:
end
 
local parsed_subtags_mt = {}
parsed_subtags_mt. __index = parsed_subtags_mt{
throw = function (self, error, index)
setmetatable(parsed_subtags_mt, parsed_subtags_mt)
self.error = error
self.invalid = table.concat(self.input, "-", index)
return self:remove_unnecessary_fields()
end,
remove_unnecessary_fields = function (self)
-- Only useful internally.
self.input = nil
return setmetatable(self, nil)
end,
}
}
 
function setmetatable(parsed_subtags_mt:throw(error, index){
__call = function (self, input)
self.error = error
return setmetatable({ input = input }, self)
self.invalid = table.concat(self.input, "-", index)
end
return self:remove_unnecessary_fields()
})
end
 
function parsed_subtags_mt:remove_unnecessary_fields()
-- Only useful internally.
self.input = nil
return setmetatable(self, nil)
end
 
function parsed_subtags_mt:__call(input)
return setmetatable({ input = input }, self)
end
 
Line 393 ⟶ 395:
-- are not needed on Wikipedia. Does not recognize "grandfathered" tags.
-- https://www.rfc-editor.org/rfc/rfc6067.txt, https://tools.ietf.org/html/bcp47
 
-- Only checks that the syntax is correct, not that the values are valid. For
-- instance, does not check that a language code actually exists.
function p.parse_IETF(tag)
if type(tag) ~= "string" or tag == "" then
Line 447 ⟶ 452:
type = subtag_info[index].type
matched = true
-- There can be multiple "variant" subtags (and "extension"
-- subtags, if those are added)
if type ~= "variant" then
index = index + 1
end
break
end
Line 460 ⟶ 470:
if type then
if parsed_subtags[type] = subtagthen
parsed_subtags[type] = { parsed_subtags[type] }
table.insert(parsed_subtags[type], subtag)
else
parsed_subtags[type] = subtag
end
last_matched_subtag_i = subtag_i
matched_count = matched_count + 1