Content deleted Content added
finished, I guess |
functional now |
||
Line 360:
function p.parse_IETF(tag)
local subtags = mw.text.split(tag, "-")
local parsed_subtags = {}▼
-- This contains the special fields "count" and "invalid".
-- These patterns are checked in order. That is, the 'language' subtag must▼
-- "count" tracks the number of subtags, "invalid" indicates that at least
-- be before the 'script' subtag. However, any of the subtags can be skipped.▼
-- one unparsable subtag was found.
-- That is, a tag may contain a 'language' subtag, no 'script' subtag and▼
--
▲ local parsed_subtags = { count = 0, invalid = false }
-- then a "region" subtag.
-- If the full list of subtags has been iterated over, the
local subtag_info = { -- can be put in data module
{
-- include extlang?
{
{
{
type =
}
}
Line 385 ⟶ 390:
local matched = false
while not matched do
if not subtag_info[index] then▼
break▼
end▼
▲ -- Check each pattern in current item in subtag_info.
for _, pattern in ipairs(subtag_info[index]) do
if subtag:find(
type = subtag_info[index].type
matched = true
Line 398 ⟶ 400:
if not matched then -- Go to next item in subtag_info.
index = index + 1
▲ if not subtag_info[index] then
▲ break
▲ end
end
end
if type then
parsed_subtags[type] = subtag
last_matched_subtag_i = subtag_i
parsed_subtags.count = parsed_subtags.count + 1
elseif not subtag_info[index] then
break
Line 408 ⟶ 416:
end
if #subtags >
-- Not all subtags were matched. The unmatched tail end of the tag
-- (after the subtag at the index last_matched_subtag_i)
-- private-use subtag if it starts with "x". Otherwise, the tag is
-- invalid.
if subtags[last_matched_subtag_i + 1] ==
parsed_subtags.private_use =
table.concat(subtags,
else
parsed_subtags.invalid = true
|