extend logic to all control and whitespace characters

This addresses #1802.
This commit is contained in:
Markus Triska
2023-05-14 09:14:10 +02:00
committed by Mark
parent 8e4465315f
commit c2f2623471

View File

@@ -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{08}' if is_quoted => "\\b".to_string(), // UTF-8 backspace
'\u{07}' if is_quoted => "\\a".to_string(), // UTF-8 alert '\u{07}' if is_quoted => "\\a".to_string(), // UTF-8 alert
'\\' if is_quoted => "\\\\".to_string(), '\\' 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() c.to_string()
} }
'\u{0}'..='\u{1f}' | '\u{7f}' ..= '\u{a0}' _ =>
// print all other control characters, and also non-breaking space, in hex. if c.is_whitespace() || c.is_control() {
=> format!("\\x{:x}\\", c as u32), // print all other control and whitespace characters in hex.
_ => c.to_string(), format!("\\x{:x}\\", c as u32)
} else {
c.to_string()
}
} }
} }