Skip to content

Commit 8181991

Browse files
committed
---
yaml --- r: 151663 b: refs/heads/try2 c: 27977e4 h: refs/heads/master i: 151661: b9ee026 151659: 8211f4f 151655: bdace6b 151647: e413a3e v: v3
1 parent 4625013 commit 8181991

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 504335ae5aeb2f38b4b8281f313eceff066c1fb2
8+
refs/heads/try2: 27977e41fc28c45af9bd23cd7eefb9dec6e7eab0
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libuuid/lib.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -322,20 +322,20 @@ impl Uuid {
322322
/// Returns the UUID as a string of 16 hexadecimal digits
323323
///
324324
/// Example: `936DA01F9ABD4d9d80C702AF85C822A8`
325-
pub fn to_simple_str(&self) -> ~str {
325+
pub fn to_simple_str(&self) -> StrBuf {
326326
let mut s: Vec<u8> = Vec::from_elem(32, 0u8);
327327
for i in range(0u, 16u) {
328328
let digit = format!("{:02x}", self.bytes[i] as uint);
329329
*s.get_mut(i*2+0) = digit[0];
330330
*s.get_mut(i*2+1) = digit[1];
331331
}
332-
str::from_utf8(s.as_slice()).unwrap().to_str()
332+
str::from_utf8(s.as_slice()).unwrap().to_strbuf()
333333
}
334334

335335
/// Returns a string of hexadecimal digits, separated into groups with a hyphen.
336336
///
337337
/// Example: `550e8400-e29b-41d4-a716-446655440000`
338-
pub fn to_hyphenated_str(&self) -> ~str {
338+
pub fn to_hyphenated_str(&self) -> StrBuf {
339339
use std::mem::{to_be16, to_be32};
340340
// Convert to field-based struct as it matches groups in output.
341341
// Ensure fields are in network byte order, as per RFC.
@@ -346,8 +346,8 @@ impl Uuid {
346346
uf.data1 = to_be32(uf.data1);
347347
uf.data2 = to_be16(uf.data2);
348348
uf.data3 = to_be16(uf.data3);
349-
let s = format!("{:08x}-{:04x}-{:04x}-{:02x}{:02x}-\
350-
{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
349+
let s = format_strbuf!("{:08x}-{:04x}-{:04x}-{:02x}{:02x}-\
350+
{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
351351
uf.data1,
352352
uf.data2, uf.data3,
353353
uf.data4[0], uf.data4[1],
@@ -361,8 +361,8 @@ impl Uuid {
361361
/// This is the same as the hyphenated format, but with the "urn:uuid:" prefix.
362362
///
363363
/// Example: `urn:uuid:F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4`
364-
pub fn to_urn_str(&self) -> ~str {
365-
"urn:uuid:" + self.to_hyphenated_str()
364+
pub fn to_urn_str(&self) -> StrBuf {
365+
format_strbuf!("urn:uuid:{}", self.to_hyphenated_str())
366366
}
367367

368368
/// Parses a UUID from a string of hexadecimal digits with optional hyphens
@@ -493,7 +493,7 @@ impl TotalEq for Uuid {}
493493
impl<T: Encoder<E>, E> Encodable<T, E> for Uuid {
494494
/// Encode a UUID as a hypenated string
495495
fn encode(&self, e: &mut T) -> Result<(), E> {
496-
e.emit_str(self.to_hyphenated_str())
496+
e.emit_str(self.to_hyphenated_str().as_slice())
497497
}
498498
}
499499

@@ -647,7 +647,7 @@ mod test {
647647
let s = uuid1.to_simple_str();
648648

649649
assert!(s.len() == 32);
650-
assert!(s.chars().all(|c| c.is_digit_radix(16)));
650+
assert!(s.as_slice().chars().all(|c| c.is_digit_radix(16)));
651651
}
652652

653653
#[test]
@@ -656,7 +656,7 @@ mod test {
656656
let s = uuid1.to_str();
657657

658658
assert!(s.len() == 32);
659-
assert!(s.chars().all(|c| c.is_digit_radix(16)));
659+
assert!(s.as_slice().chars().all(|c| c.is_digit_radix(16)));
660660
}
661661

662662
#[test]
@@ -665,18 +665,20 @@ mod test {
665665
let s = uuid1.to_hyphenated_str();
666666

667667
assert!(s.len() == 36);
668-
assert!(s.chars().all(|c| c.is_digit_radix(16) || c == '-'));
668+
assert!(s.as_slice().chars().all(|c| c.is_digit_radix(16) || c == '-'));
669669
}
670670

671671
#[test]
672672
fn test_to_urn_str() {
673673
let uuid1 = Uuid::new_v4();
674674
let ss = uuid1.to_urn_str();
675-
let s = ss.slice(9, ss.len());
675+
let s = ss.as_slice().slice(9, ss.len());
676676

677-
assert!(ss.starts_with("urn:uuid:"));
677+
assert!(ss.as_slice().starts_with("urn:uuid:"));
678678
assert!(s.len() == 36);
679-
assert!(s.chars().all(|c| c.is_digit_radix(16) || c == '-'));
679+
assert!(s.as_slice()
680+
.chars()
681+
.all(|c| c.is_digit_radix(16) || c == '-'));
680682
}
681683

682684
#[test]
@@ -686,7 +688,8 @@ mod test {
686688
let hs = uuid1.to_hyphenated_str();
687689
let ss = uuid1.to_str();
688690

689-
let hsn = str::from_chars(hs.chars()
691+
let hsn = str::from_chars(hs.as_slice()
692+
.chars()
690693
.filter(|&c| c != '-')
691694
.collect::<Vec<char>>()
692695
.as_slice());
@@ -699,7 +702,7 @@ mod test {
699702
let uuid = Uuid::new_v4();
700703

701704
let hs = uuid.to_hyphenated_str();
702-
let uuid_hs = Uuid::parse_string(hs).unwrap();
705+
let uuid_hs = Uuid::parse_string(hs.as_slice()).unwrap();
703706
assert!(uuid_hs == uuid);
704707

705708
let ss = uuid.to_str();
@@ -727,7 +730,7 @@ mod test {
727730

728731
let u = Uuid::from_fields(d1, d2, d3, d4.as_slice());
729732

730-
let expected = "a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8".to_owned();
733+
let expected = "a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8".to_strbuf();
731734
let result = u.to_simple_str();
732735
assert!(result == expected);
733736
}
@@ -738,7 +741,7 @@ mod test {
738741
0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8 );
739742

740743
let u = Uuid::from_bytes(b.as_slice()).unwrap();
741-
let expected = "a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8".to_owned();
744+
let expected = "a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8".to_strbuf();
742745

743746
assert!(u.to_simple_str() == expected);
744747
}

0 commit comments

Comments
 (0)