Skip to content

De-~[] libsemver and liburl #12923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 24 additions & 25 deletions src/libsemver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@
#[crate_type = "dylib"];
#[license = "MIT/ASL2"];

#[allow(deprecated_owned_vector)];

use std::char;
use std::cmp;
use std::fmt;
use std::fmt::Show;
use std::option::{Option, Some, None};
use std::vec_ng::Vec;

/// An identifier in the pre-release or build metadata. If the identifier can
/// be parsed as a decimal value, it will be represented with `Numeric`.
Expand Down Expand Up @@ -85,9 +84,9 @@ pub struct Version {
/// fixes are made.
patch: uint,
/// The pre-release version identifier, if one exists.
pre: ~[Identifier],
pre: Vec<Identifier>,
/// The build metadata, ignored when determining version precedence.
build: ~[Identifier],
build: Vec<Identifier>,
}

impl fmt::Show for Version {
Expand Down Expand Up @@ -218,8 +217,8 @@ fn parse_iter<T: Iterator<char>>(rdr: &mut T) -> Option<Version> {
None => return None
};

let mut pre = ~[];
let mut build = ~[];
let mut pre = vec!();
let mut build = vec!();

let mut ch = ch;
if ch == Some('-') {
Expand Down Expand Up @@ -292,66 +291,66 @@ fn test_parse() {
major: 1u,
minor: 2u,
patch: 3u,
pre: ~[],
build: ~[],
pre: vec!(),
build: vec!(),
}));
assert!(parse(" 1.2.3 ") == Some(Version {
major: 1u,
minor: 2u,
patch: 3u,
pre: ~[],
build: ~[],
pre: vec!(),
build: vec!(),
}));
assert!(parse("1.2.3-alpha1") == Some(Version {
major: 1u,
minor: 2u,
patch: 3u,
pre: ~[AlphaNumeric(~"alpha1")],
build: ~[]
pre: vec!(AlphaNumeric(~"alpha1")),
build: vec!(),
}));
assert!(parse(" 1.2.3-alpha1 ") == Some(Version {
major: 1u,
minor: 2u,
patch: 3u,
pre: ~[AlphaNumeric(~"alpha1")],
build: ~[]
pre: vec!(AlphaNumeric(~"alpha1")),
build: vec!()
}));
assert!(parse("1.2.3+build5") == Some(Version {
major: 1u,
minor: 2u,
patch: 3u,
pre: ~[],
build: ~[AlphaNumeric(~"build5")]
pre: vec!(),
build: vec!(AlphaNumeric(~"build5"))
}));
assert!(parse(" 1.2.3+build5 ") == Some(Version {
major: 1u,
minor: 2u,
patch: 3u,
pre: ~[],
build: ~[AlphaNumeric(~"build5")]
pre: vec!(),
build: vec!(AlphaNumeric(~"build5"))
}));
assert!(parse("1.2.3-alpha1+build5") == Some(Version {
major: 1u,
minor: 2u,
patch: 3u,
pre: ~[AlphaNumeric(~"alpha1")],
build: ~[AlphaNumeric(~"build5")]
pre: vec!(AlphaNumeric(~"alpha1")),
build: vec!(AlphaNumeric(~"build5"))
}));
assert!(parse(" 1.2.3-alpha1+build5 ") == Some(Version {
major: 1u,
minor: 2u,
patch: 3u,
pre: ~[AlphaNumeric(~"alpha1")],
build: ~[AlphaNumeric(~"build5")]
pre: vec!(AlphaNumeric(~"alpha1")),
build: vec!(AlphaNumeric(~"build5"))
}));
assert!(parse("1.2.3-1.alpha1.9+build5.7.3aedf ") == Some(Version {
major: 1u,
minor: 2u,
patch: 3u,
pre: ~[Numeric(1),AlphaNumeric(~"alpha1"),Numeric(9)],
build: ~[AlphaNumeric(~"build5"),
pre: vec!(Numeric(1),AlphaNumeric(~"alpha1"),Numeric(9)),
build: vec!(AlphaNumeric(~"build5"),
Numeric(7),
AlphaNumeric(~"3aedf")]
AlphaNumeric(~"3aedf"))
}));

}
Expand Down
47 changes: 24 additions & 23 deletions src/liburl/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use std::hash::Hash;
use std::io::BufReader;
use std::from_str::FromStr;
use std::uint;
use std::vec_ng::Vec;

use collections::HashMap;

Expand All @@ -42,7 +43,7 @@ use collections::HashMap;
/// host: ~"example.com",
/// port: Some(~"8080"),
/// path: ~"/foo/bar",
/// query: ~[(~"baz", ~"qux")],
/// query: vec!((~"baz", ~"qux")),
/// fragment: Some(~"quz") };
/// // https://[email protected]:8080/foo/bar?baz=qux#quz
/// ```
Expand All @@ -58,7 +59,7 @@ pub struct Url {
port: Option<~str>,
/// The path component of a URL, for example `/foo/bar`.
path: ~str,
/// The query component of a URL. `~[(~"baz", ~"qux")]` represents the
/// The query component of a URL. `vec!((~"baz", ~"qux"))` represents the
/// fragment `baz=qux` in the above example.
query: Query,
/// The fragment component, such as `quz`. Doesn't include the leading `#` character.
Expand All @@ -69,7 +70,7 @@ pub struct Url {
pub struct Path {
/// The path component of a URL, for example `/foo/bar`.
path: ~str,
/// The query component of a URL. `~[(~"baz", ~"qux")]` represents the
/// The query component of a URL. `vec!((~"baz", ~"qux"))` represents the
/// fragment `baz=qux` in the above example.
query: Query,
/// The fragment component, such as `quz`. Doesn't include the leading `#` character.
Expand All @@ -86,7 +87,7 @@ pub struct UserInfo {
}

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

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

Expand All @@ -324,7 +325,7 @@ pub fn encode_form_urlencoded(m: &HashMap<~str, ~[~str]>) -> ~str {
* Decode a string encoded with the 'application/x-www-form-urlencoded' media
* type into a hashmap.
*/
pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, ~[~str]> {
pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, Vec<~str>> {
let mut rdr = BufReader::new(s);
let mut m = HashMap::new();
let mut key = ~"";
Expand All @@ -342,7 +343,7 @@ pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, ~[~str]> {
if key != ~"" && value != ~"" {
let mut values = match m.pop(&key) {
Some(values) => values,
None => ~[],
None => vec!(),
};

values.push(value);
Expand Down Expand Up @@ -380,7 +381,7 @@ pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, ~[~str]> {
if key != ~"" && value != ~"" {
let mut values = match m.pop(&key) {
Some(values) => values,
None => ~[],
None => vec!(),
};

values.push(value);
Expand Down Expand Up @@ -427,7 +428,7 @@ impl fmt::Show for UserInfo {
}

fn query_from_str(rawquery: &str) -> Query {
let mut query: Query = ~[];
let mut query: Query = vec!();
if !rawquery.is_empty() {
for p in rawquery.split('&') {
let (k, v) = split_char_first(p, '=');
Expand All @@ -443,7 +444,7 @@ fn query_from_str(rawquery: &str) -> Query {
* # Example
*
* ```rust
* let query = ~[(~"title", ~"The Village"), (~"north", ~"52.91"), (~"west", ~"4.10")];
* let query = vec!((~"title", ~"The Village"), (~"north", ~"52.91"), (~"west", ~"4.10"));
* println!("{}", url::query_to_str(&query)); // title=The%20Village&north=52.91&west=4.10
* ```
*/
Expand Down Expand Up @@ -709,9 +710,9 @@ fn get_query_fragment(rawurl: &str) ->
let f = decode_component(rawurl.slice(
1,
rawurl.len()));
return Ok((~[], Some(f)));
return Ok((vec!(), Some(f)));
} else {
return Ok((~[], None));
return Ok((vec!(), None));
}
}
let (q, r) = split_char_first(rawurl.slice(1, rawurl.len()), '#');
Expand Down Expand Up @@ -953,7 +954,7 @@ fn test_get_path() {

#[cfg(test)]
mod tests {
use {encode_form_urlencoded, decode_form_urlencoded, decode_component,
use {encode_form_urlencoded, decode_form_urlencoded,
decode, encode, from_str, encode_component, decode_component,
path_from_str, UserInfo, get_scheme};

Expand All @@ -970,7 +971,7 @@ mod tests {
assert_eq!(&u.host, &~"rust-lang.org");
assert_eq!(&u.port, &Some(~"8080"));
assert_eq!(&u.path, &~"/doc/~u");
assert_eq!(&u.query, &~[(~"s", ~"v")]);
assert_eq!(&u.query, &vec!((~"s", ~"v")));
assert_eq!(&u.fragment, &Some(~"something"));
}

Expand All @@ -981,7 +982,7 @@ mod tests {
let up = path_from_str(path);
let u = up.unwrap();
assert_eq!(&u.path, &~"/doc/~u");
assert_eq!(&u.query, &~[(~"s", ~"v")]);
assert_eq!(&u.query, &vec!((~"s", ~"v")));
assert_eq!(&u.fragment, &Some(~"something"));
}

Expand Down Expand Up @@ -1121,15 +1122,15 @@ mod tests {
let url = ~"http://rust-lang.org/doc%20uments?ba%25d%20=%23%26%2B";
let u = from_str(url).unwrap();
assert!(u.path == ~"/doc uments");
assert!(u.query == ~[(~"ba%d ", ~"#&+")]);
assert!(u.query == vec!((~"ba%d ", ~"#&+")));
}

#[test]
fn test_path_component_encoding() {
let path = ~"/doc%20uments?ba%25d%20=%23%26%2B";
let p = path_from_str(path).unwrap();
assert!(p.path == ~"/doc uments");
assert!(p.query == ~[(~"ba%d ", ~"#&+")]);
assert!(p.query == vec!((~"ba%d ", ~"#&+")));
}

#[test]
Expand Down Expand Up @@ -1256,16 +1257,16 @@ mod tests {
let mut m = HashMap::new();
assert_eq!(encode_form_urlencoded(&m), ~"");

m.insert(~"", ~[]);
m.insert(~"foo", ~[]);
m.insert(~"", vec!());
m.insert(~"foo", vec!());
assert_eq!(encode_form_urlencoded(&m), ~"");

let mut m = HashMap::new();
m.insert(~"foo", ~[~"bar", ~"123"]);
m.insert(~"foo", vec!(~"bar", ~"123"));
assert_eq!(encode_form_urlencoded(&m), ~"foo=bar&foo=123");

let mut m = HashMap::new();
m.insert(~"foo bar", ~[~"abc", ~"12 = 34"]);
m.insert(~"foo bar", vec!(~"abc", ~"12 = 34"));
assert!(encode_form_urlencoded(&m) ==
~"foo+bar=abc&foo+bar=12+%3D+34");
}
Expand All @@ -1277,7 +1278,7 @@ mod tests {
let s = "a=1&foo+bar=abc&foo+bar=12+%3D+34".as_bytes();
let form = decode_form_urlencoded(s);
assert_eq!(form.len(), 2);
assert_eq!(form.get(&~"a"), &~[~"1"]);
assert_eq!(form.get(&~"foo bar"), &~[~"abc", ~"12 = 34"]);
assert_eq!(form.get(&~"a"), &vec!(~"1"));
assert_eq!(form.get(&~"foo bar"), &vec!(~"abc", ~"12 = 34"));
}
}