@@ -25,6 +25,7 @@ use std::hash::Hash;
25
25
use std:: io:: BufReader ;
26
26
use std:: from_str:: FromStr ;
27
27
use std:: uint;
28
+ use std:: vec_ng:: Vec ;
28
29
29
30
use collections:: HashMap ;
30
31
@@ -42,7 +43,7 @@ use collections::HashMap;
42
43
/// host: ~"example.com",
43
44
/// port: Some(~"8080"),
44
45
/// path: ~"/foo/bar",
45
- /// query: ~[( ~"baz", ~"qux")] ,
46
+ /// query: vec!(( ~"baz", ~"qux")) ,
46
47
/// fragment: Some(~"quz") };
47
48
/// // https://[email protected] :8080/foo/bar?baz=qux#quz
48
49
/// ```
@@ -58,7 +59,7 @@ pub struct Url {
58
59
port : Option < ~str > ,
59
60
/// The path component of a URL, for example `/foo/bar`.
60
61
path : ~str ,
61
- /// The query component of a URL. `~[( ~"baz", ~"qux")] ` represents the
62
+ /// The query component of a URL. `vec!(( ~"baz", ~"qux")) ` represents the
62
63
/// fragment `baz=qux` in the above example.
63
64
query : Query ,
64
65
/// The fragment component, such as `quz`. Doesn't include the leading `#` character.
@@ -69,7 +70,7 @@ pub struct Url {
69
70
pub struct Path {
70
71
/// The path component of a URL, for example `/foo/bar`.
71
72
path : ~str ,
72
- /// The query component of a URL. `~[( ~"baz", ~"qux")] ` represents the
73
+ /// The query component of a URL. `vec!(( ~"baz", ~"qux")) ` represents the
73
74
/// fragment `baz=qux` in the above example.
74
75
query : Query ,
75
76
/// The fragment component, such as `quz`. Doesn't include the leading `#` character.
@@ -86,7 +87,7 @@ pub struct UserInfo {
86
87
}
87
88
88
89
/// Represents the query component of a URI.
89
- pub type Query = ~ [ ( ~str , ~str ) ] ;
90
+ pub type Query = Vec < ( ~str , ~str ) > ;
90
91
91
92
impl Url {
92
93
pub fn new ( scheme : ~str ,
@@ -298,7 +299,7 @@ fn encode_plus(s: &str) -> ~str {
298
299
/**
299
300
* Encode a hashmap to the 'application/x-www-form-urlencoded' media type.
300
301
*/
301
- pub fn encode_form_urlencoded ( m : & HashMap < ~str , ~ [ ~ str ] > ) -> ~str {
302
+ pub fn encode_form_urlencoded ( m : & HashMap < ~str , Vec < ~ str > > ) -> ~str {
302
303
let mut out = ~"";
303
304
let mut first = true ;
304
305
@@ -324,7 +325,7 @@ pub fn encode_form_urlencoded(m: &HashMap<~str, ~[~str]>) -> ~str {
324
325
* Decode a string encoded with the 'application/x-www-form-urlencoded' media
325
326
* type into a hashmap.
326
327
*/
327
- pub fn decode_form_urlencoded( s : & [ u8 ] ) -> HashMap < ~str , ~ [ ~ str ] > {
328
+ pub fn decode_form_urlencoded( s : & [ u8 ] ) -> HashMap < ~str , Vec < ~ str > > {
328
329
let mut rdr = BufReader :: new ( s) ;
329
330
let mut m = HashMap :: new ( ) ;
330
331
let mut key = ~"";
@@ -342,7 +343,7 @@ pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, ~[~str]> {
342
343
if key != ~"" && value != ~"" {
343
344
let mut values = match m. pop ( & key) {
344
345
Some ( values) => values,
345
- None => ~ [ ] ,
346
+ None => vec ! ( ) ,
346
347
} ;
347
348
348
349
values. push ( value) ;
@@ -380,7 +381,7 @@ pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, ~[~str]> {
380
381
if key != ~"" && value != ~"" {
381
382
let mut values = match m. pop ( & key) {
382
383
Some ( values) => values,
383
- None => ~ [ ] ,
384
+ None => vec ! ( ) ,
384
385
} ;
385
386
386
387
values. push ( value) ;
@@ -427,7 +428,7 @@ impl fmt::Show for UserInfo {
427
428
}
428
429
429
430
fn query_from_str ( rawquery : & str ) -> Query {
430
- let mut query: Query = ~ [ ] ;
431
+ let mut query: Query = vec ! ( ) ;
431
432
if !rawquery. is_empty ( ) {
432
433
for p in rawquery. split ( '&' ) {
433
434
let ( k, v) = split_char_first ( p, '=' ) ;
@@ -443,7 +444,7 @@ fn query_from_str(rawquery: &str) -> Query {
443
444
* # Example
444
445
*
445
446
* ```rust
446
- * let query = ~[( ~"title", ~"The Village"), (~"north", ~"52.91"), (~"west", ~"4.10")] ;
447
+ * let query = vec!(( ~"title", ~"The Village"), (~"north", ~"52.91"), (~"west", ~"4.10")) ;
447
448
* println!("{}", url::query_to_str(&query)); // title=The%20Village&north=52.91&west=4.10
448
449
* ```
449
450
*/
@@ -709,9 +710,9 @@ fn get_query_fragment(rawurl: &str) ->
709
710
let f = decode_component ( rawurl. slice (
710
711
1 ,
711
712
rawurl. len ( ) ) ) ;
712
- return Ok ( ( ~ [ ] , Some ( f) ) ) ;
713
+ return Ok ( ( vec ! ( ) , Some ( f) ) ) ;
713
714
} else {
714
- return Ok ( ( ~ [ ] , None ) ) ;
715
+ return Ok ( ( vec ! ( ) , None ) ) ;
715
716
}
716
717
}
717
718
let ( q, r) = split_char_first ( rawurl. slice ( 1 , rawurl. len ( ) ) , '#' ) ;
@@ -953,7 +954,7 @@ fn test_get_path() {
953
954
954
955
#[cfg(test)]
955
956
mod tests {
956
- use {encode_form_urlencoded, decode_form_urlencoded, decode_component,
957
+ use {encode_form_urlencoded, decode_form_urlencoded,
957
958
decode, encode, from_str, encode_component, decode_component,
958
959
path_from_str, UserInfo, get_scheme};
959
960
@@ -970,7 +971,7 @@ mod tests {
970
971
assert_eq!(&u.host, &~" rust-lang. org");
971
972
assert_eq!(&u.port, &Some(~" 8080 "));
972
973
assert_eq!(&u.path, &~" /doc/~u");
973
- assert_eq!(&u.query, &~[( ~" s", ~" v")] );
974
+ assert_eq!(&u.query, &vec!(( ~" s", ~" v")) );
974
975
assert_eq!(&u.fragment, &Some(~" something"));
975
976
}
976
977
@@ -981,7 +982,7 @@ mod tests {
981
982
let up = path_from_str(path);
982
983
let u = up.unwrap();
983
984
assert_eq!(&u.path, &~" /doc/~u");
984
- assert_eq!(&u.query, &~[( ~" s", ~" v")] );
985
+ assert_eq!(&u.query, &vec!(( ~" s", ~" v")) );
985
986
assert_eq!(&u.fragment, &Some(~" something"));
986
987
}
987
988
@@ -1121,15 +1122,15 @@ mod tests {
1121
1122
let url = ~"http: //rust-lang.org/doc%20uments?ba%25d%20=%23%26%2B";
1122
1123
let u = from_str( url) . unwrap( ) ;
1123
1124
assert!( u. path == ~"/doc uments");
1124
- assert!(u.query == ~[( ~" ba%d ", ~" #& +")] );
1125
+ assert!(u.query == vec!(( ~" ba%d ", ~" #& +")) );
1125
1126
}
1126
1127
1127
1128
#[test]
1128
1129
fn test_path_component_encoding() {
1129
1130
let path = ~" /doc%20 uments?ba%25 d%20 =%23 %26 %2 B ";
1130
1131
let p = path_from_str(path).unwrap();
1131
1132
assert!(p.path == ~" /doc uments");
1132
- assert!(p.query == ~[( ~" ba%d ", ~" #& +")] );
1133
+ assert!(p.query == vec!(( ~" ba%d ", ~" #& +")) );
1133
1134
}
1134
1135
1135
1136
#[test]
@@ -1256,16 +1257,16 @@ mod tests {
1256
1257
let mut m = HashMap::new();
1257
1258
assert_eq!(encode_form_urlencoded(&m), ~" ");
1258
1259
1259
- m.insert(~" ", ~[] );
1260
- m.insert(~" foo", ~[] );
1260
+ m.insert(~" ", vec!() );
1261
+ m.insert(~" foo", vec!() );
1261
1262
assert_eq!(encode_form_urlencoded(&m), ~" ");
1262
1263
1263
1264
let mut m = HashMap::new();
1264
- m.insert(~" foo", ~[~ " bar", ~" 123 "] );
1265
+ m.insert(~" foo", vec!(~ " bar", ~" 123 ") );
1265
1266
assert_eq!(encode_form_urlencoded(&m), ~" foo=bar& foo=123 ");
1266
1267
1267
1268
let mut m = HashMap::new();
1268
- m.insert(~" foo bar", ~[~ " abc", ~" 12 = 34 "] );
1269
+ m.insert(~" foo bar", vec!(~ " abc", ~" 12 = 34 ") );
1269
1270
assert!(encode_form_urlencoded(&m) ==
1270
1271
~" foo+bar=abc& foo+bar=12 +%3 D +34 ");
1271
1272
}
@@ -1277,7 +1278,7 @@ mod tests {
1277
1278
let s = " a=1 & foo+bar=abc& foo+bar=12 +%3 D +34 ".as_bytes();
1278
1279
let form = decode_form_urlencoded(s);
1279
1280
assert_eq!(form.len(), 2);
1280
- assert_eq!(form.get(&~" a"), &~[~ " 1 "] );
1281
- assert_eq!(form.get(&~" foo bar"), &~[~ " abc", ~" 12 = 34 "] ) ;
1281
+ assert_eq!(form.get(&~" a"), &vec!(~ " 1 ") );
1282
+ assert_eq!(form.get(&~" foo bar"), &vec!(~ " abc", ~" 12 = 34 ") ) ;
1282
1283
}
1283
1284
}
0 commit comments