FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
librime-lua-script/lua/component/unicode_filter.lua at main · shewer/librime-lua-script · GitHub
shewer
librime-lua-script
Repository navigation
Code
Issues
4
(4)
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
librime-lua-script
/
lua
/
component
/
unicode_filter.lua
Copy path
More file actions
More file actions
Latest commit
History
History
History
70 lines (65 loc) · 1.69 KB
Breadcrumbs
librime-lua-script
/
lua
/
component
/
unicode_filter.lua
Copy path
File metadata and controls
70 lines (65 loc) · 1.69 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!
/usr/bin/env lua
--
--
unicode_filter.lua
--
Copyright (C) 2022 Shewer Lu <shewer@gmail.com>
--
--
Distributed under terms of the MIT license.
--
--
lua_filter@unicode_filter : name_space default unicode
--
tags:
--
--
option : name_space
--
--
local
puts
=
require
'
tools/debugtool
'
--
load <name_space>/tags to table
local
function
get_tags
(
env
)
local
tags
=
env
.
engine
.
schema
.
config
:
get_list
(
env
.
name_space
..
"
/tags
"
)
if
not
tags
then
return
end
local
tags_tab
=
{}
for
i
=
0
,
tags
.
size
-
1
do
table.insert
(
tags_tab
,
tags
:
get_value_at
(
i
) )
end
return
Set
(
tags_tab
)
end
--
orgin tags_match
local
function
_tags_match
(
segment
,
env
)
assert
(
env
.
tags
==
nil
or
type
(
env
.
tags
)
==
"
table
"
,
"
mfilter.lua:
"
..
__LINE__
()
..
"
:env.tags data type error
"
)
local
tab
=
type
(
env
.
tags
)
==
"
table
"
and
env
.
tags
or
{}
if
#
tab
<
1
then
return
true
end
--
tab size ==0 如果 無tags 表示 全符合
for
i
,
v
in
ipairs
(
tab
)
do
if
segment
:
has_tag
(
v
)
then
return
true
end
end
return
false
end
local
M
=
{}
function
M
.
tags_match
(
segment
,
env
)
if
env
.
engine
.
context
:
get_option
(
env
.
name_space
)
then
return
not
env
.
tags
and
true
or
(
segment
.
tags
*
env
.
tags
):
empty
()
end
return
false
end
function
M
.
init
(
env
)
env
.
name_space
=
env
.
name_space
:
match
(
"
^(unicode)_filter$
"
)
or
env
.
name_space
env
.
tags
=
get_tags
(
env
)
end
function
M
.
fini
(
env
)
end
local
function
ucode
(
text
)
if
not
text
or
#
text
<
1
then
return
"
"
end
local
str
=
"
"
for
i
,
code
in
utf8.codes
(
text
)
do
str
=
string.format
(
"
%s U%x
"
,
str
,
code
)
end
return
"
[
"
..
str
..
"
]
"
end
function
M
.
func
(
inp
,
env
)
for
cand
in
inp
:
iter
()
do
cand
.
comment
=
cand
.
comment
..
ucode
(
cand
.
text
)
yield
(
cand
)
end
end
return
M
Back
|
FazBrowse Home
|
New Git URL