1
1
//! Types/fns concerning URLs (see RFC 3986)
2
+ #[ forbid( deprecated_mode) ] ;
3
+ #[ forbid( deprecated_pattern) ] ;
2
4
3
5
use core:: cmp:: Eq ;
4
6
use map:: { hashmap, str_hash} ;
@@ -34,15 +36,16 @@ type UserInfo = {
34
36
35
37
type Query = ~[ ( ~str , ~str ) ] ;
36
38
37
- fn Url ( -scheme : ~str , -user : Option < UserInfo > , -host : ~str ,
38
- -port : Option < ~str > , -path : ~str , -query : Query ,
39
- -fragment : Option < ~str > ) -> Url {
40
- Url { scheme : scheme, user : user, host : host, port : port,
41
- path : path, query : query, fragment : fragment }
39
+ fn Url ( +scheme : ~str , +user : Option < UserInfo > , +host : ~str ,
40
+ +port : Option < ~str > , +path : ~str , +query : Query ,
41
+ +fragment : Option < ~str > ) -> Url {
42
+ Url { scheme : move scheme, user : move user, host : move host,
43
+ port : move port, path : move path, query : move query,
44
+ fragment : move fragment }
42
45
}
43
46
44
- fn UserInfo ( - user : ~str , - pass : Option < ~str > ) -> UserInfo {
45
- { user: user, pass: pass}
47
+ fn UserInfo ( + user : ~str , + pass : Option < ~str > ) -> UserInfo {
48
+ { user: move user, pass: move pass}
46
49
}
47
50
48
51
fn encode_inner ( s : & str , full_url : bool ) -> ~str {
@@ -104,7 +107,7 @@ fn encode_component(s: &str) -> ~str {
104
107
encode_inner ( s, false )
105
108
}
106
109
107
- fn decode_inner ( s : ~ str , full_url : bool ) -> ~str {
110
+ fn decode_inner ( s : & str , full_url : bool ) -> ~str {
108
111
do io:: with_str_reader ( s) |rdr| {
109
112
let mut out = ~"";
110
113
@@ -147,18 +150,18 @@ fn decode_inner(s: ~str, full_url: bool) -> ~str {
147
150
*
148
151
* This will only decode escape sequences generated by encode_uri.
149
152
*/
150
- fn decode ( s : ~ str ) -> ~str {
153
+ fn decode ( s : & str ) -> ~str {
151
154
decode_inner ( s, true )
152
155
}
153
156
154
157
/**
155
158
* Decode a string encoded with percent encoding.
156
159
*/
157
- fn decode_component ( s : ~ str ) -> ~str {
160
+ fn decode_component ( s : & str ) -> ~str {
158
161
decode_inner ( s, false )
159
162
}
160
163
161
- fn encode_plus ( s : ~ str ) -> ~str {
164
+ fn encode_plus ( s : & str ) -> ~str {
162
165
do io:: with_str_reader ( s) |rdr| {
163
166
let mut out = ~"";
164
167
@@ -269,7 +272,7 @@ fn decode_form_urlencoded(s: ~[u8]) ->
269
272
}
270
273
271
274
272
- fn split_char_first ( s : ~ str , c : char ) -> ( ~str , ~str ) {
275
+ fn split_char_first ( s : & str , c : char ) -> ( ~str , ~str ) {
273
276
let len = str:: len ( s) ;
274
277
let mut index = len;
275
278
let mut mat = 0 ;
@@ -293,7 +296,7 @@ fn split_char_first(s: ~str, c: char) -> (~str, ~str) {
293
296
}
294
297
}
295
298
296
- fn userinfo_from_str ( uinfo : ~ str ) -> UserInfo {
299
+ fn userinfo_from_str ( uinfo : & str ) -> UserInfo {
297
300
let ( user, p) = split_char_first ( uinfo, ':' ) ;
298
301
let pass = if str:: len ( p) == 0 {
299
302
option:: None
@@ -303,7 +306,7 @@ fn userinfo_from_str(uinfo: ~str) -> UserInfo {
303
306
return UserInfo ( user, pass) ;
304
307
}
305
308
306
- fn userinfo_to_str ( - userinfo : UserInfo ) -> ~str {
309
+ fn userinfo_to_str ( + userinfo : UserInfo ) -> ~str {
307
310
if option:: is_some ( userinfo. pass ) {
308
311
return str:: concat ( ~[ copy userinfo. user , ~": ",
309
312
option:: unwrap ( copy userinfo. pass ) ,
@@ -319,7 +322,7 @@ impl UserInfo : Eq {
319
322
}
320
323
}
321
324
322
- fn query_from_str ( rawquery : ~ str ) -> Query {
325
+ fn query_from_str ( rawquery : & str ) -> Query {
323
326
let mut query: Query = ~[ ] ;
324
327
if str:: len ( rawquery) != 0 {
325
328
for str:: split_char( rawquery, '&' ) . each |p| {
@@ -330,7 +333,7 @@ fn query_from_str(rawquery: ~str) -> Query {
330
333
return query;
331
334
}
332
335
333
- fn query_to_str ( query : Query ) -> ~str {
336
+ fn query_to_str ( + query : Query ) -> ~str {
334
337
let mut strvec = ~[ ] ;
335
338
for query. each |kv| {
336
339
let ( k, v) = copy kv;
@@ -676,7 +679,7 @@ impl Url : FromStr {
676
679
* result in just "http://somehost.com".
677
680
*
678
681
*/
679
- fn to_str( url: Url ) -> ~str {
682
+ fn to_str( + url: Url ) -> ~str {
680
683
let user = if option:: is_some ( url. user ) {
681
684
userinfo_to_str ( option:: unwrap ( copy url. user ) )
682
685
} else {
0 commit comments