Content deleted Content added
remove wide log entry |
"scripts in block" function |
||
Line 2:
local Unicode_data = require 'Module:Unicode data'
if type(level) == number then
return error(string.format(...), level + 1)
else -- level is actually the format string.
return error(string.format(level, ...), 2)
end
end
local Latn_pattern = table.concat {
Line 51 ⟶ 59:
setmetatable(script_to_count_mt, script_to_count_mt)
-- Uses an iterator (such as mw.ustring.gcodepoint) that generates a codepoint
▲local function show_scripts(str)
-- each time it is called with an optional state and another value.
local function show_scripts(iterator, state, value)
local script_to_count = script_to_count_mt()
for codepoint in
local script = Unicode_data.lookup_script(codepoint)
script_to_count[script] = script_to_count[script] + 1
Line 101 ⟶ 111:
:format(expanded_pattern
:gsub('^%s*', ''), -- Remove initial '\n ' to avoid creating unwanted pre element.
show_scripts(mw.ustring.gcodepoint(expanded_pattern)))
end
function p.scripts_in_block(frame)
local block_name = frame.args[1]
or error("Parameter 1 is required")
local low, high = Unicode_data.get_block_range(block_name)
if not low then
errorf("No block '%s' could be found", block_name)
end
return ("%s: %s"):format(block_name, show_scripts(fun.range(low, high)))
end
|