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 | |
| parent | 9d64e46013096997627da62ecc65225bc22682e8 (diff) | |
| download | rust-b0426edc0a83699de79ceffcbe603812b9b53374.tar.gz rust-b0426edc0a83699de79ceffcbe603812b9b53374.zip | |
std::str: s/from_utf8_slice/from_utf8/, to make the basic case shorter.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/c_str.rs | 2 | ||||
| -rw-r--r-- | src/libstd/fmt/mod.rs | 2 | ||||
| -rw-r--r-- | src/libstd/io/flate.rs | 2 | ||||
| -rw-r--r-- | src/libstd/io/fs.rs | 14 | ||||
| -rw-r--r-- | src/libstd/io/mod.rs | 2 | ||||
| -rw-r--r-- | src/libstd/path/mod.rs | 14 | ||||
| -rw-r--r-- | src/libstd/path/posix.rs | 6 | ||||
| -rw-r--r-- | src/libstd/str.rs | 30 |
8 files changed, 36 insertions, 36 deletions
diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs index 306ee331929..11845c766ed 100644 --- a/src/libstd/c_str.rs +++ b/src/libstd/c_str.rs @@ -167,7 +167,7 @@ impl CString { if self.buf.is_null() { return None; } let buf = self.as_bytes(); let buf = buf.slice_to(buf.len()-1); // chop off the trailing NUL - str::from_utf8_slice_opt(buf) + str::from_utf8_opt(buf) } /// Return a CString iterator. diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index c74a9bc9051..463540b3677 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -802,7 +802,7 @@ impl<'self> Formatter<'self> { fn runplural(&mut self, value: uint, pieces: &[rt::Piece]) { ::uint::to_str_bytes(value, 10, |buf| { - let valuestr = str::from_utf8_slice(buf); + let valuestr = str::from_utf8(buf); for piece in pieces.iter() { self.run(piece, Some(valuestr)); } diff --git a/src/libstd/io/flate.rs b/src/libstd/io/flate.rs index 6548c0e65c9..4a31449e105 100644 --- a/src/libstd/io/flate.rs +++ b/src/libstd/io/flate.rs @@ -117,7 +117,7 @@ mod test { let mut out_bytes = [0, .. 100]; let bytes_read = inflate_reader.read(out_bytes).unwrap(); assert_eq!(bytes_read, in_bytes.len()); - let out_msg = str::from_utf8_slice(out_bytes); + let out_msg = str::from_utf8(out_bytes); assert_eq!(in_msg, out_msg); } } diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index db8de9df24a..f0b51a2c3e0 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -821,7 +821,7 @@ mod test { } } unlink(filename); - let read_str = str::from_utf8_slice(read_mem); + let read_str = str::from_utf8(read_mem); assert_eq!(read_str, message); }) @@ -845,7 +845,7 @@ mod test { tell_pos_post_read = read_stream.tell(); } unlink(filename); - let read_str = str::from_utf8_slice(read_mem); + let read_str = str::from_utf8(read_mem); assert_eq!(read_str, message.slice(4, 8)); assert_eq!(tell_pos_pre_read, set_cursor); assert_eq!(tell_pos_post_read, message.len() as u64); @@ -870,7 +870,7 @@ mod test { read_stream.read(read_mem); } unlink(filename); - let read_str = str::from_utf8_slice(read_mem); + let read_str = str::from_utf8(read_mem); assert!(read_str == final_msg.to_owned()); }) @@ -892,15 +892,15 @@ mod test { read_stream.seek(-4, SeekEnd); read_stream.read(read_mem); - assert_eq!(str::from_utf8_slice(read_mem), chunk_three); + assert_eq!(str::from_utf8(read_mem), chunk_three); read_stream.seek(-9, SeekCur); read_stream.read(read_mem); - assert_eq!(str::from_utf8_slice(read_mem), chunk_two); + assert_eq!(str::from_utf8(read_mem), chunk_two); read_stream.seek(0, SeekSet); read_stream.read(read_mem); - assert_eq!(str::from_utf8_slice(read_mem), chunk_one); + assert_eq!(str::from_utf8(read_mem), chunk_one); } unlink(filename); }) @@ -974,7 +974,7 @@ mod test { { let n = f.filestem_str(); File::open(f).read(mem); - let read_str = str::from_utf8_slice(mem); + let read_str = str::from_utf8(mem); let expected = match n { None|Some("") => fail!("really shouldn't happen.."), Some(n) => prefix+n diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index c00233dda55..208c64f5ef4 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1049,7 +1049,7 @@ pub trait Buffer: Reader { Some(n) if n == width => {} Some(..) | None => return None // read error } - match str::from_utf8_slice_opt(buf.slice_to(width)) { + match str::from_utf8_opt(buf.slice_to(width)) { Some(s) => Some(s.char_at(0)), None => None } diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 8ecfdb3a9e0..79989b838f6 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -176,7 +176,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// If the path is not representable in utf-8, this returns None. #[inline] fn as_str<'a>(&'a self) -> Option<&'a str> { - str::from_utf8_slice_opt(self.as_vec()) + str::from_utf8_opt(self.as_vec()) } /// Returns the path as a byte vector @@ -207,7 +207,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// See `dirname` for details. #[inline] fn dirname_str<'a>(&'a self) -> Option<&'a str> { - str::from_utf8_slice_opt(self.dirname()) + str::from_utf8_opt(self.dirname()) } /// Returns the file component of `self`, as a byte vector. /// If `self` represents the root of the file hierarchy, returns None. @@ -217,7 +217,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// See `filename` for details. #[inline] fn filename_str<'a>(&'a self) -> Option<&'a str> { - self.filename().and_then(str::from_utf8_slice_opt) + self.filename().and_then(str::from_utf8_opt) } /// Returns the stem of the filename of `self`, as a byte vector. /// The stem is the portion of the filename just before the last '.'. @@ -239,7 +239,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// See `filestem` for details. #[inline] fn filestem_str<'a>(&'a self) -> Option<&'a str> { - self.filestem().and_then(str::from_utf8_slice_opt) + self.filestem().and_then(str::from_utf8_opt) } /// Returns the extension of the filename of `self`, as an optional byte vector. /// The extension is the portion of the filename just after the last '.'. @@ -262,7 +262,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// See `extension` for details. #[inline] fn extension_str<'a>(&'a self) -> Option<&'a str> { - self.extension().and_then(str::from_utf8_slice_opt) + self.extension().and_then(str::from_utf8_opt) } /// Replaces the filename portion of the path with the given byte vector or string. @@ -493,12 +493,12 @@ pub trait BytesContainer { /// Raises `str::null_byte` if not utf-8 #[inline] fn container_as_str<'a>(&'a self) -> &'a str { - str::from_utf8_slice(self.container_as_bytes()) + str::from_utf8(self.container_as_bytes()) } /// Returns the receiver interpreted as a utf-8 string, if possible #[inline] fn container_as_str_opt<'a>(&'a self) -> Option<&'a str> { - str::from_utf8_slice_opt(self.container_as_bytes()) + str::from_utf8_opt(self.container_as_bytes()) } /// Returns whether .container_as_str() is guaranteed to not fail // FIXME (#8888): Remove unused arg once ::<for T> works diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index b2bc00dd247..ddf2cce21b0 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -396,13 +396,13 @@ impl Path { /// Returns an iterator that yields each component of the path as Option<&str>. /// See components() for details. pub fn str_components<'a>(&'a self) -> StrComponentIter<'a> { - self.components().map(str::from_utf8_slice_opt) + self.components().map(str::from_utf8_opt) } /// Returns an iterator that yields each component of the path in reverse as Option<&str>. /// See components() for details. pub fn rev_str_components<'a>(&'a self) -> RevStrComponentIter<'a> { - self.rev_components().map(str::from_utf8_slice_opt) + self.rev_components().map(str::from_utf8_opt) } } @@ -684,7 +684,7 @@ mod tests { (s: $path:expr, $op:ident, $exp:expr, opt) => ( { let path = Path::init($path); - let left = path.$op().map(|x| str::from_utf8_slice(x)); + let left = path.$op().map(|x| str::from_utf8(x)); assert_eq!(left, $exp); } ); 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] |
