local encoding = require ('encoding')
encoding.default = 'CP1251'
u8 = encoding.UTF8
local russian_characters = {
[168] = 'Ё', [184] = 'ё', [192] = 'А', [193] = 'Б', [194] = 'В', [195] = 'Г', [196] = 'Д', [197] = 'Е', [198] = 'Ж', [199] = 'З', [200] = 'И', [201] = 'Й', [202] = 'К', [203] = 'Л', [204] = 'М', [205] = 'Н', [206] = 'О', [207] = 'П', [208] = 'Р', [209] = 'С', [210] = 'Т', [211] = 'У', [212] = 'Ф', [213] = 'Х', [214] = 'Ц', [215] = 'Ч', [216] = 'Ш', [217] = 'Щ', [218] = 'Ъ', [219] = 'Ы', [220] = 'Ь', [221] = 'Э', [222] = 'Ю', [223] = 'Я', [224] = 'а', [225] = 'б', [226] = 'в', [227] = 'г', [228] = 'д', [229] = 'е', [230] = 'ж', [231] = 'з', [232] = 'и', [233] = 'й', [234] = 'к', [235] = 'л', [236] = 'м', [237] = 'н', [238] = 'о', [239] = 'п', [240] = 'р', [241] = 'с', [242] = 'т', [243] = 'у', [244] = 'ф', [245] = 'х', [246] = 'ц', [247] = 'ч', [248] = 'ш', [249] = 'щ', [250] = 'ъ', [251] = 'ы', [252] = 'ь', [253] = 'э', [254] = 'ю', [255] = 'я',
}
local data = {}
if not doesFileExist(getWorkingDirectory()..'\\test.txt') then
local configFile = io.open(getWorkingDirectory()..'\\test.txt', 'w+')
configFile:close()
return
end
local configFile = io.open(getWorkingDirectory()..'\\test.txt', 'r')
for line in configFile:lines() do
table.insert(data, line)
end
configFile:close()
end
local search_input = imgui.ImBuffer(1000)
-- в imgui:
imgui.PushItemWidth(710)
imgui.InputText('##search', search_input)
imgui.PopItemWidth()
if search_input.v ~= '' then
for key, value in pairs(data) do
if string.find(string.rlower(data[key]), string.rlower(u8:decode(search_input.v))) then
imgui.Text(u8(value))
end
end
else
for key, value in pairs(data) do
imgui.Text(u8(value))
end
end
function string.rlower(s)
s = s:lower()
local strlen = s:len()
if strlen == 0 then return s end
s = s:lower()
local output = ''
for i = 1, strlen do
local ch = s:byte(i)
if ch >= 192 and ch <= 223 then -- upper russian characters
output = output .. russian_characters[ch + 32]
elseif ch == 168 then -- Ё
output = output .. russian_characters[184]
else
output = output .. string.char(ch)
end
end
return output
end