Content deleted Content added
faster function, though it's buggy |
|||
Line 179:
local start = frame.args[1] and tonumber(frame.args[1], 16) or 0
local ending = frame.args[2] and tonumber(frame.args[2], 16) or 0x4000
local script_data = mw.loadData "Module:Unicode data/scripts"
local singles = script_data.singles
local ranges = script_data.ranges
local counts = {}
setmetatable(counts, {
__index = {
increment = function(self, script_code, amount)
self[script_code] = (self[script_code] or 0) + (amount or 1)
end,
clear = function (self)
for _, key in ipairs(m_table.keysToList(self, false)) do
self[key] = nil
end
end,
}
})
output:insert [[
Line 185 ⟶ 203:
! block !! codepoints !! scripts
]]
for _, block in pairs(mw.loadData "Module:Unicode data/blocks") do
if codepoint > ending then break end
if
while codepoint <= block[2] do
if singles[codepoint] then
counts:increment(singles[codepoint])
codepoint = codepoint + 1
else
local range, index = Unicode_data.binary_range_search(codepoint, ranges)
if range then
local count = 0
while codepoint <= range[2] and codepoint <= block[2] do
codepoint = codepoint + 1
count = count + 1
end
counts:increment(range[3], count)
else
local count = 0
while codepoint > ranges[index][2] do
index = index + 1
end
local range = ranges[index]
while codepoint < range[1] and codepoint <= block[2] do
codepoint = codepoint + 1
count = count + 1
end
counts:increment("Zzzz", count)
end
end
end
output:insert_format([[
|-
Line 195 ⟶ 242:
| U+%04X–U+%04X
| %s
]], block[3], block[1], block[2],
table.concat(
fun.map(
function (count, script)
return ("%s (%d)"):format(script, count)
end,
m_table.sortedPairs(
counts,
function (script1, script2)
return counts[script1] > counts[script2]
end)),
", "))
end
counts:clear()
end
output:insert "|}"
|