replace .. with table concat

Signed-off-by: vadim.zyarko <vadim.zyarko@sysdig.com>
This commit is contained in:
VadimZy 2021-12-11 18:47:02 -08:00 committed by poiana
parent c86615f68c
commit b88a1cbb09

View File

@ -293,18 +293,18 @@ function split_lines(rules_content)
end end
function get_orig_yaml_obj(rules_lines, row) function get_orig_yaml_obj(rules_lines, row)
local ret = ""
idx = row idx = row
local t = {}
while (idx <= #rules_lines) do while (idx <= #rules_lines) do
ret = ret..rules_lines[idx].."\n" t[#t + 1] = rules_lines[idx]
idx = idx + 1 idx = idx + 1
if idx > #rules_lines or rules_lines[idx] == "" or string.sub(rules_lines[idx], 1, 1) == '-' then if idx > #rules_lines or rules_lines[idx] == "" or string.sub(rules_lines[idx], 1, 1) == '-' then
break break
end end
end end
local ret = ""
ret = table.concat(t, "\n")
return ret return ret
end end
@ -757,23 +757,26 @@ function build_exception_condition_string_multi_fields(eitem, exfields)
local fields = eitem['fields'] local fields = eitem['fields']
local comps = eitem['comps'] local comps = eitem['comps']
local icond = "(" local icond = {}
icond[#icond + 1] = "("
local lcount = 0
for i, values in ipairs(eitem['values']) do for i, values in ipairs(eitem['values']) do
if #fields ~= #values then if #fields ~= #values then
return nil, "Exception item "..eitem['name']..": fields and values lists must have equal length" return nil, "Exception item " .. eitem['name'] .. ": fields and values lists must have equal length"
end end
if icond ~= "(" then if lcount ~= 0 then
icond=icond.." or " icond[#icond + 1] = " or "
end end
lcount = lcount + 1
icond=icond.."(" icond[#icond + 1] = "("
for k=1,#fields do for k = 1, #fields do
if k > 1 then if k > 1 then
icond=icond.." and " icond[#icond + 1] = " and "
end end
local ival = values[k] local ival = values[k]
local istr = "" local istr = ""
@ -783,11 +786,11 @@ function build_exception_condition_string_multi_fields(eitem, exfields)
istr = "(" istr = "("
for _, item in ipairs(ival) do for _, item in ipairs(ival) do
if istr ~= "(" then if istr ~= "(" then
istr = istr..", " istr = istr .. ", "
end end
istr = istr..quote_item(item) istr = istr .. quote_item(item)
end end
istr = istr..")" istr = istr .. ")"
else else
-- If the corresponding operator is one that works on lists, possibly add surrounding parentheses. -- If the corresponding operator is one that works on lists, possibly add surrounding parentheses.
if defined_list_comp_operators[comps[k]] then if defined_list_comp_operators[comps[k]] then
@ -798,21 +801,22 @@ function build_exception_condition_string_multi_fields(eitem, exfields)
end end
end end
icond = icond..fields[k].." "..comps[k].." "..istr icond[#icond + 1] = fields[k] .. " " .. comps[k] .. " " .. istr
exfields[fields[k]] = true exfields[fields[k]] = true
end end
icond=icond..")" icond[#icond + 1] = ")"
end end
icond = icond..")" icond[#icond + 1] = ")"
-- Don't return a trivially empty condition string -- Don't return a trivially empty condition string
if icond == "()" then local ret = table.concat(icond)
icond = "" if ret == "()" then
return "", nil
end end
return icond, nil return ret, nil
end end