diff options
Diffstat (limited to 'lualib/lua_util.lua')
-rw-r--r-- | lualib/lua_util.lua | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index 75d218da3..4b0e50192 100644 --- a/lualib/lua_util.lua +++ b/lualib/lua_util.lua @@ -1473,4 +1473,19 @@ exports.shuffle = function(tbl) return tbl end +-- +local hex_table = {} +for idx = 0, 255 do + hex_table[("%02X"):format(idx)] = string.char(idx) + hex_table[("%02x"):format(idx)] = string.char(idx) +end + +---[[[ +-- @function lua_util.unhex(str) +-- Decode hex encoded string +-- @param {string} str string to decode +-- @return {string} hex decoded string (valid hex pairs are decoded, everything else is printed as is) +--]]] +exports.unhex = function(str) return str:gsub('(..)', hex_table) end + return exports |