Skip to content

Commit

Permalink
Merge pull request #1805 from triska/master
Browse files Browse the repository at this point in the history
extend logic to all control and whitespace characters
  • Loading branch information
mthom committed May 15, 2023
2 parents 2f9996f + 49addc7 commit f7d9237
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/heap_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,16 @@ fn char_to_string(is_quoted: bool, c: char) -> String {
'\u{08}' if is_quoted => "\\b".to_string(), // UTF-8 backspace
'\u{07}' if is_quoted => "\\a".to_string(), // UTF-8 alert
'\\' if is_quoted => "\\\\".to_string(),
'\'' | '\n' | '\r' | '\t' | '\u{0b}' | '\u{0c}' | '\u{08}' | '\u{07}' | '"' | '\\' => {
' ' | '\'' | '\n' | '\r' | '\t' | '\u{0b}' | '\u{0c}' | '\u{08}' | '\u{07}' | '"' | '\\' => {
c.to_string()
}
'\u{0}'..='\u{1f}' | '\u{7f}' ..= '\u{a0}'
// print all other control characters, and also non-breaking space, in hex.
=> format!("\\x{:x}\\", c as u32),
_ => c.to_string(),
_ =>
if c.is_whitespace() || c.is_control() {
// print all other control and whitespace characters in hex.
format!("\\x{:x}\\", c as u32)
} else {
c.to_string()
}
}
}

Expand Down

0 comments on commit f7d9237

Please sign in to comment.