diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2013-12-02 00:33:04 +1100 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2013-12-04 22:35:53 +1100 |
| commit | b0426edc0a83699de79ceffcbe603812b9b53374 (patch) | |
| tree | 1aff5ef5a386dbe93febb8eab89033fa83f33a8a /src/libstd/str.rs | |
| parent | 9d64e46013096997627da62ecc65225bc22682e8 (diff) | |
std::str: s/from_utf8_slice/from_utf8/, to make the basic case shorter.
Diffstat (limited to 'src/libstd/str.rs')
| -rw-r--r-- | src/libstd/str.rs | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 2076d433fb6..c1898a9b920 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -159,16 +159,16 @@ pub fn from_utf8_owned_opt(vv: ~[u8]) -> Option<~str> { /// # Failure /// /// Fails if invalid UTF-8 -pub fn from_utf8_slice<'a>(v: &'a [u8]) -> &'a str { - from_utf8_slice_opt(v).expect("from_utf8_slice: not utf-8") +pub fn from_utf8<'a>(v: &'a [u8]) -> &'a str { + from_utf8_opt(v).expect("from_utf8: not utf-8") } /// Converts a vector to a string slice without performing any allocations. /// /// Returns None if the slice is not utf-8. -pub fn from_utf8_slice_opt<'a>(v: &'a [u8]) -> Option<&'a str> { +pub fn from_utf8_opt<'a>(v: &'a [u8]) -> Option<&'a str> { if is_utf8(v) { - Some(unsafe { raw::from_utf8_slice(v) }) + Some(unsafe { raw::from_utf8(v) }) } else { None } } @@ -1029,7 +1029,7 @@ pub mod raw { /// Converts a slice of bytes to a string slice without checking /// that the string contains valid UTF-8. - pub unsafe fn from_utf8_slice<'a>(v: &'a [u8]) -> &'a str { + pub unsafe fn from_utf8<'a>(v: &'a [u8]) -> &'a str { cast::transmute(v) } @@ -3153,7 +3153,7 @@ mod tests { let s1: ~str = ~"All mimsy were the borogoves"; let v: ~[u8] = s1.as_bytes().to_owned(); - let s2: ~str = from_utf8_slice(v).to_owned(); + let s2: ~str = from_utf8(v).to_owned(); let mut i: uint = 0u; let n1: uint = s1.len(); let n2: uint = v.len(); @@ -3676,31 +3676,31 @@ mod tests { } #[test] - fn test_str_from_utf8_slice() { + fn test_str_from_utf8() { let xs = bytes!("hello"); - assert_eq!(from_utf8_slice(xs), "hello"); + assert_eq!(from_utf8(xs), "hello"); let xs = bytes!("ศไทย中华Việt Nam"); - assert_eq!(from_utf8_slice(xs), "ศไทย中华Việt Nam"); + assert_eq!(from_utf8(xs), "ศไทย中华Việt Nam"); } #[test] #[should_fail] - fn test_str_from_utf8_slice_invalid() { + fn test_str_from_utf8_invalid() { let xs = bytes!("hello", 0xff); - let _ = from_utf8_slice(xs); + let _ = from_utf8(xs); } #[test] - fn test_str_from_utf8_slice_opt() { + fn test_str_from_utf8_opt() { let xs = bytes!("hello"); - assert_eq!(from_utf8_slice_opt(xs), Some("hello")); + assert_eq!(from_utf8_opt(xs), Some("hello")); let xs = bytes!("ศไทย中华Việt Nam"); - assert_eq!(from_utf8_slice_opt(xs), Some("ศไทย中华Việt Nam")); + assert_eq!(from_utf8_opt(xs), Some("ศไทย中华Việt Nam")); let xs = bytes!("hello", 0xff); - assert_eq!(from_utf8_slice_opt(xs), None); + assert_eq!(from_utf8_opt(xs), None); } #[test] |
