Difference between revisions of "Module:Sandbox/Erutuon/scripts"
< Module:Sandbox | Erutuon
Jump to navigation
Jump to search
blackwiki>Erutuon (function for showing characters belonging to different scripts in a string) |
blackwiki>Erutuon (fixed) |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
| − | local cp_to_sc = require 'Module: | + | local cp_to_sc = require 'Module:Language/scripts'.codepointToScript |
local function in_array(arr, val) | local function in_array(arr, val) | ||
| Line 12: | Line 12: | ||
end | end | ||
| − | function | + | local function mapIter(func, iter, iterable, initVal) |
local array = {} | local array = {} | ||
local i = 0 | local i = 0 | ||
| Line 37: | Line 37: | ||
end | end | ||
| − | return mapIter( | + | return table.concat( |
| − | + | mapIter( | |
| − | + | function (codepoints, script) | |
| − | + | return ('\n* %s: %s') | |
| − | + | :format(script, table.concat(codepoints)) | |
| − | + | end, | |
| + | pairs(scripts))) | ||
| + | end | ||
| + | |||
| + | function p.main(frame) | ||
| + | return p.list_chars_in_script(frame.args[1]) | ||
end | end | ||
return p | return p | ||
Revision as of 19:34, 12 April 2018
- Latn: oó
- Zyyy: *,.[]
- Grek: ΔΖΚΣάίαδεζθικλμνοπρςστυωύϝἀἇἧἱὄὐὰὴὸῖῶ
local p = {}
local cp_to_sc = require 'Module:Language/scripts'.codepointToScript
local function in_array(arr, val)
for i, v in ipairs(arr) do
if v == val then
return true
end
end
return false
end
local function mapIter(func, iter, iterable, initVal)
local array = {}
local i = 0
for x, y in iter, iterable, initVal do
i = i + 1
array[i] = func(y, x, iterable)
end
return array
end
function p.list_chars_in_script(str)
local scripts = {}
for codepoint in mw.ustring.gcodepoint(str) do
local script = cp_to_sc(codepoint)
scripts[script] = scripts[script] or {}
local char = mw.ustring.char(codepoint)
if not in_array(scripts[script], char) then
table.insert(scripts[script], char)
end
end
for script, characters in pairs(scripts) do
table.sort(characters)
end
return table.concat(
mapIter(
function (codepoints, script)
return ('\n* %s: %s')
:format(script, table.concat(codepoints))
end,
pairs(scripts)))
end
function p.main(frame)
return p.list_chars_in_script(frame.args[1])
end
return p