Module:User:Theknightwho/findBestScript

local byte = string.byte local sub = string.sub

local Latn = require("Module:scripts").getByCode("Latn")

local function explode(str) local str_len = #str local text = {} local n, i, b = 1, 0 while n <= str_len do		a = byte(str, n)		i = i + 1 if a < 0xC0 then text[i] = a			n = n + 1 elseif a < 0xE0 then local b = byte(str, n + 1) text[i] = (a - 0xC0) * 0x40 + b - 0x80 n = n + 2 elseif a < 0xF0 then local b, c = byte(str, n + 1, n + 2) text[i] = (a - 0xE0) * 0x1000 + (b - 0x80) * 0x40 + c - 0x80 n = n + 3 else local b, c, d = byte(str, n + 1, n + 3) text[i] = (a - 0xF0) * 0x40000 + (b - 0x80) * 0x1000 + (c - 0x80) * 0x40 + d - 0x80 n = n + 4 end end return text end

local function check_ranges(cp, ranges) for i = 2, ranges.n, 2 do		if cp <= ranges[i] then return cp >= ranges[i - 1] end end return false end

local export = {}

function export.count(str, sc) local cp = explode(str) local ranges = Latn._rawData.ranges local n = 0 for i = 1, #cp do		if check_ranges(cp[i], ranges) then n = n + 1 end end return n end

return export