diff --git a/src/libcore/char/methods.rs b/src/libcore/char/methods.rs index 374adafef647d..c170e0c1ba1c9 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 5820fe58932c6..1cfde5131026a 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 d24b4eb4ce4e3..5b3c181ea9bb3 100755 --- a/src/libcore/unicode/unicode.py +++ b/src/libcore/unicode/unicode.py @@ -496,7 +496,7 @@ def emit_norm_module(f, canon, compat, combine, norm_props): ["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)