@@ -28,6 +28,7 @@ use std::hash::Hash;
28
28
use std:: io:: BufReader ;
29
29
use std:: from_str:: FromStr ;
30
30
use std:: uint;
31
+ use std:: vec_ng:: Vec ;
31
32
32
33
use collections:: HashMap ;
33
34
@@ -45,7 +46,7 @@ use collections::HashMap;
45
46
/// host: ~"example.com",
46
47
/// port: Some(~"8080"),
47
48
/// path: ~"/foo/bar",
48
- /// query: ~[( ~"baz", ~"qux")] ,
49
+ /// query: vec!(( ~"baz", ~"qux")) ,
49
50
/// fragment: Some(~"quz") };
50
51
/// // https://username@example.com:8080/foo/bar?baz=qux#quz
51
52
/// ```
@@ -61,7 +62,7 @@ pub struct Url {
61
62
port : Option < ~str > ,
62
63
/// The path component of a URL, for example `/foo/bar`.
63
64
path : ~str ,
64
- /// The query component of a URL. `~[( ~"baz", ~"qux")] ` represents the
65
+ /// The query component of a URL. `vec!(( ~"baz", ~"qux")) ` represents the
65
66
/// fragment `baz=qux` in the above example.
66
67
query : Query ,
67
68
/// The fragment component, such as `quz`. Doesn't include the leading `#` character.
@@ -72,7 +73,7 @@ pub struct Url {
72
73
pub struct Path {
73
74
/// The path component of a URL, for example `/foo/bar`.
74
75
path : ~str ,
75
- /// The query component of a URL. `~[( ~"baz", ~"qux")] ` represents the
76
+ /// The query component of a URL. `vec!(( ~"baz", ~"qux")) ` represents the
76
77
/// fragment `baz=qux` in the above example.
77
78
query : Query ,
78
79
/// The fragment component, such as `quz`. Doesn't include the leading `#` character.
@@ -89,7 +90,7 @@ pub struct UserInfo {
89
90
}
90
91
91
92
/// Represents the query component of a URI.
92
- pub type Query = ~ [ ( ~str , ~str ) ] ;
93
+ pub type Query = Vec < ( ~str , ~str ) > ;
93
94
94
95
impl Url {
95
96
pub fn new ( scheme : ~str ,
@@ -301,7 +302,7 @@ fn encode_plus(s: &str) -> ~str {
301
302
/**
302
303
* Encode a hashmap to the 'application/x-www-form-urlencoded' media type.
303
304
*/
304
- pub fn encode_form_urlencoded ( m : & HashMap < ~str , ~ [ ~ str ] > ) -> ~str {
305
+ pub fn encode_form_urlencoded ( m : & HashMap < ~str , Vec < ~ str > > ) -> ~str {
305
306
let mut out = ~"";
306
307
let mut first = true ;
307
308
@@ -327,7 +328,7 @@ pub fn encode_form_urlencoded(m: &HashMap<~str, ~[~str]>) -> ~str {
327
328
* Decode a string encoded with the 'application/x-www-form-urlencoded' media
328
329
* type into a hashmap.
329
330
*/
330
- pub fn decode_form_urlencoded( s : & [ u8 ] ) -> HashMap < ~str , ~ [ ~ str ] > {
331
+ pub fn decode_form_urlencoded( s : & [ u8 ] ) -> HashMap < ~str , Vec < ~ str > > {
331
332
let mut rdr = BufReader :: new ( s) ;
332
333
let mut m = HashMap :: new ( ) ;
333
334
let mut key = ~"";
@@ -345,7 +346,7 @@ pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, ~[~str]> {
345
346
if key != ~"" && value != ~"" {
346
347
let mut values = match m. pop ( & key) {
347
348
Some ( values) => values,
348
- None => ~ [ ] ,
349
+ None => vec ! ( ) ,
349
350
} ;
350
351
351
352
values. push ( value) ;
@@ -383,7 +384,7 @@ pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, ~[~str]> {
383
384
if key != ~"" && value != ~"" {
384
385
let mut values = match m. pop ( & key) {
385
386
Some ( values) => values,
386
- None => ~ [ ] ,
387
+ None => vec ! ( ) ,
387
388
} ;
388
389
389
390
values. push ( value) ;
@@ -430,7 +431,7 @@ impl fmt::Show for UserInfo {
430
431
}
431
432
432
433
fn query_from_str ( rawquery : & str ) -> Query {
433
- let mut query: Query = ~ [ ] ;
434
+ let mut query: Query = vec ! ( ) ;
434
435
if !rawquery. is_empty ( ) {
435
436
for p in rawquery. split ( '&' ) {
436
437
let ( k, v) = split_char_first ( p, '=' ) ;
@@ -446,7 +447,7 @@ fn query_from_str(rawquery: &str) -> Query {
446
447
* # Example
447
448
*
448
449
* ```rust
449
- * let query = ~[( ~"title", ~"The Village"), (~"north", ~"52.91"), (~"west", ~"4.10")] ;
450
+ * let query = vec!(( ~"title", ~"The Village"), (~"north", ~"52.91"), (~"west", ~"4.10")) ;
450
451
* println!("{}", url::query_to_str(&query)); // title=The%20Village&north=52.91&west=4.10
451
452
* ```
452
453
*/
@@ -712,9 +713,9 @@ fn get_query_fragment(rawurl: &str) ->
712
713
let f = decode_component ( rawurl. slice (
713
714
1 ,
714
715
rawurl. len ( ) ) ) ;
715
- return Ok ( ( ~ [ ] , Some ( f) ) ) ;
716
+ return Ok ( ( vec ! ( ) , Some ( f) ) ) ;
716
717
} else {
717
- return Ok ( ( ~ [ ] , None ) ) ;
718
+ return Ok ( ( vec ! ( ) , None ) ) ;
718
719
}
719
720
}
720
721
let ( q, r) = split_char_first ( rawurl. slice ( 1 , rawurl. len ( ) ) , '#' ) ;
@@ -956,7 +957,7 @@ fn test_get_path() {
956
957
957
958
#[cfg(test)]
958
959
mod tests {
959
- use {encode_form_urlencoded, decode_form_urlencoded, decode_component,
960
+ use {encode_form_urlencoded, decode_form_urlencoded,
960
961
decode, encode, from_str, encode_component, decode_component,
961
962
path_from_str, UserInfo, get_scheme};
962
963
@@ -973,7 +974,7 @@ mod tests {
973
974
assert_eq!(&u.host, &~" rust-lang. org");
974
975
assert_eq!(&u.port, &Some(~" 8080 "));
975
976
assert_eq!(&u.path, &~" /doc/~u");
976
- assert_eq!(&u.query, &~[( ~" s", ~" v")] );
977
+ assert_eq!(&u.query, &vec!(( ~" s", ~" v")) );
977
978
assert_eq!(&u.fragment, &Some(~" something"));
978
979
}
979
980
@@ -984,7 +985,7 @@ mod tests {
984
985
let up = path_from_str(path);
985
986
let u = up.unwrap();
986
987
assert_eq!(&u.path, &~" /doc/~u");
987
- assert_eq!(&u.query, &~[( ~" s", ~" v")] );
988
+ assert_eq!(&u.query, &vec!(( ~" s", ~" v")) );
988
989
assert_eq!(&u.fragment, &Some(~" something"));
989
990
}
990
991
@@ -1124,15 +1125,15 @@ mod tests {
1124
1125
let url = ~"http: //rust-lang.org/doc%20uments?ba%25d%20=%23%26%2B";
1125
1126
let u = from_str( url) . unwrap( ) ;
1126
1127
assert!( u. path == ~"/doc uments");
1127
- assert!(u.query == ~[( ~" ba%d ", ~" #& +")] );
1128
+ assert!(u.query == vec!(( ~" ba%d ", ~" #& +")) );
1128
1129
}
1129
1130
1130
1131
#[test]
1131
1132
fn test_path_component_encoding() {
1132
1133
let path = ~" /doc%20 uments?ba%25 d%20 =%23 %26 %2 B ";
1133
1134
let p = path_from_str(path).unwrap();
1134
1135
assert!(p.path == ~" /doc uments");
1135
- assert!(p.query == ~[( ~" ba%d ", ~" #& +")] );
1136
+ assert!(p.query == vec!(( ~" ba%d ", ~" #& +")) );
1136
1137
}
1137
1138
1138
1139
#[test]
@@ -1259,16 +1260,16 @@ mod tests {
1259
1260
let mut m = HashMap::new();
1260
1261
assert_eq!(encode_form_urlencoded(&m), ~" ");
1261
1262
1262
- m.insert(~" ", ~[] );
1263
- m.insert(~" foo", ~[] );
1263
+ m.insert(~" ", vec!() );
1264
+ m.insert(~" foo", vec!() );
1264
1265
assert_eq!(encode_form_urlencoded(&m), ~" ");
1265
1266
1266
1267
let mut m = HashMap::new();
1267
- m.insert(~" foo", ~[~ " bar", ~" 123 "] );
1268
+ m.insert(~" foo", vec!(~ " bar", ~" 123 ") );
1268
1269
assert_eq!(encode_form_urlencoded(&m), ~" foo=bar& foo=123 ");
1269
1270
1270
1271
let mut m = HashMap::new();
1271
- m.insert(~" foo bar", ~[~ " abc", ~" 12 = 34 "] );
1272
+ m.insert(~" foo bar", vec!(~ " abc", ~" 12 = 34 ") );
1272
1273
assert!(encode_form_urlencoded(&m) ==
1273
1274
~" foo+bar=abc& foo+bar=12 +%3 D +34 ");
1274
1275
}
@@ -1280,7 +1281,7 @@ mod tests {
1280
1281
let s = " a=1 & foo+bar=abc& foo+bar=12 +%3 D +34 ".as_bytes();
1281
1282
let form = decode_form_urlencoded(s);
1282
1283
assert_eq!(form.len(), 2);
1283
- assert_eq!(form.get(&~" a"), &~[~ " 1 "] );
1284
- assert_eq!(form.get(&~" foo bar"), &~[~ " abc", ~" 12 = 34 "] ) ;
1284
+ assert_eq!(form.get(&~" a"), &vec!(~ " 1 ") );
1285
+ assert_eq!(form.get(&~" foo bar"), &vec!(~ " abc", ~" 12 = 34 ") ) ;
1285
1286
}
1286
1287
}
0 commit comments