diff options
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/ffluci/sys.lua | 6 | ||||
-rw-r--r-- | core/src/ffluci/util.lua | 34 | ||||
-rw-r--r-- | core/src/ffluci/view/header.htm | 1 |
3 files changed, 19 insertions, 22 deletions
diff --git a/core/src/ffluci/sys.lua b/core/src/ffluci/sys.lua index f50b014f0..b9d529a8c 100644 --- a/core/src/ffluci/sys.lua +++ b/core/src/ffluci/sys.lua @@ -162,7 +162,7 @@ end -- Returns the binary IP to a given IP function net.ip4bin(ip) - local parts = ffluci.util.split(ip, '%.') + local parts = ffluci.util.split(ip, '.') if #parts ~= 4 then return nil end @@ -265,7 +265,7 @@ function _parse_delimited_table(iter, delimiter) local trim = ffluci.util.trim local split = ffluci.util.split - local keys = split(trim(iter()), delimiter) + local keys = split(trim(iter()), delimiter, nil, true) for i, j in pairs(keys) do keys[i] = trim(keys[i]) end @@ -274,7 +274,7 @@ function _parse_delimited_table(iter, delimiter) local row = {} line = trim(line) if #line > 0 then - for i, j in pairs(split(line, delimiter)) do + for i, j in pairs(split(line, delimiter, nil, true)) do if keys[i] then row[keys[i]] = j end diff --git a/core/src/ffluci/util.lua b/core/src/ffluci/util.lua index dfc88e3e4..9cb1e1420 100644 --- a/core/src/ffluci/util.lua +++ b/core/src/ffluci/util.lua @@ -145,33 +145,29 @@ function sessionid() end --- Splits a string into an array (Adapted from lua-users.org) -function split(str, pat, max) +-- Splits a string into an array +function split(str, pat, max, regex) pat = pat or "\n" - max = max or -1 + max = max or #str local t = {} - local fpat = "(.-)" .. pat - local last_end = 1 - local s, e, cap = str:find(fpat, 1) + local c = 1 - while s do - max = max - 1 - if s ~= 1 or cap ~= "" then - table.insert(t,cap) - end - last_end = e+1 - if max == 0 then - break - end - s, e, cap = str:find(fpat, last_end) + if #pat == 0 then + return nil end - if last_end <= #str then - cap = str:sub(last_end) - table.insert(t, cap) + if max == 0 then + return str end + repeat + local s, e = str:find(pat, c, not regex) + table.insert(t, str:sub(c, s and s - 1)) + max = max - 1 + c = e and e + 1 or #str + 1 + until not s or max < 0 + return t end diff --git a/core/src/ffluci/view/header.htm b/core/src/ffluci/view/header.htm index 1bfc7a02d..ac76e0ab5 100644 --- a/core/src/ffluci/view/header.htm +++ b/core/src/ffluci/view/header.htm @@ -3,6 +3,7 @@ require("ffluci.sys") local load1, load5, load15 = ffluci.sys.loadavg() local req = require("ffluci.dispatcher").request local menu = require("ffluci.menu").get()[req.category] +menu = menu or {} require("ffluci.i18n").loadc("default") require("ffluci.http").htmlheader() %><?xml version="1.0" encoding="utf-8"?> |