Module:Sandbox/Erutuon: Difference between revisions

Content deleted Content added
m gah
add chars_in_scripts_in_block function
Line 78:
end)),
", ")
end
 
local function get_chars_in_scripts(iterator, state, value)
local script_to_char_set = {}
for codepoint in iterator, state, value do
local script = Unicode_data.lookup_script(get_codepoint(char)codepoint)
script_to_char_set[script] = script_to_char_set[script] or {}
script_to_char_set[script][charcodepoint] = true
end
return script_to_char_set
end
 
local function print_char_set_map(script_to_char_set, format, separator)
format = format or "%s: %s"
separator = separator or "\n"
return table.concat(
fun.mapIter(
function (char_set, script)
local char_list = m_tablefun.keysToListmapIter(char_set)
function (_, codepoint)
return mw.ustring.char(codepoint)
end,
m_table.sortedPairs(script_to_char_setchar_set)),
return ("%s: %s"format):format(script, mw.text.nowiki(table.concat(char_list)))
end,
m_table.sortedPairs(script_to_char_set)),
separator)
end
 
Line 88 ⟶ 116:
return expand_range(char1, char2)
end)
local script_to_char_set = {}
for char in expanded_pattern:gmatch "[%z\1-\127\194-\244][\128-\191]*" do
local script = Unicode_data.lookup_script(get_codepoint(char))
script_to_char_set[script] = script_to_char_set[script] or {}
script_to_char_set[script][char] = true
end
--[[
mw.log(
print_char_set_map(
table.concat(
get_chars_in_scripts(
fun.mapIter(
for char in expanded_pattern:gmatch "[%z\1-\127\194-\244][\128-\191]*" do)))
function (char_set, script)
local char_list = m_table.keysToList(char_set)
return ("%s: %s"):format(script, table.concat(char_list))
end,
m_table.sortedPairs(script_to_char_set)),
'\n'))
--]]
Line 112 ⟶ 128:
:gsub('^%s*', ''), -- Remove initial '\n ' to avoid creating unwanted pre element.
show_scripts(mw.ustring.gcodepoint(expanded_pattern)))
end
 
local function get_block_info_from_arg(args, arg)
local block_name = args[1]
or errorerrorf("Parameter 1%s is required", tostring(arg))
local low, highblock_info = Unicode_data.get_block_rangeget_block_info(block_name)
or errorf("NoThe block '%s' could be found", block_name)
return block_info
end
 
local function get_boolean_from_arg(args, arg)
localreturn show_block_name = frame.args[2arg] and require "Module:Yesno" (frame.args[2arg])
end
 
function p.scripts_in_block(frame)
local block_nameblock_info = get_block_info_from_arg(frame.args[, 1])
local show_block_name = get_boolean_from_arg(frame.args, 2)
or error("Parameter 1 is required")
local script_list = show_scripts(fun.range(block_info[1], block_info[2]))
local low, high = Unicode_data.get_block_range(block_name)
if not lowshow_block_name then
return ("%s: %s"):format(block_info[3], script_list)
errorf("No block '%s' could be found", block_name)
else
return script_list
end
end
local show_block_name = frame.args[2] and require "Module:Yesno" (frame.args[2])
 
function p.chars_in_scripts_in_block(frame)
local block_info = get_block_info_from_arg(frame.args, 1)
local show_block_name = get_boolean_from_arg(frame.args, 2)
local script_char_set_map = print_char_set_map(
get_chars_in_scripts(fun.range(block_info[1], block_info[2])))
if show_block_name then
return ("%s: %s"):format(block_nameblock_info[3], show_scripts(fun.range(low, high))script_char_set_map)
else
return script_char_set_map
return ("%s"):format(show_scripts(fun.range(low, high)))
end
end