1
0
mirror of https://github.com/nmap/nmap.git synced 2026-02-05 04:56:34 +00:00

Move a reused function out to file scope

This commit is contained in:
dmiller
2021-12-07 19:50:47 +00:00
parent 8a85cdd06b
commit 87fe985f32

View File

@@ -278,6 +278,9 @@ function tooctal(n)
return format("%o", n)
end
local tohex_helper = function(b)
return format("%02x", byte(b))
end
--- Encode a string or integer in hexadecimal (12 becomes "c", "AB" becomes
-- "4142").
--
@@ -303,9 +306,7 @@ function tohex( s, options )
if type( s ) == "number" then
hex = format("%x", s)
elseif type( s ) == 'string' then
hex = gsub(s, ".", function(b)
return format("%02x", byte(b))
end)
hex = gsub(s, ".", tohex_helper)
else
error( "Type not supported in tohex(): " .. type(s), 2 )
end