about summary refs log tree commit diff
path: root/src/librustc_unicode
diff options
context:
space:
mode:
Diffstat (limited to 'src/librustc_unicode')
-rw-r--r--src/librustc_unicode/char.rs37
-rw-r--r--src/librustc_unicode/lib.rs1
2 files changed, 37 insertions, 1 deletions
diff --git a/src/librustc_unicode/char.rs b/src/librustc_unicode/char.rs
index 1ea0f8d70a8..81856cb87c7 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, EscapeDebug, 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_debug", issue = "35068")]
+    #[inline]
+    pub fn escape_debug(self) -> EscapeDebug {
+        C::escape_debug(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..3ae905eba27 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_debug)]
 #![feature(core_char_ext)]
 #![feature(decode_utf8)]
 #![feature(lang_items)]