libsemver: Remove all uses of ~str
from libsemver
This commit is contained in:
parent
30dbcf5f88
commit
5a93b4f192
@ -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<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]
|
||||
|
Loading…
Reference in New Issue
Block a user