1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

paste: Handle unicode delimiters

This commit is contained in:
Zachary Dremann 2022-01-30 22:03:17 -05:00
parent 7b3cfcf708
commit fa44957a63
2 changed files with 18 additions and 4 deletions

View file

@ -10,7 +10,6 @@
use clap::{crate_version, App, AppSettings, Arg};
use std::fs::File;
use std::io::{stdin, BufRead, BufReader, Read};
use std::iter::repeat;
use std::path::Path;
use uucore::error::{FromIo, UResult};
@ -110,10 +109,11 @@ fn paste(filenames: Vec<String>, serial: bool, delimiters: &str) -> UResult<()>
}
delim_count += 1;
}
println!("{}", &output[..output.len() - 1]);
output.pop();
println!("{}", output);
}
} else {
let mut eof: Vec<bool> = repeat(false).take(files.len()).collect();
let mut eof = vec![false; files.len()];
loop {
let mut output = String::new();
let mut eof_count = 0;
@ -137,7 +137,9 @@ fn paste(filenames: Vec<String>, serial: bool, delimiters: &str) -> UResult<()>
if files.len() == eof_count {
break;
}
println!("{}", &output[..output.len() - 1]);
// Remove final delimiter
output.pop();
println!("{}", output);
delim_count = 0;
}
}

View file

@ -60,6 +60,18 @@ static EXAMPLE_DATA: &[TestData] = &[
ins: &["1\na\n", "2\nb\n"],
out: "1 2\na b\n",
},
TestData {
name: "multibyte-delim",
args: &["-d", "💣"],
ins: &["1\na\n", "2\nb\n"],
out: "1💣2\na💣b\n",
},
TestData {
name: "multibyte-delim-serial",
args: &["-d", "💣", "-s"],
ins: &["1\na\n", "2\nb\n"],
out: "1💣a\n2💣b\n",
},
];
#[test]