projects
/
prosody.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
mod_tls: Fix ssl option fallback to a "parent" host if current host does not have...
[prosody.git]
/
util
/
hex.lua
diff --git
a/util/hex.lua
b/util/hex.lua
index b21ee17e5fe9cb96e4986f9fab89a0570cd4f97e..4cc28d33386f1f42dbe7d7cd1216e37757943e6c 100644
(file)
--- a/
util/hex.lua
+++ b/
util/hex.lua
@@
-1,19
+1,26
@@
local s_char = string.char;
local s_char = string.char;
+local s_format = string.format;
+local s_gsub = string.gsub;
+local s_lower = string.lower;
-local function char_to_hex(c)
- return ("%02x"):format(c:byte())
-end
+local char_to_hex = {};
+local hex_to_char = {};
-local function hex_to_char(h)
- return s_char(tonumber(h, 16));
+do
+ local char, hex;
+ for i = 0,255 do
+ char, hex = s_char(i), s_format("%02x", i);
+ char_to_hex[char] = hex;
+ hex_to_char[hex] = char;
+ end
end
local function to(s)
end
local function to(s)
- return
s:gsub(".", char_to_hex
);
+ return
(s_gsub(s, ".", char_to_hex)
);
end
local function from(s)
end
local function from(s)
- return
s:gsub("..", hex_to_char
);
+ return
(s_gsub(s_lower(s), "%X*(%x%x)%X*", hex_to_char)
);
end
return { to = to, from = from }
end
return { to = to, from = from }