提交 5a93b4f1 编写于 作者: P Patrick Walton

libsemver: Remove all uses of `~str` from `libsemver`

上级 30dbcf5f
......@@ -50,7 +50,7 @@
#[allow(missing_doc)]
pub enum Identifier {
Numeric(uint),
AlphaNumeric(~str)
AlphaNumeric(StrBuf)
}
impl cmp::Ord for Identifier {
......@@ -158,7 +158,7 @@ fn lt(&self, other: &Version) -> 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 ch = rdr.next();
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>)> {
let (s, ch) = take_nonempty_prefix(rdr, char::is_digit);
match from_str::<uint>(s) {
match from_str::<uint>(s.as_slice()) {
None => None,
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>)> {
let (s,ch) = take_nonempty_prefix(rdr, char::is_alphanumeric);
if s.chars().all(char::is_digit) {
match from_str::<uint>(s) {
if s.as_slice().chars().all(char::is_digit) {
match from_str::<uint>(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]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册