diff options
| author | Simon Sapin <simon.sapin@exyr.org> | 2013-12-23 17:45:01 +0100 |
|---|---|---|
| committer | Simon Sapin <simon.sapin@exyr.org> | 2014-01-21 15:48:48 -0800 |
| commit | 05ae134acebee3f35af4880de113a7ae7ce20002 (patch) | |
| tree | 096daf1c7c42bd04ac3d1f11f710fd9786d9937a /src/libstd/str.rs | |
| parent | b8c41492939c77b7139e46ee67375b47041f6692 (diff) | |
| download | rust-05ae134acebee3f35af4880de113a7ae7ce20002.tar.gz rust-05ae134acebee3f35af4880de113a7ae7ce20002.zip | |
[std::str] Rename from_utf8_owned_opt() to from_utf8_owned(), drop the old from_utf8_owned() behavior
Diffstat (limited to 'src/libstd/str.rs')
| -rw-r--r-- | src/libstd/str.rs | 34 |
1 files changed, 4 insertions, 30 deletions
diff --git a/src/libstd/str.rs b/src/libstd/str.rs index c266ddfea4b..6d52e94064c 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -129,26 +129,9 @@ condition! { Section: Creating a string */ -/// Consumes a vector of bytes to create a new utf-8 string -/// -/// # Failure -/// -/// Raises the `not_utf8` condition if invalid UTF-8 -pub fn from_utf8_owned(vv: ~[u8]) -> ~str { - use str::not_utf8::cond; - - if !is_utf8(vv) { - let first_bad_byte = *vv.iter().find(|&b| !is_utf8([*b])).unwrap(); - cond.raise(format!("from_utf8: input is not UTF-8; first bad byte is {}", - first_bad_byte)) - } else { - unsafe { raw::from_utf8_owned(vv) } - } -} - /// Consumes a vector of bytes to create a new utf-8 string. /// Returns None if the vector contains invalid UTF-8. -pub fn from_utf8_owned_opt(vv: ~[u8]) -> Option<~str> { +pub fn from_utf8_owned(vv: ~[u8]) -> Option<~str> { if is_utf8(vv) { Some(unsafe { raw::from_utf8_owned(vv) }) } else { @@ -3964,22 +3947,13 @@ mod tests { #[test] fn test_str_from_utf8_owned() { let xs = bytes!("hello").to_owned(); - assert_eq!(from_utf8_owned(xs), ~"hello"); - - let xs = bytes!("ศไทย中华Việt Nam").to_owned(); - assert_eq!(from_utf8_owned(xs), ~"ศไทย中华Việt Nam"); - } - - #[test] - fn test_str_from_utf8_owned_opt() { - let xs = bytes!("hello").to_owned(); - assert_eq!(from_utf8_owned_opt(xs), Some(~"hello")); + assert_eq!(from_utf8_owned(xs), Some(~"hello")); let xs = bytes!("ศไทย中华Việt Nam").to_owned(); - assert_eq!(from_utf8_owned_opt(xs), Some(~"ศไทย中华Việt Nam")); + assert_eq!(from_utf8_owned(xs), Some(~"ศไทย中华Việt Nam")); let xs = bytes!("hello", 0xff).to_owned(); - assert_eq!(from_utf8_owned_opt(xs), None); + assert_eq!(from_utf8_owned(xs), None); } #[test] |
