@@ -28,6 +28,7 @@ use std::hash::Hash;
2828use std:: io:: BufReader ;
2929use std:: from_str:: FromStr ;
3030use std:: uint;
31+ use std:: vec_ng:: Vec ;
3132
3233use collections:: HashMap ;
3334
@@ -45,7 +46,7 @@ use collections::HashMap;
4546/// host: ~"example.com",
4647/// port: Some(~"8080"),
4748/// path: ~"/foo/bar",
48- /// query: ~[( ~"baz", ~"qux")] ,
49+ /// query: vec!(( ~"baz", ~"qux")) ,
4950/// fragment: Some(~"quz") };
5051/// // https://[email protected] :8080/foo/bar?baz=qux#quz 5152/// ```
@@ -61,7 +62,7 @@ pub struct Url {
6162 port : Option < ~str > ,
6263 /// The path component of a URL, for example `/foo/bar`.
6364 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
6566 /// fragment `baz=qux` in the above example.
6667 query : Query ,
6768 /// The fragment component, such as `quz`. Doesn't include the leading `#` character.
@@ -72,7 +73,7 @@ pub struct Url {
7273pub struct Path {
7374 /// The path component of a URL, for example `/foo/bar`.
7475 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
7677 /// fragment `baz=qux` in the above example.
7778 query : Query ,
7879 /// The fragment component, such as `quz`. Doesn't include the leading `#` character.
@@ -89,7 +90,7 @@ pub struct UserInfo {
8990}
9091
9192/// Represents the query component of a URI.
92- pub type Query = ~ [ ( ~str , ~str ) ] ;
93+ pub type Query = Vec < ( ~str , ~str ) > ;
9394
9495impl Url {
9596 pub fn new ( scheme : ~str ,
@@ -301,7 +302,7 @@ fn encode_plus(s: &str) -> ~str {
301302/**
302303 * Encode a hashmap to the 'application/x-www-form-urlencoded' media type.
303304 */
304- pub fn encode_form_urlencoded ( m : & HashMap < ~str , ~ [ ~ str ] > ) -> ~str {
305+ pub fn encode_form_urlencoded ( m : & HashMap < ~str , Vec < ~ str > > ) -> ~str {
305306 let mut out = ~"";
306307 let mut first = true ;
307308
@@ -327,7 +328,7 @@ pub fn encode_form_urlencoded(m: &HashMap<~str, ~[~str]>) -> ~str {
327328 * Decode a string encoded with the 'application/x-www-form-urlencoded' media
328329 * type into a hashmap.
329330 */
330- pub fn decode_form_urlencoded( s : & [ u8 ] ) -> HashMap < ~str , ~ [ ~ str ] > {
331+ pub fn decode_form_urlencoded( s : & [ u8 ] ) -> HashMap < ~str , Vec < ~ str > > {
331332 let mut rdr = BufReader :: new ( s) ;
332333 let mut m = HashMap :: new ( ) ;
333334 let mut key = ~"";
@@ -345,7 +346,7 @@ pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, ~[~str]> {
345346 if key != ~"" && value != ~"" {
346347 let mut values = match m. pop ( & key) {
347348 Some ( values) => values,
348- None => ~ [ ] ,
349+ None => vec ! ( ) ,
349350 } ;
350351
351352 values. push ( value) ;
@@ -383,7 +384,7 @@ pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, ~[~str]> {
383384 if key != ~"" && value != ~"" {
384385 let mut values = match m. pop ( & key) {
385386 Some ( values) => values,
386- None => ~ [ ] ,
387+ None => vec ! ( ) ,
387388 } ;
388389
389390 values. push ( value) ;
@@ -430,7 +431,7 @@ impl fmt::Show for UserInfo {
430431}
431432
432433fn query_from_str ( rawquery : & str ) -> Query {
433- let mut query: Query = ~ [ ] ;
434+ let mut query: Query = vec ! ( ) ;
434435 if !rawquery. is_empty ( ) {
435436 for p in rawquery. split ( '&' ) {
436437 let ( k, v) = split_char_first ( p, '=' ) ;
@@ -446,7 +447,7 @@ fn query_from_str(rawquery: &str) -> Query {
446447 * # Example
447448 *
448449 * ```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")) ;
450451 * println!("{}", url::query_to_str(&query)); // title=The%20Village&north=52.91&west=4.10
451452 * ```
452453 */
@@ -712,9 +713,9 @@ fn get_query_fragment(rawurl: &str) ->
712713 let f = decode_component ( rawurl. slice (
713714 1 ,
714715 rawurl. len ( ) ) ) ;
715- return Ok ( ( ~ [ ] , Some ( f) ) ) ;
716+ return Ok ( ( vec ! ( ) , Some ( f) ) ) ;
716717 } else {
717- return Ok ( ( ~ [ ] , None ) ) ;
718+ return Ok ( ( vec ! ( ) , None ) ) ;
718719 }
719720 }
720721 let ( q, r) = split_char_first ( rawurl. slice ( 1 , rawurl. len ( ) ) , '#' ) ;
@@ -956,7 +957,7 @@ fn test_get_path() {
956957
957958#[cfg(test)]
958959mod tests {
959- use {encode_form_urlencoded, decode_form_urlencoded, decode_component,
960+ use {encode_form_urlencoded, decode_form_urlencoded,
960961 decode, encode, from_str, encode_component, decode_component,
961962 path_from_str, UserInfo, get_scheme};
962963
@@ -973,7 +974,7 @@ mod tests {
973974 assert_eq!(&u.host, &~" rust-lang. org");
974975 assert_eq!(&u.port, &Some(~" 8080 "));
975976 assert_eq!(&u.path, &~" /doc/~u");
976- assert_eq!(&u.query, &~[( ~" s", ~" v")] );
977+ assert_eq!(&u.query, &vec!(( ~" s", ~" v")) );
977978 assert_eq!(&u.fragment, &Some(~" something"));
978979 }
979980
@@ -984,7 +985,7 @@ mod tests {
984985 let up = path_from_str(path);
985986 let u = up.unwrap();
986987 assert_eq!(&u.path, &~" /doc/~u");
987- assert_eq!(&u.query, &~[( ~" s", ~" v")] );
988+ assert_eq!(&u.query, &vec!(( ~" s", ~" v")) );
988989 assert_eq!(&u.fragment, &Some(~" something"));
989990 }
990991
@@ -1124,15 +1125,15 @@ mod tests {
11241125 let url = ~"http: //rust-lang.org/doc%20uments?ba%25d%20=%23%26%2B";
11251126 let u = from_str( url) . unwrap( ) ;
11261127 assert!( u. path == ~"/doc uments");
1127- assert!(u.query == ~[( ~" ba%d ", ~" #& +")] );
1128+ assert!(u.query == vec!(( ~" ba%d ", ~" #& +")) );
11281129 }
11291130
11301131 #[test]
11311132 fn test_path_component_encoding() {
11321133 let path = ~" /doc%20 uments?ba%25 d%20 =%23 %26 %2 B ";
11331134 let p = path_from_str(path).unwrap();
11341135 assert!(p.path == ~" /doc uments");
1135- assert!(p.query == ~[( ~" ba%d ", ~" #& +")] );
1136+ assert!(p.query == vec!(( ~" ba%d ", ~" #& +")) );
11361137 }
11371138
11381139 #[test]
@@ -1259,16 +1260,16 @@ mod tests {
12591260 let mut m = HashMap::new();
12601261 assert_eq!(encode_form_urlencoded(&m), ~" ");
12611262
1262- m.insert(~" ", ~[] );
1263- m.insert(~" foo", ~[] );
1263+ m.insert(~" ", vec!() );
1264+ m.insert(~" foo", vec!() );
12641265 assert_eq!(encode_form_urlencoded(&m), ~" ");
12651266
12661267 let mut m = HashMap::new();
1267- m.insert(~" foo", ~[~ " bar", ~" 123 "] );
1268+ m.insert(~" foo", vec!(~ " bar", ~" 123 ") );
12681269 assert_eq!(encode_form_urlencoded(&m), ~" foo=bar& foo=123 ");
12691270
12701271 let mut m = HashMap::new();
1271- m.insert(~" foo bar", ~[~ " abc", ~" 12 = 34 "] );
1272+ m.insert(~" foo bar", vec!(~ " abc", ~" 12 = 34 ") );
12721273 assert!(encode_form_urlencoded(&m) ==
12731274 ~" foo+bar=abc& foo+bar=12 +%3 D +34 ");
12741275 }
@@ -1280,7 +1281,7 @@ mod tests {
12801281 let s = " a=1 & foo+bar=abc& foo+bar=12 +%3 D +34 ".as_bytes();
12811282 let form = decode_form_urlencoded(s);
12821283 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 ") ) ;
12851286 }
12861287}
0 commit comments