Skip to content

Commit e49c30a

Browse files
committed
auto merge of #12923 : sfackler/rust/vecify, r=brson
2 parents de78d7f + a37ca8c commit e49c30a

File tree

2 files changed

+48
-48
lines changed

2 files changed

+48
-48
lines changed

src/libsemver/lib.rs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@
3636
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
3737
html_root_url = "http://static.rust-lang.org/doc/master")];
3838

39-
#[allow(deprecated_owned_vector)];
40-
4139
use std::char;
4240
use std::cmp;
4341
use std::fmt;
4442
use std::fmt::Show;
4543
use std::option::{Option, Some, None};
44+
use std::vec_ng::Vec;
4645

4746
/// An identifier in the pre-release or build metadata. If the identifier can
4847
/// be parsed as a decimal value, it will be represented with `Numeric`.
@@ -88,9 +87,9 @@ pub struct Version {
8887
/// fixes are made.
8988
patch: uint,
9089
/// The pre-release version identifier, if one exists.
91-
pre: ~[Identifier],
90+
pre: Vec<Identifier>,
9291
/// The build metadata, ignored when determining version precedence.
93-
build: ~[Identifier],
92+
build: Vec<Identifier>,
9493
}
9594

9695
impl fmt::Show for Version {
@@ -221,8 +220,8 @@ fn parse_iter<T: Iterator<char>>(rdr: &mut T) -> Option<Version> {
221220
None => return None
222221
};
223222

224-
let mut pre = ~[];
225-
let mut build = ~[];
223+
let mut pre = vec!();
224+
let mut build = vec!();
226225

227226
let mut ch = ch;
228227
if ch == Some('-') {
@@ -295,66 +294,66 @@ fn test_parse() {
295294
major: 1u,
296295
minor: 2u,
297296
patch: 3u,
298-
pre: ~[],
299-
build: ~[],
297+
pre: vec!(),
298+
build: vec!(),
300299
}));
301300
assert!(parse(" 1.2.3 ") == Some(Version {
302301
major: 1u,
303302
minor: 2u,
304303
patch: 3u,
305-
pre: ~[],
306-
build: ~[],
304+
pre: vec!(),
305+
build: vec!(),
307306
}));
308307
assert!(parse("1.2.3-alpha1") == Some(Version {
309308
major: 1u,
310309
minor: 2u,
311310
patch: 3u,
312-
pre: ~[AlphaNumeric(~"alpha1")],
313-
build: ~[]
311+
pre: vec!(AlphaNumeric(~"alpha1")),
312+
build: vec!(),
314313
}));
315314
assert!(parse(" 1.2.3-alpha1 ") == Some(Version {
316315
major: 1u,
317316
minor: 2u,
318317
patch: 3u,
319-
pre: ~[AlphaNumeric(~"alpha1")],
320-
build: ~[]
318+
pre: vec!(AlphaNumeric(~"alpha1")),
319+
build: vec!()
321320
}));
322321
assert!(parse("1.2.3+build5") == Some(Version {
323322
major: 1u,
324323
minor: 2u,
325324
patch: 3u,
326-
pre: ~[],
327-
build: ~[AlphaNumeric(~"build5")]
325+
pre: vec!(),
326+
build: vec!(AlphaNumeric(~"build5"))
328327
}));
329328
assert!(parse(" 1.2.3+build5 ") == Some(Version {
330329
major: 1u,
331330
minor: 2u,
332331
patch: 3u,
333-
pre: ~[],
334-
build: ~[AlphaNumeric(~"build5")]
332+
pre: vec!(),
333+
build: vec!(AlphaNumeric(~"build5"))
335334
}));
336335
assert!(parse("1.2.3-alpha1+build5") == Some(Version {
337336
major: 1u,
338337
minor: 2u,
339338
patch: 3u,
340-
pre: ~[AlphaNumeric(~"alpha1")],
341-
build: ~[AlphaNumeric(~"build5")]
339+
pre: vec!(AlphaNumeric(~"alpha1")),
340+
build: vec!(AlphaNumeric(~"build5"))
342341
}));
343342
assert!(parse(" 1.2.3-alpha1+build5 ") == Some(Version {
344343
major: 1u,
345344
minor: 2u,
346345
patch: 3u,
347-
pre: ~[AlphaNumeric(~"alpha1")],
348-
build: ~[AlphaNumeric(~"build5")]
346+
pre: vec!(AlphaNumeric(~"alpha1")),
347+
build: vec!(AlphaNumeric(~"build5"))
349348
}));
350349
assert!(parse("1.2.3-1.alpha1.9+build5.7.3aedf ") == Some(Version {
351350
major: 1u,
352351
minor: 2u,
353352
patch: 3u,
354-
pre: ~[Numeric(1),AlphaNumeric(~"alpha1"),Numeric(9)],
355-
build: ~[AlphaNumeric(~"build5"),
353+
pre: vec!(Numeric(1),AlphaNumeric(~"alpha1"),Numeric(9)),
354+
build: vec!(AlphaNumeric(~"build5"),
356355
Numeric(7),
357-
AlphaNumeric(~"3aedf")]
356+
AlphaNumeric(~"3aedf"))
358357
}));
359358
360359
}

src/liburl/lib.rs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use std::hash::Hash;
2828
use std::io::BufReader;
2929
use std::from_str::FromStr;
3030
use std::uint;
31+
use std::vec_ng::Vec;
3132

3233
use 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://username@example.com: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 {
7273
pub 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

9495
impl 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

432433
fn 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)]
958959
mod 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%20uments?ba%25d%20=%23%26%2B";
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+%3D+34");
12741275
}
@@ -1280,7 +1281,7 @@ mod tests {
12801281
let s = "a=1&foo+bar=abc&foo+bar=12+%3D+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

Comments
 (0)