Comparison

util/datamanager.lua @ 7732:aba3dd84d9f0

util.datamanager: Use the 'base' argument to tonumber() to indicate hexadecimal
author Kim Alvefur <zash@zash.se>
date Sun, 20 Nov 2016 12:03:24 +0100
parent 7674:8027eecc750f
child 7733:601c4d81603b
comparison
equal deleted inserted replaced
7731:a0ee83c4a82c 7732:aba3dd84d9f0
48 local _ENV = nil; 48 local _ENV = nil;
49 49
50 ---- utils ----- 50 ---- utils -----
51 local encode, decode; 51 local encode, decode;
52 do 52 do
53 local urlcodes = setmetatable({}, { __index = function (t, k) t[k] = char(tonumber("0x"..k)); 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("+", " "):gsub("%%([a-fA-F0-9][a-fA-F0-9])", urlcodes)); 56 return s and (s:gsub("+", " "):gsub("%%([a-fA-F0-9][a-fA-F0-9])", urlcodes));
57 end 57 end
58 58