Модул:R:en:DAFN
Изглед
Документацију овог модула можете да направите на страници Модул:R:en:DAFN/док
p = {}
function p.normalize(term)
term = mw.ustring.lower(term)
local length = mw.ustring.len(term)
local i = 1
local normalized = ""
a = mw.ustring.codepoint("az", 1)
z = mw.ustring.codepoint("az", 2)
while i <= length do
local x = mw.ustring.codepoint(term, i)
if a <= x and x <= z then
normalized = normalized .. mw.ustring.sub(term, i, i)
end
i = i + 1
end
return normalized
end
function p.page_number(frame)
local value = p.normalize(frame.args[1])
first = mw.ustring.sub(value, 1, 1)
if first < "g" then
list = require("Module:R:en:DAFN/data1")
elseif "g" <= first and first <= "n" then
list = require("Module:R:en:DAFN/data2")
else
return ""
end
local low = 1
local high = #list
local mid = 0
while high - low > 1 do
mid = math.floor((low+high)/2)
local midval = p.normalize(list[mid])
if midval == value then return mid
elseif midval < value then low = mid
elseif midval > value then high = mid - 1
end
end
if p.normalize(list[high]) <= value then return high
else return low
end
end
return p