1919function URI (value:: AbstractString )
2020 m = match (r" ^(([^:/?#]+?):)?(\/\/ ([^/?#]*))?([^?#]*)(\? ([^#]*))?(#(.*))?" , value)
2121
22- m=== nothing && error (" Invalid argument." )
22+ m === nothing && error (" Invalid argument." )
2323
2424 return URI (
2525 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 ])
3030 )
3131end
3232
@@ -38,58 +38,58 @@ function URI(;
3838 path:: AbstractString = " " ,
3939 query:: Union{AbstractString,Nothing} = nothing ,
4040 fragment:: Union{AbstractString,Nothing} = nothing
41- )
41+ )
4242 return URI (scheme, authority, path, query, fragment)
4343end
4444
4545@inline function is_rfc3986_unreserved (c:: Char )
4646 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 == ' ~'
5353end
5454
5555@inline function is_rfc3986_sub_delim (c:: Char )
5656 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 == ' ='
6767end
6868
6969@inline function is_rfc3986_pchar (c:: Char )
7070 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 == ' @'
7474end
7575
7676@inline function is_rfc3986_query (c:: Char )
77- return is_rfc3986_pchar (c) || c== ' /' || c== ' ?'
77+ return is_rfc3986_pchar (c) || c == ' /' || c == ' ?'
7878end
7979
8080@inline function is_rfc3986_fragment (c:: Char )
81- return is_rfc3986_pchar (c) || c== ' /' || c== ' ?'
81+ return is_rfc3986_pchar (c) || c == ' /' || c == ' ?'
8282end
8383
8484@inline function is_rfc3986_userinfo (c:: Char )
8585 return is_rfc3986_unreserved (c) ||
86- is_rfc3986_sub_delim (c) ||
87- c == ' :'
86+ is_rfc3986_sub_delim (c) ||
87+ c == ' :'
8888end
8989
9090@inline function is_rfc3986_reg_name (c:: Char )
9191 return is_rfc3986_unreserved (c) ||
92- is_rfc3986_sub_delim (c)
92+ is_rfc3986_sub_delim (c)
9393end
9494
9595function encode (io:: IO , s:: AbstractString , issafe:: Function )
@@ -104,14 +104,14 @@ function encode(io::IO, s::AbstractString, issafe::Function)
104104end
105105
106106@inline function is_ipv4address (s:: AbstractString )
107- if length (s)== 1
107+ if length (s) == 1
108108 return ' 0' <= s[1 ] <= ' 9'
109- elseif length (s)== 2
109+ elseif length (s) == 2
110110 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' )
115115 else
116116 return false
117117 end
@@ -143,44 +143,44 @@ function Base.print(io::IO, uri::URI)
143143 query = uri. query
144144 fragment = uri. fragment
145145
146- if scheme!= = nothing
146+ if scheme != = nothing
147147 print (io, scheme)
148148 print (io, ' :' )
149- end
149+ end
150150
151- if authority!= = nothing
151+ if authority != = nothing
152152 print (io, " //" )
153153
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)
160160 print (io, ' @' )
161161 else
162162 host_and_port = SubString (authority, 1 )
163- end
163+ end
164164
165- idx3 = findfirst (" :" , host_and_port)
166- if idx3 === nothing
165+ idx3 = findfirst (" :" , host_and_port)
166+ if idx3 === nothing
167167 encode_host (io, host_and_port)
168- else
169- # <auth>:<port>
168+ else
169+ # <auth>:<port>
170170 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))
172172 end
173- end
173+ end
174174
175- # Append path
176- encode_path (io, path)
175+ # Append path
176+ encode_path (io, path)
177177
178- if query!= = nothing
178+ if query != = nothing
179179 print (io, ' ?' )
180180 encode (io, query, is_rfc3986_query)
181181 end
182182
183- if fragment!= = nothing
183+ if fragment != = nothing
184184 print (io, ' #' )
185185 encode (io, fragment, is_rfc3986_fragment)
186186 end
0 commit comments