48,355
edits
No edit summary |
No edit summary |
||
| Line 6: | Line 6: | ||
]=] | ]=] | ||
local u = | local concat = table.concat | ||
local | local insert = table.insert | ||
local ipairs = ipairs | |||
local next = next | |||
local remove = table.remove | |||
local select = select | |||
local sort = table.sort | |||
local u = require("Module:string utilities").char | |||
------------------------------------------------------------------------------------ | |||
-- | |||
-- Helper functions | |||
-- | |||
------------------------------------------------------------------------------------ | |||
-- Note: a[2] > b[2] means opens are sorted before closes if otherwise equal. | |||
local function sort_ranges(a, b) | |||
return a[1] < b[1] or a[1] == b[1] and a[2] > b[2] | |||
end | |||
-- Returns the union of two or more range tables. | |||
local function union(...) | |||
local ranges = {} | |||
for i = 1, select("#", ...) do | |||
local argt = select(i, ...) | |||
for j, v in ipairs(argt) do | |||
insert(ranges, {v, j % 2 == 1 and 1 or -1}) | |||
end | |||
end | |||
sort(ranges, sort_ranges) | |||
local ret, i = {}, 0 | |||
for _, range in ipairs(ranges) do | |||
i = i + range[2] | |||
if i == 0 and range[2] == -1 then -- close | |||
insert(ret, range[1]) | |||
elseif i == 1 and range[2] == 1 then -- open | |||
if ret[#ret] and range[1] <= ret[#ret] + 1 then | |||
remove(ret) -- merge adjacent ranges | |||
else | |||
insert(ret, range[1]) | |||
end | |||
end | |||
end | |||
return ret | |||
end | |||
-- Adds the `characters` key, which is determined by a script's `ranges` table. | |||
local function process_ranges(sc) | |||
local ranges, chars = sc.ranges, {} | |||
for i = 2, #ranges, 2 do | |||
if ranges[i] == ranges[i - 1] then | |||
insert(chars, u(ranges[i])) | |||
else | |||
insert(chars, u(ranges[i - 1])) | |||
if ranges[i] > ranges[i - 1] + 1 then | |||
insert(chars, "-") | |||
end | |||
insert(chars, u(ranges[i])) | |||
end | |||
end | |||
sc.characters = concat(chars) | |||
ranges.n = #ranges | |||
return sc | |||
end | |||
local function handle_normalization_fixes(fixes) | |||
local combiningClasses = fixes.combiningClasses | |||
if combiningClasses then | |||
local chars, i = {}, 0 | |||
for char in next, combiningClasses do | |||
i = i + 1 | |||
chars[i] = char | |||
end | |||
fixes.combiningClassCharacters = concat(chars) | |||
end | |||
return fixes | |||
end | |||
------------------------------------------------------------------------------------ | |||
-- | |||
-- Data | |||
-- | |||
------------------------------------------------------------------------------------ | |||
--Constructed languages | --Constructed languages | ||