-
Notifications
You must be signed in to change notification settings - Fork 6
/
unicode.lua
45 lines (41 loc) · 1.02 KB
/
unicode.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#! /usr/bin/env lua
--
-- unicode.lua
-- Copyright (C) 2021 Shewer Lu <shewer@gmail.com>
--
-- Distributed under terms of the MIT license.
--
-- 1 copy this file in lua/component/uincode.lua
-- 2 rime.lua
-- uincode = require('component/unicode')
--
-- 3 schema.yaml
-- recognizer/patterns/unicode: "U[a-f0-9]+"
-- engine/translators
-- - lua_translator@unicode -- append
--
local M={}
function M.init(env)
end
function M.fini(env)
end
-- Ucode
-- patterns:
-- unicode: "U([a-h0-9]+)"
function M.func(input,seg,env)
local ucodestr = seg:has_tag("unicode") and input:match("U(%x+)")
if ucodestr and #ucodestr>1 then
local code= tonumber(ucodestr,16)
local text = utf8.char( code )
yield(
Candidate( "unicode", seg.start, seg._end, text, string.format("U%x",code) ))
if #ucodestr < 5 then
for i=0,15 do
local text = utf8.char( code * 16 + i)
yield(
Candidate( "unicode", seg.start, seg._end, text, string.format("U%x~%x",code,i) ))
end
end
end
end
return M