-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenglish_init.lua
executable file
·76 lines (67 loc) · 1.44 KB
/
english_init.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
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
71
72
73
74
75
#! /usr/bin/env lua
--
-- english_init.lua
-- Copyright (C) 2020 Shewer Lu <shewer@gmail.com>
--
-- Distributed under terms of the MIT license.
--
--[[
OS="win"
if OS=="win" then
USERDIR=os.getenv("APPDATA") or ""
USERDIR= USERDIR .. "\\Rime"
else
USERDIR=os.getenv("APPDATA") or ""
USERDIR= USERDIR .. "/Rime"
end
--]]
--USERDIR= USERDIR .. "\\Rime"
function string.split( str, sp,sp1)
if type(sp) == "string" then
if sp:len() == 0 then
sp= "([%z\1-\127\194-\244][\128-\191]*)"
elseif sp:len() > 1 then
sp1= sp1 or "^"
_,str= pcall(string.gsub,str ,sp,sp1)
sp= "[^".. sp1.. "]*"
else
if sp =="%" then
sp= "%%"
end
sp= "[^" .. sp .. "]*"
end
else
sp= "[^" .. " " .."]+"
end
local tab= setmetatable( {} , {__index=table} )
flag,res= pcall( string.gmatch,str,sp)
for v in res do
tab:insert(v)
end
return tab
end
table.each=function(tab,func)
for i,v in ipairs(tab) do
func(v,i)
end
return tab
end
table.find_all=function(tab,elm,...)
local tmptab=setmetatable({} , {__index=table} )
local _func= (type(elm) == "function" and elm ) or function(v,k, ... ) return v == elm end
for k,v in pairs(tab) do
if _func(v,...) then
tmptab:insert(v)
end
end
return tmptab
end
table.find=function(tab,elm,...)
local _func= (type(elm) == "function" and elm ) or function(v, ... ) return v == elm end
for k,v in pairs(tab) do
if _func(v,...) then
return v,k
end
end
return nil
end