forked from sikuner/book-code
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.lua
More file actions
29 lines (21 loc) · 626 Bytes
/
Copy pathutil.lua
File metadata and controls
29 lines (21 loc) · 626 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
local util = {}
function util.test(arg)
end
-- Decodes URL Query String Entities, e.g. '%20' becomes ' ' (space)
function util.decode(s)
s = s:gsub('+', ' ')
s = s:gsub('\n', '')
s = s:gsub('%%(%x%x)', function(h) return string.char(tonumber(h, 16)) end)
return s
end
-- Transforms query string, e.g. 'cmd=get&par=whatever' into a map '{cmd = "get", par = "whatever"}'
function util.parseurl(qs)
local map = {}
qs:gsub('([^&=]+)=([^&=]*)&?',
function(key, val) map[decode(key)] = decode(val) end)
return map
end
function printf(...)
io.write(string.format(...))
end
return util