diff options
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/option.rs | 6 | ||||
| -rw-r--r-- | src/libcore/result.rs | 2 | ||||
| -rw-r--r-- | src/libcore/str.rs | 36 |
3 files changed, 17 insertions, 27 deletions
diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 8adbba8b94b..d831a57893b 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -718,15 +718,15 @@ impl<T: Default> Option<T> { /// # Example /// /// Convert a string to an integer, turning poorly-formed strings - /// into 0 (the default value for integers). `from_str` converts + /// into 0 (the default value for integers). `parse` converts /// a string to any other type that implements `FromStr`, returning /// `None` on error. /// /// ``` /// let good_year_from_input = "1909"; /// let bad_year_from_input = "190blarg"; - /// let good_year = from_str(good_year_from_input).unwrap_or_default(); - /// let bad_year = from_str(bad_year_from_input).unwrap_or_default(); + /// let good_year = good_year_from_input.parse().unwrap_or_default(); + /// let bad_year = bad_year_from_input.parse().unwrap_or_default(); /// /// assert_eq!(1909i, good_year); /// assert_eq!(0i, bad_year); diff --git a/src/libcore/result.rs b/src/libcore/result.rs index b59734a7d98..8014b4dc89d 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -458,7 +458,7 @@ impl<T, E> Result<T, E> { /// let line: IoResult<String> = buffer.read_line(); /// // Convert the string line to a number using `map` and `from_str` /// let val: IoResult<int> = line.map(|line| { - /// from_str::<int>(line.as_slice().trim_right()).unwrap_or(0) + /// line.as_slice().trim_right().parse::<int>().unwrap_or(0) /// }); /// // Add the value if there were no errors, otherwise add 0 /// sum += val.ok().unwrap_or(0); diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 60d4262a9b1..bfccc1e3f73 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -18,14 +18,13 @@ use self::Searcher::{Naive, TwoWay, TwoWayLong}; -use char::{mod, Char}; use clone::Clone; use cmp::{mod, Eq}; use default::Default; use iter::range; use iter::{DoubleEndedIteratorExt, ExactSizeIterator}; use iter::{Map, Iterator, IteratorExt, DoubleEndedIterator}; -use kinds::{Copy, Sized}; +use kinds::Sized; use mem; use num::Int; use ops::{Fn, FnMut}; @@ -60,9 +59,9 @@ impl FromStr for bool { /// # Examples /// /// ```rust - /// assert_eq!(from_str::<bool>("true"), Some(true)); - /// assert_eq!(from_str::<bool>("false"), Some(false)); - /// assert_eq!(from_str::<bool>("not even a boolean"), None); + /// assert_eq!("true".parse(), Some(true)); + /// assert_eq!("false".parse(), Some(false)); + /// assert_eq!("not even a boolean".parse::<bool>(), None); /// ``` #[inline] fn from_str(s: &str) -> Option<bool> { @@ -79,6 +78,7 @@ Section: Creating a string */ /// Errors which can occur when attempting to interpret a byte slice as a `str`. +#[deriving(Copy, Eq, PartialEq, Clone)] pub enum Utf8Error { /// An invalid byte was detected at the byte offset given. /// @@ -334,6 +334,7 @@ impl<'a> DoubleEndedIterator<(uint, char)> for CharIndices<'a> { /// External iterator for a string's bytes. /// Use with the `std::iter` module. #[stable] +#[deriving(Clone)] pub struct Bytes<'a> { inner: Map<&'a u8, u8, slice::Items<'a, u8>, BytesFn>, } @@ -946,24 +947,7 @@ pub fn is_utf8(v: &[u8]) -> bool { run_utf8_validation_iterator(&mut v.iter()).is_ok() } -/// Return a slice of `v` ending at (and not including) the first NUL -/// (0). -/// -/// # Example -/// -/// ```rust -/// use std::str; -/// -/// // "abcd" -/// let mut v = ['a' as u16, 'b' as u16, 'c' as u16, 'd' as u16]; -/// // no NULs so no change -/// assert_eq!(str::truncate_utf16_at_nul(&v), v.as_slice()); -/// -/// // "ab\0d" -/// v[2] = 0; -/// let b: &[_] = &['a' as u16, 'b' as u16]; -/// assert_eq!(str::truncate_utf16_at_nul(&v), b); -/// ``` +/// Deprecated function #[deprecated = "this function will be removed"] pub fn truncate_utf16_at_nul<'a>(v: &'a [u16]) -> &'a [u16] { match v.iter().position(|c| *c == 0) { @@ -1595,6 +1579,8 @@ impl<'a> Default for &'a str { impl<'a> Iterator<&'a str> for Lines<'a> { #[inline] fn next(&mut self) -> Option<&'a str> { self.inner.next() } + #[inline] + fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() } } impl<'a> DoubleEndedIterator<&'a str> for Lines<'a> { #[inline] @@ -1603,6 +1589,8 @@ impl<'a> DoubleEndedIterator<&'a str> for Lines<'a> { impl<'a> Iterator<&'a str> for LinesAny<'a> { #[inline] fn next(&mut self) -> Option<&'a str> { self.inner.next() } + #[inline] + fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() } } impl<'a> DoubleEndedIterator<&'a str> for LinesAny<'a> { #[inline] @@ -1611,6 +1599,8 @@ impl<'a> DoubleEndedIterator<&'a str> for LinesAny<'a> { impl<'a> Iterator<u8> for Bytes<'a> { #[inline] fn next(&mut self) -> Option<u8> { self.inner.next() } + #[inline] + fn size_hint(&self) -> (uint, Option<uint>) { self.inner.size_hint() } } impl<'a> DoubleEndedIterator<u8> for Bytes<'a> { #[inline] |
