Content deleted Content added
m error in throwing invalid character error |
error if no subtags follow x |
||
Line 358:
local parsed_subtags_mt = {}
parsed_subtags_mt.__index = parsed_subtags_mt
setmetatable(parsed_subtags_mt, parsed_subtags_mt)
function parsed_subtags_mt:throw(error, index)
self.error = error
Line 363 ⟶ 365:
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 378 ⟶ 385:
-- Returns nil if tag is not a string or empty.
-- Else returns a table with a map of subtag type to subtag for all subtags that
-- were parsed.
-- If there was an error, returns an "error" field with a description of the --
--
-- Does not recognize "extension" tags, such as those introduced by "u" and
-- described here, as they are not needed on Wikipedia:
Line 397 ⟶ 406:
-- "invalid" is the portion of the tag after the last valid subtag (minus a
-- hyphen).
local potential_subtags = mw.text.split(tag, "-")▼
local matched_count = 0
▲ local potential_subtags = mw.text.split(tag, "-")
-- Language tags probably only contain ASCII alphabetic and numerical
Line 470 ⟶ 476:
if potential_subtags[last_matched_subtag_i + 1] == "x" then
-- Check length of all following subtags.
return parsed_subtags:throw("empty private-use subtag",
last_matched_subtag_i + 1)
end
for i = last_matched_subtag_i + 2, #potential_subtags do
local length = #potential_subtags[i]
|