Skip to content

Commit

Permalink
Use an iterator instead of building an intermediate table for format_…
Browse files Browse the repository at this point in the history
…output
  • Loading branch information
bonsaiviking committed Oct 18, 2018
1 parent 93edeef commit 39cfbdf
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions nselib/stdnse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ local sub = string.sub
local gsub = string.gsub
local char = string.char
local byte = string.byte
local gmatch = string.gmatch

local concat = table.concat;
local insert = table.insert;
Expand Down Expand Up @@ -561,9 +562,9 @@ local function format_output_sub(status, data, indent)
insert(output, format_output_sub(status, value, new_indent))

elseif(type(value) == 'string') then
local lines = splitlines(value)

for j, line in ipairs(lines) do
-- ensure it ends with a newline
if sub(value, -1) ~= "\n" then value = value .. "\n" end
for line in gmatch(value, "([^\r\n]-)\n") do
insert(output, format("%s %s%s\n",
format_get_indent(indent),
prefix, line))
Expand Down

0 comments on commit 39cfbdf

Please sign in to comment.