Comparison

util/datamanager.lua @ 7734:6a52415ed68a

util.datamanager: Shorter pattern
author Kim Alvefur <zash@zash.se>
date Sun, 20 Nov 2016 12:06:36 +0100
parent 7733:601c4d81603b
child 7925:209503ee3aaa
comparison
equal deleted inserted replaced
7733:601c4d81603b 7734:6a52415ed68a
51 local encode, decode; 51 local encode, decode;
52 do 52 do
53 local urlcodes = setmetatable({}, { __index = function (t, k) t[k] = char(tonumber(k, 16)); return t[k]; end }); 53 local urlcodes = setmetatable({}, { __index = function (t, k) t[k] = char(tonumber(k, 16)); return t[k]; end });
54 54
55 decode = function (s) 55 decode = function (s)
56 return s and (s:gsub("%%([a-fA-F0-9][a-fA-F0-9])", urlcodes)); 56 return s and (s:gsub("%%(%x%x)", urlcodes));
57 end 57 end
58 58
59 encode = function (s) 59 encode = function (s)
60 return s and (s:gsub("%W", function (c) return format("%%%02x", c:byte()); end)); 60 return s and (s:gsub("%W", function (c) return format("%%%02x", c:byte()); end));
61 end 61 end