Module:Sandbox/Erutuon: Difference between revisions

Content deleted Content added
moved some stuff to Module:Sandbox/Erutuon/Unicode
function to print data module for "default ignorable" property
 
(10 intermediate revisions by 2 users not shown)
Line 1:
local p = {}
 
function p.show(frame)
local page = frame.args[1] or "User:Erutuon/Unicode/DerivedCoreProperties.txt"
local text = assert(mw.title.new(page):getContent())
local defaultIgnorable = text
:match("Derived Property: Default_Ignorable_Code_Point.-(%f[^\n]%x%x%x%x.-)%s*\n# Total code points")
local singles, ranges = {}, {}
for codePoint1, codePoint2 in defaultIgnorable:gmatch("%f[^\n%z](%x+)%.?%.?(%x*)") do
codePoint1, codePoint2 = tonumber(codePoint1, 16), tonumber(codePoint2, 16)
local lastRange = ranges[#ranges]
if lastRange and lastRange[2] == codePoint1 - 1 then
lastRange[2] = codePoint2 or codePoint1
else
if not codePoint2 then
singles[codePoint1] = true
else
table.insert(ranges, { codePoint1, codePoint2 })
end
end
end
local template = [[
local data = {}
 
data.defaultIgnorable = {
singles = {
...
},
ranges = {
...
},
}
 
return data
]]
 
local Array = require "Module:array"
local printedRanges = Array()
for _, range in ipairs(ranges) do
local low, high, script_code = unpack(range)
printedRanges:insert(('\t\t{ 0x%05X, 0x%05X },'):format(low, high))
end
local printedSingles = Array()
for codepoint in require 'Module:TableTools'.sortedPairs(singles) do
printedSingles:insert(('\t\t[0x%05X] = true,'):format(codepoint))
end
local data = template
:gsub('%.%.%.', printedSingles:concat('\n'), 1)
:gsub('%.%.%.', printedRanges:concat('\n'), 1)
return data
end
 
local Unicode_data = require "Module:Unicode data/sandbox"
local fun = require "Module:fun"
local m_table = require "Module:TableTableTools"
 
local function errorf(level, ...)
if type(level) == "number" then
return error(string.format(...), level + 1)
else -- level is actually the format string.
Line 366 ⟶ 421:
mw.log("Invalid private-use subtag in", parsed_subtags:get_tag())
end
end
 
function p.show_COinS(frame)
local ref = frame.args[1]
local tag = ref:match('<span [^>]*class="Z3988"[^>]*>')
local data = tag:match('title="(.-)"')
local vals = {}
for item in mw.text.gsplit(data, "&") do
local key, value = item:match("(.-)=(.*)")
vals[key] = mw.uri.decode(value)
end
return ref .. "\n\n" .. table.concat(
require "Module:fun".mapIter(
function (value, key)
return ("%s: %s"):format(key, value)
end,
m_table.sortedPairs(
vals)),
", ")
end