diff options
| author | Simon Sapin <simon.sapin@exyr.org> | 2019-02-02 10:34:36 +0100 |
|---|---|---|
| committer | Simon Sapin <simon.sapin@exyr.org> | 2019-02-12 09:55:30 +0100 |
| commit | 92cce78d066676f49524c07f72c7cdbf49cc0de8 (patch) | |
| tree | 7658b238251d38775df0901b186e6277823a25b2 /src/liballoc | |
| parent | 55216f82a69092fdb22fb779d3f64d3d756c7ed8 (diff) | |
| download | rust-92cce78d066676f49524c07f72c7cdbf49cc0de8.tar.gz rust-92cce78d066676f49524c07f72c7cdbf49cc0de8.zip | |
Move str::escape_* to libcore
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/str.rs | 118 |
1 files changed, 0 insertions, 118 deletions
diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 8daa088a21a..a36804bddff 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -29,13 +29,8 @@ #![allow(unused_imports)] use core::borrow::Borrow; -use core::fmt::{self, Write}; -use core::char; -use core::iter::{Chain, Flatten, FlatMap}; use core::str::pattern::{Pattern, Searcher, ReverseSearcher, DoubleEndedSearcher}; use core::mem; -use core::ops::Try; -use core::option; use core::ptr; use core::iter::FusedIterator; use core::unicode::conversions; @@ -446,40 +441,6 @@ impl str { return s; } - /// Escapes each char in `s` with [`char::escape_debug`]. - /// - /// Note: only extended grapheme codepoints that begin the string will be - /// escaped. - /// - /// [`char::escape_debug`]: primitive.char.html#method.escape_debug - #[stable(feature = "str_escape", since = "1.34.0")] - pub fn escape_debug(&self) -> EscapeDebug { - let mut chars = self.chars(); - EscapeDebug { - inner: chars.next() - .map(|first| first.escape_debug_ext(true)) - .into_iter() - .flatten() - .chain(chars.flat_map(CharEscapeDebugContinue)) - } - } - - /// Escapes each char in `s` with [`char::escape_default`]. - /// - /// [`char::escape_default`]: primitive.char.html#method.escape_default - #[stable(feature = "str_escape", since = "1.34.0")] - pub fn escape_default(&self) -> EscapeDefault { - EscapeDefault { inner: self.chars().flat_map(CharEscapeDefault) } - } - - /// Escapes each char in `s` with [`char::escape_unicode`]. - /// - /// [`char::escape_unicode`]: primitive.char.html#method.escape_unicode - #[stable(feature = "str_escape", since = "1.34.0")] - pub fn escape_unicode(&self) -> EscapeUnicode { - EscapeUnicode { inner: self.chars().flat_map(CharEscapeUnicode) } - } - /// Converts a [`Box<str>`] into a [`String`] without copying or allocating. /// /// [`String`]: string/struct.String.html @@ -611,82 +572,3 @@ pub unsafe fn from_boxed_utf8_unchecked(v: Box<[u8]>) -> Box<str> { Box::from_raw(Box::into_raw(v) as *mut str) } -impl_fn_for_zst! { - #[derive(Clone)] - struct CharEscapeDebugContinue impl Fn = |c: char| -> char::EscapeDebug { - c.escape_debug_ext(false) - }; - - #[derive(Clone)] - struct CharEscapeUnicode impl Fn = |c: char| -> char::EscapeUnicode { - c.escape_unicode() - }; - #[derive(Clone)] - struct CharEscapeDefault impl Fn = |c: char| -> char::EscapeDefault { - c.escape_default() - }; -} - -macro_rules! escape_types { - ($( - struct $Name: ident<'a> { - inner: $Inner: ty, - } - )+) => {$( - #[stable(feature = "str_escape", since = "1.34.0")] - #[derive(Clone, Debug)] - pub struct $Name<'a> { - inner: $Inner, - } - - #[stable(feature = "str_escape", since = "1.34.0")] - impl<'a> fmt::Display for $Name<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.clone().try_for_each(|c| f.write_char(c)) - } - } - - #[stable(feature = "str_escape", since = "1.34.0")] - impl<'a> Iterator for $Name<'a> { - type Item = char; - - #[inline] - fn next(&mut self) -> Option<char> { self.inner.next() } - - #[inline] - fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() } - - #[inline] - fn try_fold<Acc, Fold, R>(&mut self, init: Acc, fold: Fold) -> R where - Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, R: Try<Ok=Acc> - { - self.inner.try_fold(init, fold) - } - - #[inline] - fn fold<Acc, Fold>(self, init: Acc, fold: Fold) -> Acc - where Fold: FnMut(Acc, Self::Item) -> Acc, - { - self.inner.fold(init, fold) - } - } - - #[stable(feature = "str_escape", since = "1.34.0")] - impl<'a> FusedIterator for $Name<'a> {} - )+} -} - -escape_types! { - struct EscapeDebug<'a> { - inner: Chain< - Flatten<option::IntoIter<char::EscapeDebug>>, - FlatMap<Chars<'a>, char::EscapeDebug, CharEscapeDebugContinue> - >, - } - struct EscapeUnicode<'a> { - inner: FlatMap<Chars<'a>, char::EscapeUnicode, CharEscapeUnicode>, - } - struct EscapeDefault<'a> { - inner: FlatMap<Chars<'a>, char::EscapeDefault, CharEscapeDefault>, - } -} |
