Module:User:Erutuon/wrong script

local export = {}

setmetatable(_G, { __index = function (self, k)	if k == "Unicode_data" then		local val = require "Module:Unicode data"		self[k] = val		return val	end end })

local function unique_matches(pattern, text) local matches = {} for match in text:gmatch(pattern) do		matches[match] = true end local list = require "Module:array" for match in pairs(matches) do		list:insert(match) end list:sort(require "Module:collation".laborious_comp) return list end

local function superscript_edit_link(title) return "" .. tostring(mw.uri.fullUrl(title, { action = "edit" })) .. " edit " end

local function display_datum(title, jsonl) local output = require "Module:array" output:insert("; " .. title .. " " .. superscript_edit_link(title) .. "\n") for json in jsonl:gmatch "[^\n]+" do		local data = mw.text.jsonDecode(json) output:insert("* "			.. " incorrect characters in  \n") for _, incorrect in ipairs(data.incorrect) do			output:insert("** : "				.. incorrect.name .. "\n") end end return output:concat end

local function iter_chars(str) return mw.ustring.gmatch(str, "(.)") end

local function all_matches(str, pattern) local matches = require "Module:array" for match in str:gmatch(pattern) do		matches:insert(match) end return matches end

local function display_datum_new(json) local output = require "Module:array" local ok, data = pcall(mw.text.jsonDecode, json) if not ok then mw.log(json) return "" end output:insert("; " .. data.title .. " " .. superscript_edit_link(data.title) .. "\n") for _, template in ipairs(data.templates) do		output:insert("* "				.. " incorrect characters in  :") if type(template.chars) == "string" and all_matches(template.text, "%f[%a]%a+%f[%A]"):concat "" == template.chars then output:insert(" \n") else output:insert("\n") for _, incorrect in (type(template.chars) == "string" and iter_chars or ipairs)(template.chars) do				local char, name if type(incorrect) == "string" then char = incorrect name = Unicode_data.lookup_name(mw.ustring.codepoint(char)) else char = incorrect.char name = incorrect.name end output:insert("** : "					.. name .. "\n") end end end return output:concat end

local function display_data(data, new) if new then return (data:gsub("[^\n]+", display_datum_new)) else return (unique_matches( "%f[^\n%z]\t.-%f[\t%z]", data)			:concat			:gsub("\t([^\n]+)\n(.-)%f[\t%z]", display_datum)) end end

local function get_format(json) local ok, data = pcall(mw.text.jsonDecode, json) local is_new_format = ok and data.title ~= nil return is_new_format end

function export.show(frame) local title = mw.title.getCurrentTitle.fullText local data_subpage = title .. "/data" local data = frame.args[1] and mw.text.trim(mw.text.unstripNoWiki(frame.args[1])) or mw.title.new(data_subpage):getContent:match(" (.+)  ") local match = data:match("new format\n(.+)") data = match or data local is_new_format = get_format(data:match "[^\n]+") return display_data(data, is_new_format) end

return export