forked from bonsai/harakit
fop(1): fixes glaring issue with newline handling
This commit is contained in:
parent
0f121cbac7
commit
d2ae35eac9
11
src/fop.rs
11
src/fop.rs
@ -71,7 +71,7 @@ fn main() {
|
|||||||
|
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
if let Err(e) = stdin().read_to_string(&mut buf) {
|
if let Err(e) = stdin().read_to_string(&mut buf) {
|
||||||
eprintln!("{}: {}", argv[0], e.strerror);
|
eprintln!("{}: {}", argv[0], e.strerror());
|
||||||
exit(EX_IOERR);
|
exit(EX_IOERR);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -120,8 +120,13 @@ fn main() {
|
|||||||
/* get the output with which the original field will be replaced */
|
/* get the output with which the original field will be replaced */
|
||||||
let mut replace = output.stdout.clone();
|
let mut replace = output.stdout.clone();
|
||||||
|
|
||||||
/* as long as it’s not a newline, set the replacement to the output */
|
/* pop trailing newline out if the input did not contain it */
|
||||||
if replace.pop() != Some(b'\n') { replace = output.stdout; }
|
if fields[index].chars().last() != Some('\n') /* no newline */
|
||||||
|
&& replace.pop() != Some(b'\n') { /* pop last char of replacement */
|
||||||
|
/* restore replacement to original command output if popped char was not
|
||||||
|
* a newline */
|
||||||
|
replace = output.stdout;
|
||||||
|
}
|
||||||
|
|
||||||
/* convert the output of the program to UTF-8 */
|
/* convert the output of the program to UTF-8 */
|
||||||
let new_field = String::from_utf8(replace).unwrap_or_else(|e| {
|
let new_field = String::from_utf8(replace).unwrap_or_else(|e| {
|
||||||
|
Loading…
Reference in New Issue
Block a user