From 8b9991d7808d65782844ac68a2f9c53fa4225dc6 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Tue, 8 May 2018 23:49:59 +0200 Subject: [PATCH] Append newline at the end of the file if necessary --- src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 78c794cb..773f3432 100644 --- a/src/main.rs +++ b/src/main.rs @@ -199,7 +199,12 @@ fn print_file( Ok(0) => { break; } - Ok(_) => &line_buffer, + Ok(_) => { + if !line_buffer.ends_with("\n") { + line_buffer.push('\n'); + } + &line_buffer + } Err(_) => "\n", };