add cursor functionality

This commit is contained in:
union2find
2016-04-21 22:13:10 +08:00
parent bb00055293
commit d6fcc9adf9
4 changed files with 298 additions and 221 deletions

View File

@@ -1,3 +1,5 @@
local BaseUtil = require("ffi/util")
--[[--
Miscellaneous helper functions for KOReader frontend.
]]
@@ -94,4 +96,31 @@ function util.lastIndexOf(string, ch)
if i == nil then return -1 else return i - 1 end
end
-- Split string into a list of UTF-8 chars.
-- @text: the string to be splitted.
-- @tab: the table to store the chars sequentially, must not be nil.
function util.splitToChars(text, tab)
if text == nil then return end
-- clear
for k, v in pairs(tab) do
tab[k] = nil
end
print("table", tab)
local prevcharcode, charcode = 0
for uchar in string.gfind(text, "([%z\1-\127\194-\244][\128-\191]*)") do
charcode = BaseUtil.utf8charcode(uchar)
if prevcharcode then -- utf8
table.insert(tab, uchar)
end
prevcharcode = charcode
end
print(table.concat(tab, ","))
end
-- Test whether a string could be separated by a char for multi-line rendering
function util.isSplitable(c)
return #c > 1 or c == " " or string.match(c, "%p") ~= nil
end
return util