Content deleted Content added
m shorter |
matched_count maybe not useful except internally |
||
Line 358:
-- A previous draft, in [[Module:Lang/sandbox]]:
-- https://en.wikipedia.org/w/index.php?oldid=812819217
-- Based on https://www.w3.org/International/articles/language-tags/.
function p.parse_IETF(tag)
if not tag or tag == "" or type(tag) ~= "string" then
Line 363 ⟶ 365:
end
-- This
--
-- tag is invalid (if applicable).
-- All other fields are subtags, and they appear in the tag in the following
Line 371 ⟶ 373:
-- "invalid" is the portion of the tag after the last valid subtag (minus a
-- hyphen).
local parsed_subtags = {}
local matched_count = 0 -- Language tags probably only contain ASCII alphabetic and numerical
-- characters and hyphen-minus, though I am not sure if this is explicitly
-- stated in the spec.
if not tag:find '^[A-Za-z0-9-]+$' then
parsed_subtags.error = "invalid characters"
Line 426 ⟶ 433:
parsed_subtags[type] = subtag
last_matched_subtag_i = subtag_i
elseif not subtag_info[index] then
break
Line 432 ⟶ 439:
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) is a
Line 440 ⟶ 447:
if suffix:sub(1, 1) == "x" then
parsed_subtags.private_use = suffix
else
parsed_subtags.invalid = suffix
|