mirror of
https://github.com/nmap/nmap.git
synced 2026-08-04 14:49:29 +00:00
add comments to stdnse.tohex()
This commit is contained in:
parent
2dd98df5b9
commit
6057449ae0
1 changed files with 6 additions and 2 deletions
|
|
@ -158,6 +158,7 @@ end
|
|||
--@return hexadecimal encoded string
|
||||
function tohex( s, options )
|
||||
options = options or {}
|
||||
local separator = options.separator
|
||||
local hex
|
||||
|
||||
if type( s ) == 'number' then
|
||||
|
|
@ -168,16 +169,19 @@ function tohex( s, options )
|
|||
error( "Type not supported in tohex(): " .. type(s), 2 )
|
||||
end
|
||||
|
||||
if options.separator then
|
||||
-- format hex if we got a separator
|
||||
if separator then
|
||||
local group = options.group or 2
|
||||
local fmt_table = {}
|
||||
-- split hex in group-size chunks
|
||||
for i=#hex,1,-group do
|
||||
-- table index must be consecutive otherwise table.concat won't work
|
||||
fmt_table[ceil(i/group)] = hex:sub(max(i-group+1,1),i)
|
||||
end
|
||||
|
||||
hex = concat( fmt_table, options.separator )
|
||||
hex = concat( fmt_table, separator )
|
||||
end
|
||||
|
||||
return hex
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue