about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libcore/char/methods.rs26
-rw-r--r--src/libcore/fmt/mod.rs10
-rwxr-xr-xsrc/libcore/unicode/unicode.py2
3 files changed, 33 insertions, 5 deletions
diff --git a/src/libcore/char/methods.rs b/src/libcore/char/methods.rs
index 374adafef64..c170e0c1ba1 100644
--- a/src/libcore/char/methods.rs
+++ b/src/libcore/char/methods.rs
@@ -229,8 +229,8 @@ impl char {
             '\r' => EscapeDefaultState::Backslash('r'),
             '\n' => EscapeDefaultState::Backslash('n'),
             '\\' | '\'' | '"' => EscapeDefaultState::Backslash(self),
-            c if is_printable(c) => EscapeDefaultState::Char(c),
-            c => EscapeDefaultState::Unicode(c.escape_unicode()),
+            _ if is_printable(self) => EscapeDefaultState::Char(self),
+            _ => EscapeDefaultState::Unicode(self.escape_unicode()),
         };
         EscapeDebug(EscapeDefault { state: init_state })
     }
@@ -692,6 +692,28 @@ impl char {
         general_category::Cc(self)
     }
 
+    /// Returns true if this `char` is a nonspacing mark code point, and false otherwise.
+    ///
+    /// 'Nonspacing mark code point' is defined in terms of the Unicode General
+    /// Category `Mn`.
+    ///
+    /// # Examples
+    ///
+    /// Basic usage:
+    ///
+    /// ```
+    /// // U+0301, COMBINING ACUTE ACCENT
+    /// assert!('\u{301}'.is_nonspacing_mark());
+    /// assert!(!'e'.is_nonspacing_mark());
+    /// ```
+    #[unstable(feature = "rustc_private",
+               reason = "mainly needed for compiler internals",
+               issue = "27812")]
+    #[inline]
+    pub fn is_nonspacing_mark(self) -> bool {
+        general_category::Mn(self)
+    }
+
     /// Returns true if this `char` is numeric, and false otherwise.
     ///
     /// 'Numeric'-ness is defined in terms of the Unicode General Categories
diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs
index 5820fe58932..1cfde513102 100644
--- a/src/libcore/fmt/mod.rs
+++ b/src/libcore/fmt/mod.rs
@@ -1844,8 +1844,14 @@ impl Display for str {
 impl Debug for char {
     fn fmt(&self, f: &mut Formatter) -> Result {
         f.write_char('\'')?;
-        for c in self.escape_debug() {
-            f.write_char(c)?
+        if self.is_nonspacing_mark() {
+            for c in self.escape_unicode() {
+                f.write_char(c)?
+            }
+        } else {
+            for c in self.escape_debug() {
+                f.write_char(c)?
+            }
         }
         f.write_char('\'')
     }
diff --git a/src/libcore/unicode/unicode.py b/src/libcore/unicode/unicode.py
index d24b4eb4ce4..5b3c181ea9b 100755
--- a/src/libcore/unicode/unicode.py
+++ b/src/libcore/unicode/unicode.py
@@ -496,7 +496,7 @@ pub const UNICODE_VERSION: UnicodeVersion = UnicodeVersion {
                      ["Full_Composition_Exclusion"])
 
         # category tables
-        for (name, cat, pfuns) in ("general_category", gencats, ["N", "Cc"]), \
+        for (name, cat, pfuns) in ("general_category", gencats, ["N", "Cc", "Mn"]), \
                                   ("derived_property", derived, want_derived), \
                                   ("property", props, ["White_Space", "Pattern_White_Space"]):
             emit_property_module(rf, name, cat, pfuns)