From: Markus Triska Date: Sun, 14 May 2023 07:14:10 +0000 (+0200) Subject: extend logic to all control and whitespace characters X-Git-Tag: v0.9.2~123^2~20 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=c2f26234718ed285f7f28d96cdb3782707e76aec;p=scryer-prolog.git extend logic to all control and whitespace characters This addresses #1802. --- diff --git a/src/heap_print.rs b/src/heap_print.rs index c861a26c..dfb2efde 100644 --- a/src/heap_print.rs +++ b/src/heap_print.rs @@ -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() + } } }