1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Use string.gsub instead of looped concat to modify strings

This commit is contained in:
dmiller
2015-02-27 14:55:29 +00:00
parent d16772a8a8
commit e275a96c72
5 changed files with 23 additions and 42 deletions

View File

@@ -1156,16 +1156,9 @@ end
-- returns the string with all non-printable chars
-- coded as hex
function makeStringReadable(data)
local r = ""
for i=1,#data,1 do
local x = data:byte(i)
if x > 31 and x <127 then
r = r .. data:sub(i,i)
else
r = r .. ("\\x%x"):format(x)
end
end
return r
return data:gsub("[\x00-\x1f\x7f-\xff]", function (x)
return ("\\x%02x"):format(x:byte())
end)
end
function readNonProxyDesc(dis)