19
19
function URI (value:: AbstractString )
20
20
m = match (r" ^(([^:/?#]+?):)?(\/\/ ([^/?#]*))?([^?#]*)(\? ([^#]*))?(#(.*))?" , value)
21
21
22
- m=== nothing && error (" Invalid argument." )
22
+ m === nothing && error (" Invalid argument." )
23
23
24
24
return URI (
25
25
m. captures[2 ],
26
- m. captures[4 ]=== nothing ? nothing : percent_decode (m. captures[4 ]),
27
- m. captures[5 ]=== nothing ? nothing : percent_decode (m. captures[5 ]),
28
- m. captures[7 ]=== nothing ? nothing : percent_decode (m. captures[7 ]),
29
- m. captures[9 ]=== nothing ? nothing : percent_decode (m. captures[9 ])
26
+ m. captures[4 ] === nothing ? nothing : percent_decode (m. captures[4 ]),
27
+ m. captures[5 ] === nothing ? nothing : percent_decode (m. captures[5 ]),
28
+ m. captures[7 ] === nothing ? nothing : percent_decode (m. captures[7 ]),
29
+ m. captures[9 ] === nothing ? nothing : percent_decode (m. captures[9 ])
30
30
)
31
31
end
32
32
@@ -38,58 +38,58 @@ function URI(;
38
38
path:: AbstractString = " " ,
39
39
query:: Union{AbstractString,Nothing} = nothing ,
40
40
fragment:: Union{AbstractString,Nothing} = nothing
41
- )
41
+ )
42
42
return URI (scheme, authority, path, query, fragment)
43
43
end
44
44
45
45
@inline function is_rfc3986_unreserved (c:: Char )
46
46
return ' A' <= c <= ' Z' ||
47
- ' a' <= c <= ' z' ||
48
- ' 0' <= c <= ' 9' ||
49
- c == ' -' ||
50
- c == ' .' ||
51
- c == ' _' ||
52
- c == ' ~'
47
+ ' a' <= c <= ' z' ||
48
+ ' 0' <= c <= ' 9' ||
49
+ c == ' -' ||
50
+ c == ' .' ||
51
+ c == ' _' ||
52
+ c == ' ~'
53
53
end
54
54
55
55
@inline function is_rfc3986_sub_delim (c:: Char )
56
56
return c == ' !' ||
57
- c == ' $' ||
58
- c == ' &' ||
59
- c == ' \' ' ||
60
- c == ' (' ||
61
- c == ' )' ||
62
- c == ' *' ||
63
- c == ' +' ||
64
- c == ' ,' ||
65
- c == ' ;' ||
66
- c == ' ='
57
+ c == ' $' ||
58
+ c == ' &' ||
59
+ c == ' \' ' ||
60
+ c == ' (' ||
61
+ c == ' )' ||
62
+ c == ' *' ||
63
+ c == ' +' ||
64
+ c == ' ,' ||
65
+ c == ' ;' ||
66
+ c == ' ='
67
67
end
68
68
69
69
@inline function is_rfc3986_pchar (c:: Char )
70
70
return is_rfc3986_unreserved (c) ||
71
- is_rfc3986_sub_delim (c) ||
72
- c == ' :' ||
73
- c == ' @'
71
+ is_rfc3986_sub_delim (c) ||
72
+ c == ' :' ||
73
+ c == ' @'
74
74
end
75
75
76
76
@inline function is_rfc3986_query (c:: Char )
77
- return is_rfc3986_pchar (c) || c== ' /' || c== ' ?'
77
+ return is_rfc3986_pchar (c) || c == ' /' || c == ' ?'
78
78
end
79
79
80
80
@inline function is_rfc3986_fragment (c:: Char )
81
- return is_rfc3986_pchar (c) || c== ' /' || c== ' ?'
81
+ return is_rfc3986_pchar (c) || c == ' /' || c == ' ?'
82
82
end
83
83
84
84
@inline function is_rfc3986_userinfo (c:: Char )
85
85
return is_rfc3986_unreserved (c) ||
86
- is_rfc3986_sub_delim (c) ||
87
- c == ' :'
86
+ is_rfc3986_sub_delim (c) ||
87
+ c == ' :'
88
88
end
89
89
90
90
@inline function is_rfc3986_reg_name (c:: Char )
91
91
return is_rfc3986_unreserved (c) ||
92
- is_rfc3986_sub_delim (c)
92
+ is_rfc3986_sub_delim (c)
93
93
end
94
94
95
95
function encode (io:: IO , s:: AbstractString , issafe:: Function )
@@ -104,14 +104,14 @@ function encode(io::IO, s::AbstractString, issafe::Function)
104
104
end
105
105
106
106
@inline function is_ipv4address (s:: AbstractString )
107
- if length (s)== 1
107
+ if length (s) == 1
108
108
return ' 0' <= s[1 ] <= ' 9'
109
- elseif length (s)== 2
109
+ elseif length (s) == 2
110
110
return ' 1' <= s[1 ] <= ' 9' && ' 0' <= s[2 ] <= ' 9'
111
- elseif length (s)== 3
112
- return (s[1 ]== ' 1' && ' 0' <= s[2 ] <= ' 9' && ' 0' <= s[3 ] <= ' 9' ) ||
113
- (s[1 ]== ' 2' && ' 0' <= s[2 ] <= ' 4' && ' 0' <= s[3 ] <= ' 9' ) ||
114
- (s[1 ]== ' 2' && s[2 ] == ' 5' && ' 0' <= s[3 ] <= ' 5' )
111
+ elseif length (s) == 3
112
+ return (s[1 ] == ' 1' && ' 0' <= s[2 ] <= ' 9' && ' 0' <= s[3 ] <= ' 9' ) ||
113
+ (s[1 ] == ' 2' && ' 0' <= s[2 ] <= ' 4' && ' 0' <= s[3 ] <= ' 9' ) ||
114
+ (s[1 ] == ' 2' && s[2 ] == ' 5' && ' 0' <= s[3 ] <= ' 5' )
115
115
else
116
116
return false
117
117
end
@@ -143,44 +143,44 @@ function Base.print(io::IO, uri::URI)
143
143
query = uri. query
144
144
fragment = uri. fragment
145
145
146
- if scheme!= = nothing
146
+ if scheme != = nothing
147
147
print (io, scheme)
148
148
print (io, ' :' )
149
- end
149
+ end
150
150
151
- if authority!= = nothing
151
+ if authority != = nothing
152
152
print (io, " //" )
153
153
154
- idx = findfirst (" @" , authority)
155
- if idx != = nothing
156
- # <user>@<auth>
157
- userinfo = SubString (authority, 1 : idx. start- 1 )
158
- host_and_port = SubString (authority, idx. start + 1 )
159
- encode (io, userinfo, is_rfc3986_userinfo)
154
+ idx = findfirst (" @" , authority)
155
+ if idx != = nothing
156
+ # <user>@<auth>
157
+ userinfo = SubString (authority, 1 : idx. start- 1 )
158
+ host_and_port = SubString (authority, idx. start + 1 )
159
+ encode (io, userinfo, is_rfc3986_userinfo)
160
160
print (io, ' @' )
161
161
else
162
162
host_and_port = SubString (authority, 1 )
163
- end
163
+ end
164
164
165
- idx3 = findfirst (" :" , host_and_port)
166
- if idx3 === nothing
165
+ idx3 = findfirst (" :" , host_and_port)
166
+ if idx3 === nothing
167
167
encode_host (io, host_and_port)
168
- else
169
- # <auth>:<port>
168
+ else
169
+ # <auth>:<port>
170
170
encode_host (io, SubString (host_and_port, 1 : idx3. start- 1 ))
171
- print (io, SubString (host_and_port, idx3. start))
171
+ print (io, SubString (host_and_port, idx3. start))
172
172
end
173
- end
173
+ end
174
174
175
- # Append path
176
- encode_path (io, path)
175
+ # Append path
176
+ encode_path (io, path)
177
177
178
- if query!= = nothing
178
+ if query != = nothing
179
179
print (io, ' ?' )
180
180
encode (io, query, is_rfc3986_query)
181
181
end
182
182
183
- if fragment!= = nothing
183
+ if fragment != = nothing
184
184
print (io, ' #' )
185
185
encode (io, fragment, is_rfc3986_fragment)
186
186
end
0 commit comments