Module:Sandbox/Erutuon: Difference between revisions

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 containsmay contain the special fields "matched_countinvalid" and, "invaliderror".
-- "matched_count" tracks the number of subtags, "error" indicates why the
-- 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
parsed_subtags.matched_count = parsed_subtags.matched_count + 1
elseif not subtag_info[index] then
break
Line 432 ⟶ 439:
end
if #subtags > parsed_subtags.matched_count then
-- 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
parsed_subtags.matched_count = parsed_subtags.matched_count + 1 -- not used after this point
else
parsed_subtags.invalid = suffix