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