fop(1): better newline removal (preserves existing newlines)

This commit is contained in:
Emma Tebibyte 2024-02-14 23:05:39 -07:00
parent 4c663bf9dd
commit 448211bbe2
Signed by untrusted user: emma
GPG Key ID: 06FA419A1698C270

View File

@ -101,7 +101,11 @@ fn main() {
exit(EX_IOERR); 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!( eprintln!(
"{}: {}: Command output is invalid UTF-8.", "{}: {}: Command output is invalid UTF-8.",
argv[0], argv[0],
@ -110,7 +114,7 @@ fn main() {
exit(EX_IOERR); exit(EX_IOERR);
}); });
fields[index] = &new_field.trim_end(); fields[index] = &new_field;
print!("{}", fields.join(&d.to_string())); print!("{}", fields.join(&d.to_string()));
} }