Skip to content

Commit 4694d20

Browse files
committed
Escape combining characters in escape_debug
1 parent b72faf5 commit 4694d20

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

src/libcore/char/methods.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ impl char {
229229
'\r' => EscapeDefaultState::Backslash('r'),
230230
'\n' => EscapeDefaultState::Backslash('n'),
231231
'\\' | '\'' | '"' => EscapeDefaultState::Backslash(self),
232-
c if is_printable(c) => EscapeDefaultState::Char(c),
233-
c => EscapeDefaultState::Unicode(c.escape_unicode()),
232+
_ if is_printable(self) => EscapeDefaultState::Char(self),
233+
_ => EscapeDefaultState::Unicode(self.escape_unicode()),
234234
};
235235
EscapeDebug(EscapeDefault { state: init_state })
236236
}
@@ -692,6 +692,28 @@ impl char {
692692
general_category::Cc(self)
693693
}
694694

695+
/// Returns true if this `char` is a nonspacing mark code point, and false otherwise.
696+
///
697+
/// 'Nonspacing mark code point' is defined in terms of the Unicode General
698+
/// Category `Mn`.
699+
///
700+
/// # Examples
701+
///
702+
/// Basic usage:
703+
///
704+
/// ```
705+
/// // U+0301, COMBINING ACUTE ACCENT
706+
/// assert!('\u{301}'.is_nonspacing_mark());
707+
/// assert!(!'e'.is_nonspacing_mark());
708+
/// ```
709+
#[unstable(feature = "rustc_private",
710+
reason = "mainly needed for compiler internals",
711+
issue = "27812")]
712+
#[inline]
713+
pub fn is_nonspacing_mark(self) -> bool {
714+
general_category::Mn(self)
715+
}
716+
695717
/// Returns true if this `char` is numeric, and false otherwise.
696718
///
697719
/// 'Numeric'-ness is defined in terms of the Unicode General Categories

src/libcore/fmt/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,8 +1844,14 @@ impl Display for str {
18441844
impl Debug for char {
18451845
fn fmt(&self, f: &mut Formatter) -> Result {
18461846
f.write_char('\'')?;
1847-
for c in self.escape_debug() {
1848-
f.write_char(c)?
1847+
if self.is_nonspacing_mark() {
1848+
for c in self.escape_unicode() {
1849+
f.write_char(c)?
1850+
}
1851+
} else {
1852+
for c in self.escape_debug() {
1853+
f.write_char(c)?
1854+
}
18491855
}
18501856
f.write_char('\'')
18511857
}

src/libcore/unicode/unicode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ def emit_norm_module(f, canon, compat, combine, norm_props):
496496
["Full_Composition_Exclusion"])
497497

498498
# category tables
499-
for (name, cat, pfuns) in ("general_category", gencats, ["N", "Cc"]), \
499+
for (name, cat, pfuns) in ("general_category", gencats, ["N", "Cc", "Mn"]), \
500500
("derived_property", derived, want_derived), \
501501
("property", props, ["White_Space", "Pattern_White_Space"]):
502502
emit_property_module(rf, name, cat, pfuns)

0 commit comments

Comments
 (0)