From 6057449ae048f77e4479c7f10921d5856ce93973 Mon Sep 17 00:00:00 2001 From: sven Date: Mon, 6 Oct 2008 09:52:55 +0000 Subject: [PATCH] add comments to stdnse.tohex() --- nselib/stdnse.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nselib/stdnse.lua b/nselib/stdnse.lua index ee56f134d..7ad5a5c22 100644 --- a/nselib/stdnse.lua +++ b/nselib/stdnse.lua @@ -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