Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Escape combining characters in escape_debug
  • Loading branch information
varkor committed May 21, 2018
1 parent b72faf5 commit 4694d20
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
26 changes: 24 additions & 2 deletions src/libcore/char/methods.rs
Expand Up @@ -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 })
}
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/libcore/fmt/mod.rs
Expand Up @@ -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('\'')
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/unicode/unicode.py
Expand Up @@ -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)
Expand Down

0 comments on commit 4694d20

Please sign in to comment.