mirror of
https://github.com/iDvel/rime-ice.git
synced 2026-05-14 00:30:37 +08:00
style: Lua 统一缩进 4 空格
This commit is contained in:
@@ -42,39 +42,51 @@
|
||||
-- puts(INFO,__FILE__(),__LINE__(),__FUNC__() , ...)
|
||||
--
|
||||
-- global variable
|
||||
function __FILE__(n) n=n or 2 return debug.getinfo(n,'S').source end
|
||||
function __LINE__(n) n=n or 2 return debug.getinfo(n, 'l').currentline end
|
||||
function __FUNC__(n) n=n or 2 return debug.getinfo(n, 'n').name end
|
||||
INFO="log"
|
||||
WARN="warn"
|
||||
ERROR="error"
|
||||
DEBUG="trace"
|
||||
CONSOLE="console"
|
||||
function __FILE__(n)
|
||||
n = n or 2
|
||||
return debug.getinfo(n, 'S').source
|
||||
end
|
||||
|
||||
function __LINE__(n)
|
||||
n = n or 2
|
||||
return debug.getinfo(n, 'l').currentline
|
||||
end
|
||||
|
||||
function __FUNC__(n)
|
||||
n = n or 2
|
||||
return debug.getinfo(n, 'n').name
|
||||
end
|
||||
|
||||
INFO = "log"
|
||||
WARN = "warn"
|
||||
ERROR = "error"
|
||||
DEBUG = "trace"
|
||||
CONSOLE = "console"
|
||||
|
||||
|
||||
|
||||
|
||||
local function tran_msg(...)
|
||||
local msg="\t"
|
||||
for i,k in next, {...} do msg = msg .. ": " .. tostring(k) end
|
||||
return msg
|
||||
local msg = "\t"
|
||||
for i, k in next, { ... } do msg = msg .. ": " .. tostring(k) end
|
||||
return msg
|
||||
end
|
||||
local function puts( tag , ...)
|
||||
if type(tag) ~= "string" then return end
|
||||
local function puts(tag, ...)
|
||||
if type(tag) ~= "string" then return end
|
||||
|
||||
if INFO and tag:match("^" .. INFO) then
|
||||
(log and log.info or print)( tag .. tran_msg(...))
|
||||
elseif WARN and tag:match("^" .. WARN) then
|
||||
(log and log.warning or print)(tag .. tran_msg(...))
|
||||
elseif ERROR and tag:match("^" .. ERROR) then
|
||||
(log and log.error or print)(tag .. tran_msg(...))
|
||||
elseif DEBUG and tag:match("^" .. DEBUG) then
|
||||
(log and log.error or print)(tag .. tran_msg(...))
|
||||
elseif CONSOLE and tag:match( "^" .. CONSOLE ) then
|
||||
( print)( tag .. tran_msg(...))
|
||||
else
|
||||
return
|
||||
end
|
||||
if INFO and tag:match("^" .. INFO) then
|
||||
(log and log.info or print)(tag .. tran_msg(...))
|
||||
elseif WARN and tag:match("^" .. WARN) then
|
||||
(log and log.warning or print)(tag .. tran_msg(...))
|
||||
elseif ERROR and tag:match("^" .. ERROR) then
|
||||
(log and log.error or print)(tag .. tran_msg(...))
|
||||
elseif DEBUG and tag:match("^" .. DEBUG) then
|
||||
(log and log.error or print)(tag .. tran_msg(...))
|
||||
elseif CONSOLE and tag:match("^" .. CONSOLE) then
|
||||
(print)(tag .. tran_msg(...))
|
||||
else
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
return puts
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
local drop_words =
|
||||
{ "示~例~",
|
||||
{ "示~例~",
|
||||
}
|
||||
return drop_words
|
||||
return drop_words
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
local drop_list = require("cold_word_drop.drop_words")
|
||||
local hide_list = require("cold_word_drop.hide_words")
|
||||
local turndown_freq_list = require("cold_word_drop.turndown_freq_words")
|
||||
@@ -24,8 +23,8 @@ local function filter(input, env)
|
||||
i = i + 1
|
||||
---@diagnostic disable-next-line: undefined-global
|
||||
yield(cand)
|
||||
else
|
||||
table.insert(cands, cand)
|
||||
else
|
||||
table.insert(cands, cand)
|
||||
end
|
||||
else
|
||||
table.insert(cands, cand)
|
||||
@@ -43,13 +42,13 @@ local function filter(input, env)
|
||||
(hide_list[cand.text] and table.find_index(hide_list[cand.text], cpreedit_code))
|
||||
)
|
||||
then
|
||||
---@diagnostic disable-next-line: undefined-global
|
||||
---@diagnostic disable-next-line: undefined-global
|
||||
yield(cand)
|
||||
end
|
||||
end
|
||||
for cand in input:iter() do
|
||||
yield(cand)
|
||||
end
|
||||
for cand in input:iter() do
|
||||
yield(cand)
|
||||
end
|
||||
end
|
||||
|
||||
return filter
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
local hide_words =
|
||||
{ ["示~例~"] = { "shil", "shili", },
|
||||
{ ["示~例~"] = { "shil", "shili", },
|
||||
}
|
||||
return hide_words
|
||||
return hide_words
|
||||
|
||||
@@ -27,29 +27,29 @@ function metatable_chk(tab)
|
||||
end
|
||||
end
|
||||
|
||||
table.eachi = function (tab, func)
|
||||
table.eachi = function(tab, func)
|
||||
for i = 1, #tab do
|
||||
func(tab[i], i)
|
||||
end
|
||||
return tab
|
||||
end
|
||||
table.eacha = function (tab, func)
|
||||
table.eacha = function(tab, func)
|
||||
for i, v in ipairs(tab) do
|
||||
func(v, i)
|
||||
end
|
||||
return tab
|
||||
end
|
||||
table.each = function (tab, func)
|
||||
table.each = function(tab, func)
|
||||
for k, v in pairs(tab) do
|
||||
func(v, k)
|
||||
end
|
||||
return tab
|
||||
end
|
||||
table.find_index = function (tab, elm, ...)
|
||||
table.find_index = function(tab, elm, ...)
|
||||
local _, i = table.find(tab, elm, ...)
|
||||
return i
|
||||
end
|
||||
table.find = function (tab, elm, func)
|
||||
table.find = function(tab, elm, func)
|
||||
for i, v in ipairs(tab) do
|
||||
if elm == v then
|
||||
return v, i
|
||||
@@ -57,17 +57,17 @@ table.find = function (tab, elm, func)
|
||||
end
|
||||
end
|
||||
|
||||
table.find_with_func = function (tab, elm, ...)
|
||||
table.find_with_func = function(tab, elm, ...)
|
||||
local i, v = table.find(tab, elm)
|
||||
end
|
||||
table.delete = function (tab, elm, ...)
|
||||
table.delete = function(tab, elm, ...)
|
||||
local index = table.find_index(tab, elm)
|
||||
return index and table.remove(tab, index)
|
||||
end
|
||||
|
||||
table.find_all = function (tab, elm, ...)
|
||||
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
|
||||
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, k, ...) then
|
||||
tmptab:insert(v)
|
||||
@@ -77,7 +77,7 @@ table.find_all = function (tab, elm, ...)
|
||||
end
|
||||
table.select = table.find_all
|
||||
|
||||
table.reduce = function (tab, func, arg)
|
||||
table.reduce = function(tab, func, arg)
|
||||
local new, old = arg, arg
|
||||
for i, v in ipairs(tab) do
|
||||
new, old = func(v, new)
|
||||
@@ -85,17 +85,17 @@ table.reduce = function (tab, func, arg)
|
||||
return new, arg
|
||||
end
|
||||
|
||||
table.map = function (tab, func)
|
||||
table.map = function(tab, func)
|
||||
local newtab = setmetatable({}, { __index = table })
|
||||
func = func or function (v, i) return v, i end
|
||||
func = func or function(v, i) return v, i end
|
||||
for i, v in ipairs(tab) do
|
||||
newtab[i] = func(v, i)
|
||||
end
|
||||
return newtab
|
||||
end
|
||||
table.map_hash = function (tab, func) -- table to list of array { key, v}
|
||||
table.map_hash = function(tab, func) -- table to list of array { key, v}
|
||||
local newtab = setmetatable({}, { __index = table })
|
||||
func = func or function (k, v) return { k, v } end
|
||||
func = func or function(k, v) return { k, v } end
|
||||
for k, v in pairs(tab) do
|
||||
newtab:insert(func(k, v))
|
||||
end
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
require('cold_word_drop.string')
|
||||
require("cold_word_drop.metatable")
|
||||
-- local puts = require("tools/debugtool")
|
||||
@@ -146,7 +145,7 @@ local function processor(key, env)
|
||||
return 1 -- kAccept
|
||||
end
|
||||
|
||||
return 2 -- kNoop, 不做任何操作, 交给下个组件处理
|
||||
return 2 -- kNoop, 不做任何操作, 交给下个组件处理
|
||||
end
|
||||
|
||||
return processor
|
||||
|
||||
@@ -3,38 +3,39 @@
|
||||
-- string.utf8_len = utf8.len
|
||||
-- string.utf8_offset= utf8.offset
|
||||
-- string.utf8_sub= utf8.sub
|
||||
function string.split( str, sp,sp1)
|
||||
sp =type(sp) == "string" and sp or " "
|
||||
if #sp == 0 then
|
||||
sp= "([%z\1-\127\194-\244][\128-\191]*)"
|
||||
elseif #sp == 1 then
|
||||
sp= "[^" .. (sp=="%" and "%%" or sp) .. "]*"
|
||||
else
|
||||
sp1= sp1 or "^"
|
||||
str=str:gsub(sp,sp1)
|
||||
sp= "[^".. sp1 .. "]*"
|
||||
end
|
||||
function string.split(str, sp, sp1)
|
||||
sp = type(sp) == "string" and sp or " "
|
||||
if #sp == 0 then
|
||||
sp = "([%z\1-\127\194-\244][\128-\191]*)"
|
||||
elseif #sp == 1 then
|
||||
sp = "[^" .. (sp == "%" and "%%" or sp) .. "]*"
|
||||
else
|
||||
sp1 = sp1 or "^"
|
||||
str = str:gsub(sp, sp1)
|
||||
sp = "[^" .. sp1 .. "]*"
|
||||
end
|
||||
|
||||
local tab= {}
|
||||
for v in str:gmatch(sp) do
|
||||
table.insert(tab,v)
|
||||
end
|
||||
return tab
|
||||
local tab = {}
|
||||
for v in str:gmatch(sp) do
|
||||
table.insert(tab, v)
|
||||
end
|
||||
return tab
|
||||
end
|
||||
|
||||
function utf8.gsub(str,si,ei)
|
||||
local function index(ustr,i)
|
||||
return i>=0 and ( ustr:utf8_offset(i) or ustr:len() +1 )
|
||||
or ( ustr:utf8_offset(i) or 1 )
|
||||
end
|
||||
function utf8.gsub(str, si, ei)
|
||||
local function index(ustr, i)
|
||||
return i >= 0 and (ustr:utf8_offset(i) or ustr:len() + 1)
|
||||
or (ustr:utf8_offset(i) or 1)
|
||||
end
|
||||
|
||||
local u_si= index(str,si)
|
||||
ei = ei or str:utf8_len()
|
||||
ei = ei >=0 and ei +1 or ei
|
||||
local u_ei= index(str, ei ) -1
|
||||
return str:sub(u_si,u_ei)
|
||||
local u_si = index(str, si)
|
||||
ei = ei or str:utf8_len()
|
||||
ei = ei >= 0 and ei + 1 or ei
|
||||
local u_ei = index(str, ei) - 1
|
||||
return str:sub(u_si, u_ei)
|
||||
end
|
||||
string.utf8_len= utf8.len
|
||||
string.utf8_offset=utf8.offset
|
||||
string.utf8_sub= utf8.gsub
|
||||
|
||||
string.utf8_len = utf8.len
|
||||
string.utf8_offset = utf8.offset
|
||||
string.utf8_sub = utf8.gsub
|
||||
return true
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
local turndown_freq_words =
|
||||
{ ["示~例~"] = { "shili", },
|
||||
{ ["示~例~"] = { "shili", },
|
||||
}
|
||||
return turndown_freq_words
|
||||
return turndown_freq_words
|
||||
|
||||
Reference in New Issue
Block a user