diff options
| author | Tobias Bucher <tobiasbucher5991@gmail.com> | 2016-07-26 01:39:54 +0200 |
|---|---|---|
| committer | Tobias Bucher <tobiasbucher5991@gmail.com> | 2016-07-26 15:15:00 +0200 |
| commit | 68efea08fa1cf800b3b76683992ec77a89323d53 (patch) | |
| tree | f9c7cee686d99efacdf80cbbaf477bd6ff19f12f /src/librustc_unicode | |
| parent | 0685900fbd1ea1f6be5c3454dcde753ac3484c01 (diff) | |
| download | rust-68efea08fa1cf800b3b76683992ec77a89323d53.tar.gz rust-68efea08fa1cf800b3b76683992ec77a89323d53.zip | |
Restore `char::escape_default` and add `char::escape` instead
Diffstat (limited to 'src/librustc_unicode')
| -rw-r--r-- | src/librustc_unicode/char.rs | 37 | ||||
| -rw-r--r-- | src/librustc_unicode/lib.rs | 1 |
2 files changed, 37 insertions, 1 deletions
diff --git a/src/librustc_unicode/char.rs b/src/librustc_unicode/char.rs index 7445ff94eb5..683d5289ab5 100644 --- a/src/librustc_unicode/char.rs +++ b/src/librustc_unicode/char.rs @@ -36,7 +36,7 @@ use tables::{conversions, derived_property, general_category, property}; #[stable(feature = "rust1", since = "1.0.0")] pub use core::char::{MAX, from_digit, from_u32, from_u32_unchecked}; #[stable(feature = "rust1", since = "1.0.0")] -pub use core::char::{EncodeUtf16, EncodeUtf8, EscapeDefault, EscapeUnicode}; +pub use core::char::{EncodeUtf16, EncodeUtf8, Escape, EscapeDefault, EscapeUnicode}; // unstable reexports #[unstable(feature = "decode_utf8", issue = "33906")] @@ -269,6 +269,41 @@ impl char { /// Returns an iterator that yields the literal escape code of a `char`. /// + /// This will escape the characters similar to the `Debug` implementations + /// of `str` or `char`. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// for i in '\n'.escape_default() { + /// println!("{}", i); + /// } + /// ``` + /// + /// This prints: + /// + /// ```text + /// \ + /// n + /// ``` + /// + /// Collecting into a `String`: + /// + /// ``` + /// let quote: String = '\n'.escape_default().collect(); + /// + /// assert_eq!(quote, "\\n"); + /// ``` + #[unstable(feature = "char_escape", issue = "0")] + #[inline] + pub fn escape(self) -> Escape { + C::escape(self) + } + + /// Returns an iterator that yields the literal escape code of a `char`. + /// /// The default is chosen with a bias toward producing literals that are /// legal in a variety of languages, including C++11 and similar C-family /// languages. The exact rules are: diff --git a/src/librustc_unicode/lib.rs b/src/librustc_unicode/lib.rs index f91a754ab57..8c91d3b6a92 100644 --- a/src/librustc_unicode/lib.rs +++ b/src/librustc_unicode/lib.rs @@ -32,6 +32,7 @@ #![cfg_attr(not(stage0), deny(warnings))] #![no_std] +#![feature(char_escape)] #![feature(core_char_ext)] #![feature(decode_utf8)] #![feature(lang_items)] |
