Skip to content

Commit d583736

Browse files
committed
---
yaml --- r: 114137 b: refs/heads/master c: 5a93b4f h: refs/heads/master i: 114135: 4cfe675 v: v3
1 parent 064d348 commit d583736

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 30dbcf5f88b20db3ea1c70bb50cb37fa9364f1a9
2+
refs/heads/master: 5a93b4f192bfc8cba24b9c51e8a70a9b51e96b05
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ec0258a381b88b5574e3f8ce72ae553ac3a574b7
55
refs/heads/try: 7c6c492fb2af9a85f21ff952942df3523b22fd17

trunk/src/libsemver/lib.rs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use std::strbuf::StrBuf;
5050
#[allow(missing_doc)]
5151
pub enum Identifier {
5252
Numeric(uint),
53-
AlphaNumeric(~str)
53+
AlphaNumeric(StrBuf)
5454
}
5555

5656
impl cmp::Ord for Identifier {
@@ -158,7 +158,7 @@ impl cmp::Ord for Version {
158158
}
159159

160160
fn take_nonempty_prefix<T:Iterator<char>>(rdr: &mut T, pred: |char| -> bool)
161-
-> (~str, Option<char>) {
161+
-> (StrBuf, Option<char>) {
162162
let mut buf = StrBuf::new();
163163
let mut ch = rdr.next();
164164
loop {
@@ -171,21 +171,21 @@ fn take_nonempty_prefix<T:Iterator<char>>(rdr: &mut T, pred: |char| -> bool)
171171
}
172172
}
173173
}
174-
(buf.into_owned(), ch)
174+
(buf, ch)
175175
}
176176

177177
fn take_num<T: Iterator<char>>(rdr: &mut T) -> Option<(uint, Option<char>)> {
178178
let (s, ch) = take_nonempty_prefix(rdr, char::is_digit);
179-
match from_str::<uint>(s) {
179+
match from_str::<uint>(s.as_slice()) {
180180
None => None,
181181
Some(i) => Some((i, ch))
182182
}
183183
}
184184

185185
fn take_ident<T: Iterator<char>>(rdr: &mut T) -> Option<(Identifier, Option<char>)> {
186186
let (s,ch) = take_nonempty_prefix(rdr, char::is_alphanumeric);
187-
if s.chars().all(char::is_digit) {
188-
match from_str::<uint>(s) {
187+
if s.as_slice().chars().all(char::is_digit) {
188+
match from_str::<uint>(s.as_slice()) {
189189
None => None,
190190
Some(i) => Some((Numeric(i), ch))
191191
}
@@ -308,52 +308,52 @@ fn test_parse() {
308308
major: 1u,
309309
minor: 2u,
310310
patch: 3u,
311-
pre: vec!(AlphaNumeric("alpha1".to_owned())),
311+
pre: vec!(AlphaNumeric("alpha1".to_strbuf())),
312312
build: vec!(),
313313
}));
314314
assert!(parse(" 1.2.3-alpha1 ") == Some(Version {
315315
major: 1u,
316316
minor: 2u,
317317
patch: 3u,
318-
pre: vec!(AlphaNumeric("alpha1".to_owned())),
318+
pre: vec!(AlphaNumeric("alpha1".to_strbuf())),
319319
build: vec!()
320320
}));
321321
assert!(parse("1.2.3+build5") == Some(Version {
322322
major: 1u,
323323
minor: 2u,
324324
patch: 3u,
325325
pre: vec!(),
326-
build: vec!(AlphaNumeric("build5".to_owned()))
326+
build: vec!(AlphaNumeric("build5".to_strbuf()))
327327
}));
328328
assert!(parse(" 1.2.3+build5 ") == Some(Version {
329329
major: 1u,
330330
minor: 2u,
331331
patch: 3u,
332332
pre: vec!(),
333-
build: vec!(AlphaNumeric("build5".to_owned()))
333+
build: vec!(AlphaNumeric("build5".to_strbuf()))
334334
}));
335335
assert!(parse("1.2.3-alpha1+build5") == Some(Version {
336336
major: 1u,
337337
minor: 2u,
338338
patch: 3u,
339-
pre: vec!(AlphaNumeric("alpha1".to_owned())),
340-
build: vec!(AlphaNumeric("build5".to_owned()))
339+
pre: vec!(AlphaNumeric("alpha1".to_strbuf())),
340+
build: vec!(AlphaNumeric("build5".to_strbuf()))
341341
}));
342342
assert!(parse(" 1.2.3-alpha1+build5 ") == Some(Version {
343343
major: 1u,
344344
minor: 2u,
345345
patch: 3u,
346-
pre: vec!(AlphaNumeric("alpha1".to_owned())),
347-
build: vec!(AlphaNumeric("build5".to_owned()))
346+
pre: vec!(AlphaNumeric("alpha1".to_strbuf())),
347+
build: vec!(AlphaNumeric("build5".to_strbuf()))
348348
}));
349349
assert!(parse("1.2.3-1.alpha1.9+build5.7.3aedf ") == Some(Version {
350350
major: 1u,
351351
minor: 2u,
352352
patch: 3u,
353-
pre: vec!(Numeric(1),AlphaNumeric("alpha1".to_owned()),Numeric(9)),
354-
build: vec!(AlphaNumeric("build5".to_owned()),
353+
pre: vec!(Numeric(1),AlphaNumeric("alpha1".to_strbuf()),Numeric(9)),
354+
build: vec!(AlphaNumeric("build5".to_strbuf()),
355355
Numeric(7),
356-
AlphaNumeric("3aedf".to_owned()))
356+
AlphaNumeric("3aedf".to_strbuf()))
357357
}));
358358

359359
}
@@ -377,10 +377,14 @@ fn test_ne() {
377377

378378
#[test]
379379
fn test_show() {
380-
assert_eq!(format!("{}", parse("1.2.3").unwrap()), "1.2.3".to_owned());
381-
assert_eq!(format!("{}", parse("1.2.3-alpha1").unwrap()), "1.2.3-alpha1".to_owned());
382-
assert_eq!(format!("{}", parse("1.2.3+build.42").unwrap()), "1.2.3+build.42".to_owned());
383-
assert_eq!(format!("{}", parse("1.2.3-alpha1+42").unwrap()), "1.2.3-alpha1+42".to_owned());
380+
assert_eq!(format_strbuf!("{}", parse("1.2.3").unwrap()),
381+
"1.2.3".to_strbuf());
382+
assert_eq!(format_strbuf!("{}", parse("1.2.3-alpha1").unwrap()),
383+
"1.2.3-alpha1".to_strbuf());
384+
assert_eq!(format_strbuf!("{}", parse("1.2.3+build.42").unwrap()),
385+
"1.2.3+build.42".to_strbuf());
386+
assert_eq!(format_strbuf!("{}", parse("1.2.3-alpha1+42").unwrap()),
387+
"1.2.3-alpha1+42".to_strbuf());
384388
}
385389

386390
#[test]

0 commit comments

Comments
 (0)