Module:Sandbox/Erutuon: Difference between revisions

Content deleted Content added
check length of private-use subtag; make "throw" method returnable
private-use subtag can have multiple following subtags not introduced separately by "x"?
Line 466:
-- Not all potential subtags were matched. Check for private-use subtags.
-- https://tools.ietf.org/html/bcp47#section-2.2.7
-- Private-use subtags consist of "x-" followed by 1one toor 8more alphanumeric characters.subtags
local private_use_tag_start_indices = {}
-- consisting of 1 to 8 alphanumeric characters.
for subtag_i = last_matched_subtag_i + 1, #potential_subtags do
-- Alphanumericity has already been checked.
if potential_subtags[subtag_ilast_matched_subtag_i + 1] == "x" then
table.insert(private_use_tag_start_indices, subtag_i)
-- Check length of all following subtags.
end
for subtag_ii = last_matched_subtag_i + 1, #potential_subtags do
end
local subtaglength = table.concat(#potential_subtags, "-",[i]
if not private_use_tag_start_indices[1] then
return parsed_subtags:throw("invalid subtag", last_matched_subtag_i + 1)
if not (31 <= #subtaglength and #subtaglength <= 108) then -- "u-x" - "u-xxxxxxxx"
end
return parsed_subtags
return parsed_subtags :throw("length of private-use subtag out of range",
for i, subtag_index in pairs(private_use_tag_start_indices) do
last_matched_subtag_i + 1)
local next_subtag_index = private_use_tag_start_indices[i + 1] or #potential_subtags + 1
end
-- Private-use subtags consist of "x-" followed by 1 to 8 alphanumeric characters.
if next_subtag_index - subtag_index ~= 2 then
return parsed_subtags:throw("invalid subtag", subtag_index)
end
parsed_subtags.private_use = parsed_subtagstable.private_useconcat(potential_subtags, or {}"-",
-- Generate private_use table only if needed.
last_matched_subtag_i + 1)
parsed_subtags.private_use = parsed_subtags.private_use or {}
else
local subtag = table.concat(potential_subtags, "-",
return parsed_subtags:throw("invalid subtag", last_matched_subtag_i + 1)
subtag_index,
last_matched_subtag_i + 1)
private_use_tag_start_indices[i + 1]
and private_use_tag_start_indices[i + 1] - 1)
if not (3 <= #subtag and #subtag <= 10) then -- "u-x" - "u-xxxxxxxx"
return parsed_subtags:throw("length of private-use subtag out of range",
private_use_tag_start_indices[i + 1])
end
table.insert(parsed_subtags.private_use, subtag)
end
end