libsemver: Remove all uses of ~str from libsemver

This commit is contained in:
Patrick Walton 2014-05-12 21:39:26 -07:00
parent 30dbcf5f88
commit 5a93b4f192

View File

@ -50,7 +50,7 @@ use std::strbuf::StrBuf;
#[allow(missing_doc)] #[allow(missing_doc)]
pub enum Identifier { pub enum Identifier {
Numeric(uint), Numeric(uint),
AlphaNumeric(~str) AlphaNumeric(StrBuf)
} }
impl cmp::Ord for Identifier { impl cmp::Ord for Identifier {
@ -158,7 +158,7 @@ impl cmp::Ord for Version {
} }
fn take_nonempty_prefix<T:Iterator<char>>(rdr: &mut T, pred: |char| -> bool) fn take_nonempty_prefix<T:Iterator<char>>(rdr: &mut T, pred: |char| -> bool)
-> (~str, Option<char>) { -> (StrBuf, Option<char>) {
let mut buf = StrBuf::new(); let mut buf = StrBuf::new();
let mut ch = rdr.next(); let mut ch = rdr.next();
loop { loop {
@ -171,12 +171,12 @@ fn take_nonempty_prefix<T:Iterator<char>>(rdr: &mut T, pred: |char| -> bool)
} }
} }
} }
(buf.into_owned(), ch) (buf, ch)
} }
fn take_num<T: Iterator<char>>(rdr: &mut T) -> Option<(uint, Option<char>)> { fn take_num<T: Iterator<char>>(rdr: &mut T) -> Option<(uint, Option<char>)> {
let (s, ch) = take_nonempty_prefix(rdr, char::is_digit); let (s, ch) = take_nonempty_prefix(rdr, char::is_digit);
match from_str::<uint>(s) { match from_str::<uint>(s.as_slice()) {
None => None, None => None,
Some(i) => Some((i, ch)) Some(i) => Some((i, ch))
} }
@ -184,8 +184,8 @@ fn take_num<T: Iterator<char>>(rdr: &mut T) -> Option<(uint, Option<char>)> {
fn take_ident<T: Iterator<char>>(rdr: &mut T) -> Option<(Identifier, Option<char>)> { fn take_ident<T: Iterator<char>>(rdr: &mut T) -> Option<(Identifier, Option<char>)> {
let (s,ch) = take_nonempty_prefix(rdr, char::is_alphanumeric); let (s,ch) = take_nonempty_prefix(rdr, char::is_alphanumeric);
if s.chars().all(char::is_digit) { if s.as_slice().chars().all(char::is_digit) {
match from_str::<uint>(s) { match from_str::<uint>(s.as_slice()) {
None => None, None => None,
Some(i) => Some((Numeric(i), ch)) Some(i) => Some((Numeric(i), ch))
} }
@ -308,14 +308,14 @@ fn test_parse() {
major: 1u, major: 1u,
minor: 2u, minor: 2u,
patch: 3u, patch: 3u,
pre: vec!(AlphaNumeric("alpha1".to_owned())), pre: vec!(AlphaNumeric("alpha1".to_strbuf())),
build: vec!(), build: vec!(),
})); }));
assert!(parse(" 1.2.3-alpha1 ") == Some(Version { assert!(parse(" 1.2.3-alpha1 ") == Some(Version {
major: 1u, major: 1u,
minor: 2u, minor: 2u,
patch: 3u, patch: 3u,
pre: vec!(AlphaNumeric("alpha1".to_owned())), pre: vec!(AlphaNumeric("alpha1".to_strbuf())),
build: vec!() build: vec!()
})); }));
assert!(parse("1.2.3+build5") == Some(Version { assert!(parse("1.2.3+build5") == Some(Version {
@ -323,37 +323,37 @@ fn test_parse() {
minor: 2u, minor: 2u,
patch: 3u, patch: 3u,
pre: vec!(), pre: vec!(),
build: vec!(AlphaNumeric("build5".to_owned())) build: vec!(AlphaNumeric("build5".to_strbuf()))
})); }));
assert!(parse(" 1.2.3+build5 ") == Some(Version { assert!(parse(" 1.2.3+build5 ") == Some(Version {
major: 1u, major: 1u,
minor: 2u, minor: 2u,
patch: 3u, patch: 3u,
pre: vec!(), pre: vec!(),
build: vec!(AlphaNumeric("build5".to_owned())) build: vec!(AlphaNumeric("build5".to_strbuf()))
})); }));
assert!(parse("1.2.3-alpha1+build5") == Some(Version { assert!(parse("1.2.3-alpha1+build5") == Some(Version {
major: 1u, major: 1u,
minor: 2u, minor: 2u,
patch: 3u, patch: 3u,
pre: vec!(AlphaNumeric("alpha1".to_owned())), pre: vec!(AlphaNumeric("alpha1".to_strbuf())),
build: vec!(AlphaNumeric("build5".to_owned())) build: vec!(AlphaNumeric("build5".to_strbuf()))
})); }));
assert!(parse(" 1.2.3-alpha1+build5 ") == Some(Version { assert!(parse(" 1.2.3-alpha1+build5 ") == Some(Version {
major: 1u, major: 1u,
minor: 2u, minor: 2u,
patch: 3u, patch: 3u,
pre: vec!(AlphaNumeric("alpha1".to_owned())), pre: vec!(AlphaNumeric("alpha1".to_strbuf())),
build: vec!(AlphaNumeric("build5".to_owned())) build: vec!(AlphaNumeric("build5".to_strbuf()))
})); }));
assert!(parse("1.2.3-1.alpha1.9+build5.7.3aedf ") == Some(Version { assert!(parse("1.2.3-1.alpha1.9+build5.7.3aedf ") == Some(Version {
major: 1u, major: 1u,
minor: 2u, minor: 2u,
patch: 3u, patch: 3u,
pre: vec!(Numeric(1),AlphaNumeric("alpha1".to_owned()),Numeric(9)), pre: vec!(Numeric(1),AlphaNumeric("alpha1".to_strbuf()),Numeric(9)),
build: vec!(AlphaNumeric("build5".to_owned()), build: vec!(AlphaNumeric("build5".to_strbuf()),
Numeric(7), Numeric(7),
AlphaNumeric("3aedf".to_owned())) AlphaNumeric("3aedf".to_strbuf()))
})); }));
} }
@ -377,10 +377,14 @@ fn test_ne() {
#[test] #[test]
fn test_show() { fn test_show() {
assert_eq!(format!("{}", parse("1.2.3").unwrap()), "1.2.3".to_owned()); assert_eq!(format_strbuf!("{}", parse("1.2.3").unwrap()),
assert_eq!(format!("{}", parse("1.2.3-alpha1").unwrap()), "1.2.3-alpha1".to_owned()); "1.2.3".to_strbuf());
assert_eq!(format!("{}", parse("1.2.3+build.42").unwrap()), "1.2.3+build.42".to_owned()); assert_eq!(format_strbuf!("{}", parse("1.2.3-alpha1").unwrap()),
assert_eq!(format!("{}", parse("1.2.3-alpha1+42").unwrap()), "1.2.3-alpha1+42".to_owned()); "1.2.3-alpha1".to_strbuf());
assert_eq!(format_strbuf!("{}", parse("1.2.3+build.42").unwrap()),
"1.2.3+build.42".to_strbuf());
assert_eq!(format_strbuf!("{}", parse("1.2.3-alpha1+42").unwrap()),
"1.2.3-alpha1+42".to_strbuf());
} }
#[test] #[test]