mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
add cursor functionality
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user