dict: 槛(jian 栏杆、圈) (#705)

lua:Unicode.lua 添加数值超限警告,防止 error 产生
This commit is contained in:
mirtlecn
2024-02-26 23:53:18 +08:00
committed by GitHub
parent ec9c14000c
commit e56544ec79
3 changed files with 18 additions and 13 deletions

View File

@@ -2,6 +2,7 @@
-- 复制自: https://github.com/shewer/librime-lua-script/blob/main/lua/component/unicode.lua
-- 示例:输入 U62fc 得到「拼」
-- 触发前缀默认为 recognizer/patterns/unicode 的第 2 个字符,即 U
-- 2024.02.26: 限定编码最大值
local function unicode(input, seg, env)
-- 获取 recognizer/patterns/unicode 的第 2 个字符作为触发前缀
env.unicode_keyword = env.unicode_keyword or
@@ -10,6 +11,10 @@ local function unicode(input, seg, env)
local ucodestr = input:match(env.unicode_keyword .. "(%x+)")
if ucodestr and #ucodestr > 1 then
local code = tonumber(ucodestr, 16)
if code > 0x10FFFF then
yield(Candidate("unicode", seg.start, seg._end, "数值超限!", ""))
return
end
local text = utf8.char(code)
yield(Candidate("unicode", seg.start, seg._end, text, string.format("U%x", code)))
if code < 0x10000 then