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,19 +293,19 @@ 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
local t = {}
while (idx <= #rules_lines) do
t[#t + 1] = rules_lines[idx]
idx = idx + 1
idx = row if idx > #rules_lines or rules_lines[idx] == "" or string.sub(rules_lines[idx], 1, 1) == '-' then
while (idx <= #rules_lines) do break
ret = ret..rules_lines[idx].."\n" end
idx = idx + 1 end
local ret = ""
if idx > #rules_lines or rules_lines[idx] == "" or string.sub(rules_lines[idx], 1, 1) == '-' then ret = table.concat(t, "\n")
break return ret
end
end
return ret
end end
function get_lines(rules_lines, row, num_lines) function get_lines(rules_lines, row, num_lines)
@ -754,65 +754,69 @@ end
-- Populates exfields with all fields used -- Populates exfields with all fields used
function build_exception_condition_string_multi_fields(eitem, exfields) 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 = {}
for i, values in ipairs(eitem['values']) do icond[#icond + 1] = "("
if #fields ~= #values then local lcount = 0
return nil, "Exception item "..eitem['name']..": fields and values lists must have equal length" for i, values in ipairs(eitem['values']) do
end if #fields ~= #values then
return nil, "Exception item " .. eitem['name'] .. ": fields and values lists must have equal length"
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 = ""
-- If ival is a table, express it as (titem1, titem2, etc) -- If ival is a table, express it as (titem1, titem2, etc)
if type(ival) == "table" then if type(ival) == "table" then
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
istr = paren_item(ival) istr = paren_item(ival)
else else
-- Quote the value if not already quoted -- Quote the value if not already quoted
istr = quote_item(ival) istr = quote_item(ival)
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
end return "", nil
end
return icond, nil return ret, nil
end end