Skip to content

Commit b1f5235

Browse files
committed
Remove most ~[] usage in liburl
1 parent 352c5e7 commit b1f5235

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

src/liburl/lib.rs

+24-23
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use std::hash::Hash;
2525
use std::io::BufReader;
2626
use std::from_str::FromStr;
2727
use std::uint;
28+
use std::vec_ng::Vec;
2829

2930
use collections::HashMap;
3031

@@ -42,7 +43,7 @@ use collections::HashMap;
4243
/// host: ~"example.com",
4344
/// port: Some(~"8080"),
4445
/// path: ~"/foo/bar",
45-
/// query: ~[(~"baz", ~"qux")],
46+
/// query: vec!((~"baz", ~"qux")),
4647
/// fragment: Some(~"quz") };
4748
/// // https://[email protected]:8080/foo/bar?baz=qux#quz
4849
/// ```
@@ -58,7 +59,7 @@ pub struct Url {
5859
port: Option<~str>,
5960
/// The path component of a URL, for example `/foo/bar`.
6061
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
6263
/// fragment `baz=qux` in the above example.
6364
query: Query,
6465
/// The fragment component, such as `quz`. Doesn't include the leading `#` character.
@@ -69,7 +70,7 @@ pub struct Url {
6970
pub struct Path {
7071
/// The path component of a URL, for example `/foo/bar`.
7172
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
7374
/// fragment `baz=qux` in the above example.
7475
query: Query,
7576
/// The fragment component, such as `quz`. Doesn't include the leading `#` character.
@@ -86,7 +87,7 @@ pub struct UserInfo {
8687
}
8788

8889
/// Represents the query component of a URI.
89-
pub type Query = ~[(~str, ~str)];
90+
pub type Query = Vec<(~str, ~str)>;
9091

9192
impl Url {
9293
pub fn new(scheme: ~str,
@@ -298,7 +299,7 @@ fn encode_plus(s: &str) -> ~str {
298299
/**
299300
* Encode a hashmap to the 'application/x-www-form-urlencoded' media type.
300301
*/
301-
pub fn encode_form_urlencoded(m: &HashMap<~str, ~[~str]>) -> ~str {
302+
pub fn encode_form_urlencoded(m: &HashMap<~str, Vec<~str>>) -> ~str {
302303
let mut out = ~"";
303304
let mut first = true;
304305

@@ -324,7 +325,7 @@ pub fn encode_form_urlencoded(m: &HashMap<~str, ~[~str]>) -> ~str {
324325
* Decode a string encoded with the 'application/x-www-form-urlencoded' media
325326
* type into a hashmap.
326327
*/
327-
pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, ~[~str]> {
328+
pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, Vec<~str>> {
328329
let mut rdr = BufReader::new(s);
329330
let mut m = HashMap::new();
330331
let mut key = ~"";
@@ -342,7 +343,7 @@ pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, ~[~str]> {
342343
if key != ~"" && value != ~"" {
343344
let mut values = match m.pop(&key) {
344345
Some(values) => values,
345-
None => ~[],
346+
None => vec!(),
346347
};
347348

348349
values.push(value);
@@ -380,7 +381,7 @@ pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, ~[~str]> {
380381
if key != ~"" && value != ~"" {
381382
let mut values = match m.pop(&key) {
382383
Some(values) => values,
383-
None => ~[],
384+
None => vec!(),
384385
};
385386

386387
values.push(value);
@@ -427,7 +428,7 @@ impl fmt::Show for UserInfo {
427428
}
428429

429430
fn query_from_str(rawquery: &str) -> Query {
430-
let mut query: Query = ~[];
431+
let mut query: Query = vec!();
431432
if !rawquery.is_empty() {
432433
for p in rawquery.split('&') {
433434
let (k, v) = split_char_first(p, '=');
@@ -443,7 +444,7 @@ fn query_from_str(rawquery: &str) -> Query {
443444
* # Example
444445
*
445446
* ```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"));
447448
* println!("{}", url::query_to_str(&query)); // title=The%20Village&north=52.91&west=4.10
448449
* ```
449450
*/
@@ -709,9 +710,9 @@ fn get_query_fragment(rawurl: &str) ->
709710
let f = decode_component(rawurl.slice(
710711
1,
711712
rawurl.len()));
712-
return Ok((~[], Some(f)));
713+
return Ok((vec!(), Some(f)));
713714
} else {
714-
return Ok((~[], None));
715+
return Ok((vec!(), None));
715716
}
716717
}
717718
let (q, r) = split_char_first(rawurl.slice(1, rawurl.len()), '#');
@@ -953,7 +954,7 @@ fn test_get_path() {
953954
954955
#[cfg(test)]
955956
mod tests {
956-
use {encode_form_urlencoded, decode_form_urlencoded, decode_component,
957+
use {encode_form_urlencoded, decode_form_urlencoded,
957958
decode, encode, from_str, encode_component, decode_component,
958959
path_from_str, UserInfo, get_scheme};
959960
@@ -970,7 +971,7 @@ mod tests {
970971
assert_eq!(&u.host, &~"rust-lang.org");
971972
assert_eq!(&u.port, &Some(~"8080"));
972973
assert_eq!(&u.path, &~"/doc/~u");
973-
assert_eq!(&u.query, &~[(~"s", ~"v")]);
974+
assert_eq!(&u.query, &vec!((~"s", ~"v")));
974975
assert_eq!(&u.fragment, &Some(~"something"));
975976
}
976977
@@ -981,7 +982,7 @@ mod tests {
981982
let up = path_from_str(path);
982983
let u = up.unwrap();
983984
assert_eq!(&u.path, &~"/doc/~u");
984-
assert_eq!(&u.query, &~[(~"s", ~"v")]);
985+
assert_eq!(&u.query, &vec!((~"s", ~"v")));
985986
assert_eq!(&u.fragment, &Some(~"something"));
986987
}
987988
@@ -1121,15 +1122,15 @@ mod tests {
11211122
let url = ~"http://rust-lang.org/doc%20uments?ba%25d%20=%23%26%2B";
11221123
let u = from_str(url).unwrap();
11231124
assert!(u.path == ~"/doc uments");
1124-
assert!(u.query == ~[(~"ba%d ", ~"#&+")]);
1125+
assert!(u.query == vec!((~"ba%d ", ~"#&+")));
11251126
}
11261127
11271128
#[test]
11281129
fn test_path_component_encoding() {
11291130
let path = ~"/doc%20uments?ba%25d%20=%23%26%2B";
11301131
let p = path_from_str(path).unwrap();
11311132
assert!(p.path == ~"/doc uments");
1132-
assert!(p.query == ~[(~"ba%d ", ~"#&+")]);
1133+
assert!(p.query == vec!((~"ba%d ", ~"#&+")));
11331134
}
11341135
11351136
#[test]
@@ -1256,16 +1257,16 @@ mod tests {
12561257
let mut m = HashMap::new();
12571258
assert_eq!(encode_form_urlencoded(&m), ~"");
12581259
1259-
m.insert(~"", ~[]);
1260-
m.insert(~"foo", ~[]);
1260+
m.insert(~"", vec!());
1261+
m.insert(~"foo", vec!());
12611262
assert_eq!(encode_form_urlencoded(&m), ~"");
12621263
12631264
let mut m = HashMap::new();
1264-
m.insert(~"foo", ~[~"bar", ~"123"]);
1265+
m.insert(~"foo", vec!(~"bar", ~"123"));
12651266
assert_eq!(encode_form_urlencoded(&m), ~"foo=bar&foo=123");
12661267
12671268
let mut m = HashMap::new();
1268-
m.insert(~"foo bar", ~[~"abc", ~"12 = 34"]);
1269+
m.insert(~"foo bar", vec!(~"abc", ~"12 = 34"));
12691270
assert!(encode_form_urlencoded(&m) ==
12701271
~"foo+bar=abc&foo+bar=12+%3D+34");
12711272
}
@@ -1277,7 +1278,7 @@ mod tests {
12771278
let s = "a=1&foo+bar=abc&foo+bar=12+%3D+34".as_bytes();
12781279
let form = decode_form_urlencoded(s);
12791280
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"));
12821283
}
12831284
}

0 commit comments

Comments
 (0)