Module:R:CEDHL

local m_str_utils = require("Module:string utilities")

local codepoint = m_str_utils.codepoint local concat = table.concat local floor = math.floor local gsub = m_str_utils.gsub local insert = table.insert local ulen = m_str_utils.len local usub = m_str_utils.sub

local list = mw.loadData("Module:R:CEDHL/data")

local export = {}

function export.normalize(term) local normalized, i, length = {}, 1, ulen(term) while i <= length do		local x = codepoint(term, i)		if not (0x591 <= x and x <= 0x5C7) then insert(normalized, usub(term, i, i)) end i = i + 1 end return (gsub(concat(normalized), "['׳◌]", "")) end

function export.page_number(frame) local value = export.normalize(frame.args[1]) local low, high, mid = 1, list.n	while high - low > 1 do		mid = floor((low+high)/2) if list[mid] == value then return mid elseif list[mid] < value then low = mid elseif list[mid] > value then high = mid - 1 end end return list[high] <= value and high or low end

return export