From 351664eb90520f3b4beabbb652cf5ca9216893ed Mon Sep 17 00:00:00 2001 From: xiaorouji <60100640+xiaorouji@users.noreply.github.com> Date: Wed, 11 Oct 2023 21:51:41 +0800 Subject: [PATCH] luci: optimization code --- luci-app-passwall/luasrc/passwall/api.lua | 23 +++++++++++++++++++ .../root/usr/share/passwall/subscribe.lua | 23 +------------------ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/luci-app-passwall/luasrc/passwall/api.lua b/luci-app-passwall/luasrc/passwall/api.lua index 309bc6ef3..f84f50497 100644 --- a/luci-app-passwall/luasrc/passwall/api.lua +++ b/luci-app-passwall/luasrc/passwall/api.lua @@ -106,6 +106,29 @@ function trim(s) return (s:gsub("^%s*(.-)%s*$", "%1")) end +-- 分割字符串 +function split(full, sep) + if full then + full = full:gsub("%z", "") -- 这里不是很清楚 有时候结尾带个\0 + local off, result = 1, {} + while true do + local nStart, nEnd = full:find(sep, off) + if not nEnd then + local res = string.sub(full, off, string.len(full)) + if #res > 0 then -- 过滤掉 \0 + table.insert(result, res) + end + break + else + table.insert(result, string.sub(full, off, nStart - 1)) + off = nEnd + 1 + end + end + return result + end + return {} +end + function is_exist(table, value) for index, k in ipairs(table) do if k == value then diff --git a/luci-app-passwall/root/usr/share/passwall/subscribe.lua b/luci-app-passwall/root/usr/share/passwall/subscribe.lua index 0c49bc20d..8626bc0ca 100755 --- a/luci-app-passwall/root/usr/share/passwall/subscribe.lua +++ b/luci-app-passwall/root/usr/share/passwall/subscribe.lua @@ -16,6 +16,7 @@ local datatypes = require "luci.cbi.datatypes" -- so caching them is worth the effort local tinsert = table.insert local ssub, slen, schar, sbyte, sformat, sgsub = string.sub, string.len, string.char, string.byte, string.format, string.gsub +local split = api.split local jsonParse, jsonStringify = luci.jsonc.parse, luci.jsonc.stringify local base64Decode = api.base64Decode local uci = luci.model.uci.cursor() @@ -317,28 +318,6 @@ do end end --- 分割字符串 -local function split(full, sep) - if full then - full = full:gsub("%z", "") -- 这里不是很清楚 有时候结尾带个\0 - local off, result = 1, {} - while true do - local nStart, nEnd = full:find(sep, off) - if not nEnd then - local res = ssub(full, off, slen(full)) - if #res > 0 then -- 过滤掉 \0 - tinsert(result, res) - end - break - else - tinsert(result, ssub(full, off, nStart - 1)) - off = nEnd + 1 - end - end - return result - end - return {} -end -- urlencode -- local function get_urlencode(c) return sformat("%%%02X", sbyte(c)) end