--
p=
----------------------------< P A R S E _ I E T F >----------------------------------------------------------
local function parse_ietf (source, pattern_table) local element = for _, pattern in ipairs (pattern_table) do element[1], element[2], element[3], element[4] = source:match (pattern); if element[1] then return element[1], element[2], element[3], element[4]; end endend
--script=, |region=, and |variant= are supported (not supported in because those parameters are superfluous to the IETF subtags in |code=)
returns six values. Valid parts are returned as themselves; omitted parts are returned as empty strings, invalidparts are returned as nil; the sixth returned item is an error message (if an error detected) or nil.
see http://www.rfc-editor.org/rfc/bcp/bcp47.txt section 2.1
function p.get_ietf_parts (frame) local code; local script; local region; local variant; local private; local source = frame.args[1]; -- debug
local csrv_patterns = local crv_patterns = local csv_patterns = local csr_patterns = local cv_patterns = local cr_patterns =
local cs_patterns =
local cp_patterns = local c_patterns =
-- if not is_set (source) then-- return nil, nil, nil, nil, nil, 'missing language tag'; -- end
local _, element_count = source:gsub ('%-', )
if 0
element_count then while true do -- spoof a loop so that we can use break to escape when a match is made code, script = source:match (cs_patterns[1]); -- done this way because there is only one pattern if code then break; end code, region = parse_ietf (source, cr_patterns); if code then break; end
code, variant = parse_ietf (source, cv_patterns); break; -- terminal exit from loop spoof end elseif 2
code, region, variant = parse_ietf (source, crv_patterns); if code then break; end
code, private = source:match (cp_patterns[1]); -- the -x- counts as an element but we don't return that; done this way because there is only one pattern break; -- terminal exit from loop spoof end elseif 3
end
return p;