properly handle character controls from ASCII to UTF-8, re: #48

This commit is contained in:
Mark Thom
2018-09-03 13:57:32 -06:00
parent c3cce4abd5
commit 684e3d217f
2 changed files with 11 additions and 18 deletions

View File

@@ -296,23 +296,16 @@ impl<'a, Formatter: HCValueFormatter, Outputter: HCValueOutputter>
} }
fn print_char(&mut self, c: char) { fn print_char(&mut self, c: char) {
if c == '\n' { match c {
self.outputter.append("\\n"); '\n' => self.outputter.append("\\n"),
} else if c == '\r' { '\r' => self.outputter.append("\\r"),
self.outputter.append("\\r"); '\t' => self.outputter.append("\\t"),
} else if c == '\t' { '\u{0b}' => self.outputter.append("\\v"), // UTF-8 vertical tab
self.outputter.append("\\t"); '\u{0c}' => self.outputter.append("\\f"), // UTF-8 form feed
} else if c == '\u{0b}' { // UTF-8 vertical tab '\u{08}' => self.outputter.append("\\b"), // UTF-8 backspace
self.outputter.append("\\v"); '\u{07}' => self.outputter.append("\\a"), // UTF-8 alert
} else if c == '\u{0c}' { // UTF-8 form feed _ => self.outputter.push_char(c)
self.outputter.append("\\f"); };
} else if c == '\u{08}' { // UTF-8 backspace
self.outputter.append("\\b");
} else if c == '\u{07}' { // UTF-8 alert
self.outputter.append("\\a");
} else {
self.outputter.push_char(c);
}
} }
fn print_constant(&mut self, c: Constant) { fn print_constant(&mut self, c: Constant) {