1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
..
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
-- vim: ft=terra
local m={}
local pstr = lib.mem.ptr(int8)
terra m.sanitize(txt: pstr, quo: bool)
if txt.ptr == nil then return pstr.null() end
if txt.ct == 0 then txt.ct = lib.str.sz(txt.ptr) end
var a: lib.str.acc a:init(txt.ct*1.3)
for i=0,txt.ct do
if txt(i) == @'<' then a:lpush('<')
elseif txt(i) == @'>' then a:lpush('>')
elseif txt(i) == @'&' then a:lpush('&')
elseif quo and txt(i) == @'"' then a:lpush('"')
else a:push(&txt(i),1) end
end
................................................................................
terra m.hexbyte(i: uint8): int8[2]
return arrayof(int8,
m.hexdgt(i / 0x10),
m.hexdgt(i % 0x10))
end
terra m.urlenc(txt: pstr, qparam: bool)
if txt.ptr == nil then return pstr.null() end
if txt.ct == 0 then txt.ct = lib.str.sz(txt.ptr) end
var a: lib.str.acc a:init(txt.ct*1.3)
for i=0,txt.ct do
if txt(i) == @' ' then a:lpush('+')
elseif txt(i) == @'&' and not qparam then a:lpush('&')
elseif (txt(i) < 0x2c or
(txt(i) > @';' and txt(i) < @'@') or
(txt(i) > @'Z' and txt(i) < @'a') or
(txt(i) >= 0x7b and txt(i) <= 0x7f)) and
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
..
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
-- vim: ft=terra
local m={}
local pstr = lib.mem.ptr(int8)
terra m.sanitize(pool: &lib.mem.pool, txt: pstr, quo: bool)
if txt.ptr == nil then return pstr.null() end
if txt.ct == 0 then txt.ct = lib.str.sz(txt.ptr) end
var a: lib.str.acc a:pool(pool,txt.ct*1.3)
for i=0,txt.ct do
if txt(i) == @'<' then a:lpush('<')
elseif txt(i) == @'>' then a:lpush('>')
elseif txt(i) == @'&' then a:lpush('&')
elseif quo and txt(i) == @'"' then a:lpush('"')
else a:push(&txt(i),1) end
end
................................................................................
terra m.hexbyte(i: uint8): int8[2]
return arrayof(int8,
m.hexdgt(i / 0x10),
m.hexdgt(i % 0x10))
end
terra m.urlenc(pool: &lib.mem.pool, txt: pstr, qparam: bool)
if txt.ptr == nil then return pstr.null() end
if txt.ct == 0 then txt.ct = lib.str.sz(txt.ptr) end
var a: lib.str.acc a:pool(pool,txt.ct*1.3)
for i=0,txt.ct do
if txt(i) == @' ' then a:lpush('+')
elseif txt(i) == @'&' and not qparam then a:lpush('&')
elseif (txt(i) < 0x2c or
(txt(i) > @';' and txt(i) < @'@') or
(txt(i) > @'Z' and txt(i) < @'a') or
(txt(i) >= 0x7b and txt(i) <= 0x7f)) and
|