aboutsummaryrefslogtreecommitdiffstats
path: root/util/hex.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2014-09-02 22:34:32 +0200
committerKim Alvefur <zash@zash.se>2014-09-02 22:34:32 +0200
commitc47fa42628b2119f7e37e83f22919bc905a53624 (patch)
tree5ae5bb832b9e41b4812e12421bb70daf1c3b7446 /util/hex.lua
parent46105d64bf9627c8618624281c966ec784f4fc12 (diff)
parentc80b30a71ceb555bb33d14c3c7dbee0a8c93eaee (diff)
downloadprosody-c47fa42628b2119f7e37e83f22919bc905a53624.tar.gz
prosody-c47fa42628b2119f7e37e83f22919bc905a53624.zip
Merge 0.10->trunk
Diffstat (limited to 'util/hex.lua')
-rw-r--r--util/hex.lua19
1 files changed, 19 insertions, 0 deletions
diff --git a/util/hex.lua b/util/hex.lua
new file mode 100644
index 00000000..72fc22bd
--- /dev/null
+++ b/util/hex.lua
@@ -0,0 +1,19 @@
+local s_char = string.char;
+
+local function char_to_hex(c)
+ return ("%02x"):format(c:byte())
+end
+
+local function hex_to_char(h)
+ return s_char(tonumber(h, 16));
+end
+
+function to(s)
+ return s:gsub(".", char_to_hex);
+end
+
+function from(s)
+ return s:gsub("..", hex_to_char);
+end
+
+return { to = to, from = from }