forked from candid82/joker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
a_url.go
103 lines (79 loc) · 2.51 KB
/
a_url.go
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// This file is generated by generate-std.joke script. Do not edit manually!
package url
import (
"net/url"
. "github.com/candid82/joker/core"
)
var urlNamespace = GLOBAL_ENV.EnsureNamespace(MakeSymbol("joker.url"))
var path_escape_ Proc = func(args []Object) Object {
c := len(args)
switch {
case c == 1:
s := ExtractString(args, 0)
res := url.PathEscape(s)
return MakeString(res)
default:
PanicArity(c)
}
return NIL
}
var path_unescape_ Proc = func(args []Object) Object {
c := len(args)
switch {
case c == 1:
s := ExtractString(args, 0)
res := pathUnescape(s)
return MakeString(res)
default:
PanicArity(c)
}
return NIL
}
var query_escape_ Proc = func(args []Object) Object {
c := len(args)
switch {
case c == 1:
s := ExtractString(args, 0)
res := url.QueryEscape(s)
return MakeString(res)
default:
PanicArity(c)
}
return NIL
}
var query_unescape_ Proc = func(args []Object) Object {
c := len(args)
switch {
case c == 1:
s := ExtractString(args, 0)
res := queryUnescape(s)
return MakeString(res)
default:
PanicArity(c)
}
return NIL
}
func init() {
urlNamespace.ResetMeta(MakeMeta(nil, "Parses URLs and implements query escaping.", "1.0"))
urlNamespace.InternVar("path-escape", path_escape_,
MakeMeta(
NewListFrom(NewVectorFrom(MakeSymbol("s"))),
`Escapes the string so it can be safely placed inside a URL path segment.`, "1.0"))
urlNamespace.InternVar("path-unescape", path_unescape_,
MakeMeta(
NewListFrom(NewVectorFrom(MakeSymbol("s"))),
`Does the inverse transformation of path-escape, converting each 3-byte encoded
substring of the form "%AB" into the hex-decoded byte 0xAB. It also converts
'+' into ' ' (space). It returns an error if any % is not followed by two hexadecimal digits.
PathUnescape is identical to QueryUnescape except that it does not unescape '+' to ' ' (space).`, "1.0"))
urlNamespace.InternVar("query-escape", query_escape_,
MakeMeta(
NewListFrom(NewVectorFrom(MakeSymbol("s"))),
`Escapes the string so it can be safely placed inside a URL query.`, "1.0"))
urlNamespace.InternVar("query-unescape", query_unescape_,
MakeMeta(
NewListFrom(NewVectorFrom(MakeSymbol("s"))),
`Does the inverse transformation of query-escape, converting each 3-byte encoded
substring of the form "%AB" into the hex-decoded byte 0xAB. It also converts
'+' into ' ' (space). It returns an error if any % is not followed by two hexadecimal digits.`, "1.0"))
}