Module:User:Erutuon/titles by script

local export = {}

local Array = require "Module:array"

local floor = math.floor local function binary_range_search(codepoint, ranges) local low, mid, high low, high = 1, #ranges while low <= high do		mid = floor((low + high) / 2) local range = ranges[mid] if codepoint < range[1] then high = mid - 1 elseif codepoint <= range[2] then return range, mid else low = mid + 1 end end return nil, mid end

local script_data = require "Module:User:Erutuon/titles by script/data" local function lookup_script(codepoint) if script_data.singles[codepoint] then return script_data.singles[codepoint] else local range = binary_range_search(codepoint, script_data.ranges) if range then return range[3] else return "Zzzz" end end end

local function excluded_title(title_object) local title = title_object.fullText return not (title:find "кварк"		or title:find "витамин" or title:find "^Unsupported titles/") and title_object.exists and not title_object.isRedirect end

local function make_table(caption) local titles = mw.title.new(mw.title.getCurrentTitle.fullText .. "/data") :getContent:match("%s* %s*(.-)%s*  %s*") local output = Array output:insert class="wikitable sortable" if caption then output:insert("|+ " .. caption .. "\n") end output:insert ! title !! characters local lookup_name = require "Module:Unicode data".lookup_name for title in mw.text.gsplit(titles, "\n") do		local characters_by_script = { Latn = Array, Cyrl = Array, Grek = Array } for codepoint in mw.ustring.gcodepoint(title) do			local script = lookup_script(codepoint) if characters_by_script[script] then local name = lookup_name(codepoint) characters_by_script[script]:insert { name = name, char = mw.ustring.char(codepoint) } end end title = "" .. title:gsub("_", " ") .. "" output:insert("|-\n| " .. title .. "\n") output:insert("| ") local script_list = Array for script, characters in require "Module:table".sortedPairs(characters_by_script) do			if #characters > 0 then local character_list = characters :map(						function (character)							return ''								.. character.char .. ' '						end) :concat script_list:insert(script .. ": " .. character_list) end end output:insert(script_list:concat "; ") output:insert "\n" end output:insert "|}" return output:concat end

function export.show_Cyrillic_and_Latin(frame) return make_table Mainspace titles with Cyrillic and Latin (except redirects and titles with кварк ) end

function export.show_Greek_and_Latin(frame) return make_table end

return export