Merge pull request #2517 from jfinkels/tac-null-separator

tac: support null separator (-s "")
This commit is contained in:
Sylvestre Ledru 2021-08-03 09:22:50 +02:00 committed by GitHub
commit 26cc2ed440
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 10 deletions

View file

@ -35,15 +35,11 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
let before = matches.is_present(options::BEFORE);
let regex = matches.is_present(options::REGEX);
let separator = match matches.value_of(options::SEPARATOR) {
Some(m) => {
if m.is_empty() {
crash!(1, "separator cannot be empty")
} else {
m.to_owned()
}
}
None => "\n".to_owned(),
let raw_separator = matches.value_of(options::SEPARATOR).unwrap_or("\n");
let separator = if raw_separator.is_empty() {
"\0"
} else {
raw_separator
};
let files: Vec<String> = match matches.values_of(options::FILE) {
@ -51,7 +47,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
None => vec!["-".to_owned()],
};
tac(files, before, regex, &separator[..])
tac(files, before, regex, separator)
}
pub fn uu_app() -> App<'static, 'static> {

View file

@ -73,3 +73,12 @@ fn test_invalid_input() {
fn test_no_line_separators() {
new_ucmd!().pipe_in("a").succeeds().stdout_is("a");
}
#[test]
fn test_null_separator() {
new_ucmd!()
.args(&["-s", ""])
.pipe_in("a\0b\0")
.succeeds()
.stdout_is("b\0a\0");
}