mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
tac: support null separator
This commit is contained in:
parent
24b1822cba
commit
d74fb62df7
2 changed files with 15 additions and 10 deletions
|
@ -35,15 +35,11 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
|
|
||||||
let before = matches.is_present(options::BEFORE);
|
let before = matches.is_present(options::BEFORE);
|
||||||
let regex = matches.is_present(options::REGEX);
|
let regex = matches.is_present(options::REGEX);
|
||||||
let separator = match matches.value_of(options::SEPARATOR) {
|
let raw_separator = matches.value_of(options::SEPARATOR).unwrap_or("\n");
|
||||||
Some(m) => {
|
let separator = if raw_separator.is_empty() {
|
||||||
if m.is_empty() {
|
"\0"
|
||||||
crash!(1, "separator cannot be empty")
|
|
||||||
} else {
|
} else {
|
||||||
m.to_owned()
|
raw_separator
|
||||||
}
|
|
||||||
}
|
|
||||||
None => "\n".to_owned(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let files: Vec<String> = match matches.values_of(options::FILE) {
|
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()],
|
None => vec!["-".to_owned()],
|
||||||
};
|
};
|
||||||
|
|
||||||
tac(files, before, regex, &separator[..])
|
tac(files, before, regex, separator)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uu_app() -> App<'static, 'static> {
|
pub fn uu_app() -> App<'static, 'static> {
|
||||||
|
|
|
@ -73,3 +73,12 @@ fn test_invalid_input() {
|
||||||
fn test_no_line_separators() {
|
fn test_no_line_separators() {
|
||||||
new_ucmd!().pipe_in("a").succeeds().stdout_is("a");
|
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");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue