diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-03-30 11:00:05 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-03-31 15:49:57 -0700 |
| commit | d4a2c941809f303b97d153e06ba07e95cd245f88 (patch) | |
| tree | f876f056ff60aeac3f0098deb2dbe1fabfd13091 /src/libcore/str | |
| parent | d754722a04b99fdcae0fd97fa2a4395521145ef2 (diff) | |
| download | rust-d4a2c941809f303b97d153e06ba07e95cd245f88.tar.gz rust-d4a2c941809f303b97d153e06ba07e95cd245f88.zip | |
std: Clean out #[deprecated] APIs
This commit cleans out a large amount of deprecated APIs from the standard library and some of the facade crates as well, updating all users in the compiler and in tests as it goes along.
Diffstat (limited to 'src/libcore/str')
| -rw-r--r-- | src/libcore/str/mod.rs | 98 | ||||
| -rw-r--r-- | src/libcore/str/pattern.rs | 168 |
2 files changed, 125 insertions, 141 deletions
diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index f9e2b47d9b6..934c4515614 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -28,8 +28,6 @@ use iter::ExactSizeIterator; use iter::{Map, Iterator, DoubleEndedIterator}; use marker::Sized; use mem; -#[allow(deprecated)] -use num::Int; use ops::{Fn, FnMut, FnOnce}; use option::Option::{self, None, Some}; use raw::{Repr, Slice}; @@ -243,78 +241,6 @@ pub unsafe fn from_utf8_unchecked<'a>(v: &'a [u8]) -> &'a str { mem::transmute(v) } -/// Constructs a static string slice from a given raw pointer. -/// -/// This function will read memory starting at `s` until it finds a 0, and then -/// transmute the memory up to that point as a string slice, returning the -/// corresponding `&'static str` value. -/// -/// This function is unsafe because the caller must ensure the C string itself -/// has the static lifetime and that the memory `s` is valid up to and including -/// the first null byte. -/// -/// # Panics -/// -/// This function will panic if the string pointed to by `s` is not valid UTF-8. -#[unstable(feature = "core")] -#[deprecated(since = "1.0.0", - reason = "use std::ffi::c_str_to_bytes + str::from_utf8")] -pub unsafe fn from_c_str(s: *const i8) -> &'static str { - let s = s as *const u8; - let mut len: usize = 0; - while *s.offset(len as isize) != 0 { - len += 1; - } - let v: &'static [u8] = ::mem::transmute(Slice { data: s, len: len }); - from_utf8(v).ok().expect("from_c_str passed invalid utf-8 data") -} - -/// Something that can be used to compare against a character -#[unstable(feature = "core")] -#[deprecated(since = "1.0.0", - reason = "use `Pattern` instead")] -// NB: Rather than removing it, make it private and move it into self::pattern -pub trait CharEq { - /// Determine if the splitter should split at the given character - fn matches(&mut self, char) -> bool; - /// Indicate if this is only concerned about ASCII characters, - /// which can allow for a faster implementation. - fn only_ascii(&self) -> bool; -} - -#[allow(deprecated) /* for CharEq */ ] -impl CharEq for char { - #[inline] - fn matches(&mut self, c: char) -> bool { *self == c } - - #[inline] - fn only_ascii(&self) -> bool { (*self as u32) < 128 } -} - -#[allow(deprecated) /* for CharEq */ ] -impl<F> CharEq for F where F: FnMut(char) -> bool { - #[inline] - fn matches(&mut self, c: char) -> bool { (*self)(c) } - - #[inline] - fn only_ascii(&self) -> bool { false } -} - -#[allow(deprecated) /* for CharEq */ ] -impl<'a> CharEq for &'a [char] { - #[inline] - #[allow(deprecated) /* for CharEq */ ] - fn matches(&mut self, c: char) -> bool { - self.iter().any(|&m| { let mut m = m; m.matches(c) }) - } - - #[inline] - #[allow(deprecated) /* for CharEq */ ] - fn only_ascii(&self) -> bool { - self.iter().all(|m| m.only_ascii()) - } -} - #[stable(feature = "rust1", since = "1.0.0")] impl Error for Utf8Error { fn description(&self) -> &str { @@ -1047,22 +973,6 @@ impl<'a, P: Pattern<'a>> Iterator for MatchIndices<'a, P> { } } -/// An iterator over the substrings of a string separated by a given -/// search string -#[unstable(feature = "core")] -#[deprecated(since = "1.0.0", reason = "use `Split` with a `&str`")] -pub struct SplitStr<'a, P: Pattern<'a>>(Split<'a, P>); -#[allow(deprecated)] -impl<'a, P: Pattern<'a>> Iterator for SplitStr<'a, P> { - type Item = &'a str; - - #[inline] - #[allow(deprecated)] - fn next(&mut self) -> Option<&'a str> { - Iterator::next(&mut self.0) - } -} - impl<'a, 'b> OldMatchIndices<'a, 'b> { #[inline] #[allow(dead_code)] @@ -1444,8 +1354,6 @@ pub trait StrExt { fn rsplitn<'a, P: Pattern<'a>>(&'a self, count: usize, pat: P) -> RSplitN<'a, P> where P::Searcher: ReverseSearcher<'a>; fn match_indices<'a, P: Pattern<'a>>(&'a self, pat: P) -> MatchIndices<'a, P>; - #[allow(deprecated) /* for SplitStr */] - fn split_str<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitStr<'a, P>; fn lines<'a>(&'a self) -> Lines<'a>; fn lines_any<'a>(&'a self) -> LinesAny<'a>; fn char_len(&self) -> usize; @@ -1566,12 +1474,6 @@ impl StrExt for str { } #[inline] - #[allow(deprecated) /* for SplitStr */ ] - fn split_str<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitStr<'a, P> { - SplitStr(self.split(pat)) - } - - #[inline] fn lines(&self) -> Lines { Lines { inner: self.split_terminator('\n').0 } } diff --git a/src/libcore/str/pattern.rs b/src/libcore/str/pattern.rs index 98b6533980d..922ab2c14a6 100644 --- a/src/libcore/str/pattern.rs +++ b/src/libcore/str/pattern.rs @@ -8,10 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(deprecated) /* for CharEq */ ] - use prelude::*; -use super::CharEq; // Pattern @@ -228,6 +225,40 @@ pub trait DoubleEndedSearcher<'a>: ReverseSearcher<'a> {} // Impl for a CharEq wrapper +#[doc(hidden)] +trait CharEq { + fn matches(&mut self, char) -> bool; + fn only_ascii(&self) -> bool; +} + +impl CharEq for char { + #[inline] + fn matches(&mut self, c: char) -> bool { *self == c } + + #[inline] + fn only_ascii(&self) -> bool { (*self as u32) < 128 } +} + +impl<F> CharEq for F where F: FnMut(char) -> bool { + #[inline] + fn matches(&mut self, c: char) -> bool { (*self)(c) } + + #[inline] + fn only_ascii(&self) -> bool { false } +} + +impl<'a> CharEq for &'a [char] { + #[inline] + fn matches(&mut self, c: char) -> bool { + self.iter().any(|&m| { let mut m = m; m.matches(c) }) + } + + #[inline] + fn only_ascii(&self) -> bool { + self.iter().all(|m| m.only_ascii()) + } +} + struct CharEqPattern<C: CharEq>(C); struct CharEqSearcher<'a, C: CharEq> { @@ -425,65 +456,116 @@ fn str_search_step<F, G>(mut m: &mut StrSearcher, } } -macro_rules! associated_items { - ($t:ty, $s:ident, $e:expr) => { - // FIXME: #22463 - //type Searcher = $t; - - fn into_searcher(self, haystack: &'a str) -> $t { - let $s = self; - $e.into_searcher(haystack) +macro_rules! char_eq_pattern_impl { + ($wrapper:ty, $wrapper_ident:ident) => { + fn into_searcher(self, haystack: &'a str) -> $wrapper { + $wrapper_ident(CharEqPattern(self).into_searcher(haystack)) } - #[inline] fn is_contained_in(self, haystack: &'a str) -> bool { - let $s = self; - $e.is_contained_in(haystack) + CharEqPattern(self).is_contained_in(haystack) } - #[inline] fn is_prefix_of(self, haystack: &'a str) -> bool { - let $s = self; - $e.is_prefix_of(haystack) + CharEqPattern(self).is_prefix_of(haystack) } - - // FIXME: #21750 - /*#[inline] + #[inline] fn is_suffix_of(self, haystack: &'a str) -> bool - where $t: ReverseSearcher<'a> + where $wrapper: ReverseSearcher<'a> { - let $s = self; - $e.is_suffix_of(haystack) - }*/ + CharEqPattern(self).is_suffix_of(haystack) + } } } -// CharEq delegation impls +// Pattern for char -/// Searches for chars that are equal to a given char impl<'a> Pattern<'a> for char { - type Searcher = <CharEqPattern<Self> as Pattern<'a>>::Searcher; - associated_items!(<CharEqPattern<Self> as Pattern<'a>>::Searcher, - s, CharEqPattern(s)); + type Searcher = CharSearcher<'a>; + char_eq_pattern_impl!(CharSearcher<'a>, CharSearcher); +} + +pub struct CharSearcher<'a>(CharEqSearcher<'a, char>); + +unsafe impl<'a> Searcher<'a> for CharSearcher<'a> { + #[inline] + fn haystack(&self) -> &'a str { self.0.haystack() } + #[inline] + fn next(&mut self) -> SearchStep { self.0.next() } +} +unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> { + #[inline] + fn next_back(&mut self) -> SearchStep { self.0.next_back() } } +impl<'a> DoubleEndedSearcher<'a> for CharSearcher<'a> {} + +// Pattern for &[char] -/// Searches for chars that are equal to any of the chars in the array impl<'a, 'b> Pattern<'a> for &'b [char] { - type Searcher = <CharEqPattern<Self> as Pattern<'a>>::Searcher; - associated_items!(<CharEqPattern<Self> as Pattern<'a>>::Searcher, - s, CharEqPattern(s)); + type Searcher = CharSliceSearcher<'a, 'b>; + char_eq_pattern_impl!(CharSliceSearcher<'a, 'b>, CharSliceSearcher); } -/// A convenience impl that delegates to the impl for `&str` -impl<'a, 'b> Pattern<'a> for &'b &'b str { - type Searcher = <&'b str as Pattern<'a>>::Searcher; - associated_items!(<&'b str as Pattern<'a>>::Searcher, - s, (*s)); +pub struct CharSliceSearcher<'a, 'b>(CharEqSearcher<'a, &'b [char]>); + +unsafe impl<'a, 'b> Searcher<'a> for CharSliceSearcher<'a, 'b> { + #[inline] + fn haystack(&self) -> &'a str { self.0.haystack() } + #[inline] + fn next(&mut self) -> SearchStep { self.0.next() } +} +unsafe impl<'a, 'b> ReverseSearcher<'a> for CharSliceSearcher<'a, 'b> { + #[inline] + fn next_back(&mut self) -> SearchStep { self.0.next_back() } +} +impl<'a, 'b> DoubleEndedSearcher<'a> for CharSliceSearcher<'a, 'b> {} + +// Pattern for predicates + +impl<'a, F: FnMut(char) -> bool> Pattern<'a> for F { + type Searcher = CharPredSearcher<'a, F>; + char_eq_pattern_impl!(CharPredSearcher<'a, F>, CharPredSearcher); +} + +pub struct CharPredSearcher<'a, F: FnMut(char) -> bool>(CharEqSearcher<'a, F>); + +unsafe impl<'a, F> Searcher<'a> for CharPredSearcher<'a, F> + where F: FnMut(char) -> bool +{ + #[inline] + fn haystack(&self) -> &'a str { self.0.haystack() } + #[inline] + fn next(&mut self) -> SearchStep { self.0.next() } +} +unsafe impl<'a, F> ReverseSearcher<'a> for CharPredSearcher<'a, F> + where F: FnMut(char) -> bool +{ + #[inline] + fn next_back(&mut self) -> SearchStep { self.0.next_back() } } +impl<'a, F> DoubleEndedSearcher<'a> for CharPredSearcher<'a, F> + where F: FnMut(char) -> bool +{} -/// Searches for chars that match the given predicate -impl<'a, F> Pattern<'a> for F where F: FnMut(char) -> bool { - type Searcher = <CharEqPattern<Self> as Pattern<'a>>::Searcher; - associated_items!(<CharEqPattern<Self> as Pattern<'a>>::Searcher, - s, CharEqPattern(s)); +// Pattern for &&str + +impl<'a, 'b> Pattern<'a> for &'b &'b str { + type Searcher = <&'b str as Pattern<'a>>::Searcher; + #[inline] + fn into_searcher(self, haystack: &'a str) + -> <&'b str as Pattern<'a>>::Searcher { + (*self).into_searcher(haystack) + } + #[inline] + fn is_contained_in(self, haystack: &'a str) -> bool { + (*self).is_contained_in(haystack) + } + #[inline] + fn is_prefix_of(self, haystack: &'a str) -> bool { + (*self).is_prefix_of(haystack) + } + #[inline] + fn is_suffix_of(self, haystack: &'a str) -> bool { + (*self).is_suffix_of(haystack) + } } |
