replace_nonprintable: Keep \n around
Since it has a functional role, we can not just replace it, we must keep
it around. This also allows us to simplify the code slightly.
We must fix this before we fix #1438 since otherwise the \n will be
missing with --style=plain, since we will stop adding it if it is
missing.
commitc3fc1b88fea5e4f4aee2e02ee7426180031a0081
authorMartin Nordholts <enselic@gmail.com>
dateSat 19 Dec 2020, 10:21 (6 years ago)
parentf3489ff
src/preprocessor.rs+1−1
@@ -72,7 +72,7 @@ pub fn replace_nonprintable(input: &[u8], tab_width: usize) -> String {
7272 }
7373 }
7474 // line feed
75− '\x0A' => output.push('␊'),
75+ '\x0A' => output.push_str("␊\x0A"),
7676 // carriage return
7777 '\x0D' => output.push('␍'),
7878 // null
src/printer.rs−3
@@ -91,9 +91,6 @@ impl<'a> Printer for SimplePrinter<'a> {
9191 if self.config.show_nonprintable {
9292 let line = replace_nonprintable(line_buffer, self.config.tab_width);
9393 write!(handle, "{}", line)?;
94− if line_buffer.last() == Some(&b'\n') {
95− writeln!(handle)?;
96− }
9794 } else {
9895 handle.write_all(line_buffer)?
9996 };