From 448211bbe293856845ca6915978e2d0b251435c7 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 14 Feb 2024 23:05:39 -0700 Subject: [PATCH] fop(1): better newline removal (preserves existing newlines) --- src/fop.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/fop.rs b/src/fop.rs index ba99ae4..09cac94 100644 --- a/src/fop.rs +++ b/src/fop.rs @@ -101,7 +101,11 @@ fn main() { exit(EX_IOERR); }); - let new_field = String::from_utf8(output.stdout).unwrap_or_else(|_| { + let mut replace = output.stdout.clone(); + + if replace.pop() != Some(b'\n') { replace = output.stdout; } + + let new_field = String::from_utf8(replace).unwrap_or_else(|_| { eprintln!( "{}: {}: Command output is invalid UTF-8.", argv[0], @@ -110,7 +114,7 @@ fn main() { exit(EX_IOERR); }); - fields[index] = &new_field.trim_end(); + fields[index] = &new_field; print!("{}", fields.join(&d.to_string())); }