mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 17:58:06 +00:00
tr: fix squeeze and complement with two sets (#2485)
This commit is contained in:
parent
2177b8dc37
commit
30b80d0c82
2 changed files with 17 additions and 18 deletions
|
@ -173,16 +173,14 @@ struct TranslateAndSqueezeOperation {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TranslateAndSqueezeOperation {
|
impl TranslateAndSqueezeOperation {
|
||||||
fn new(
|
fn new(sets: Vec<String>, truncate: bool, complement: bool) -> TranslateAndSqueezeOperation {
|
||||||
set1: ExpandSet,
|
let set1 = ExpandSet::new(sets[0].as_ref());
|
||||||
set2: &mut ExpandSet,
|
let set1_ = ExpandSet::new(sets[0].as_ref());
|
||||||
set2_: ExpandSet,
|
let mut set2 = ExpandSet::new(sets[1].as_ref());
|
||||||
truncate: bool,
|
let set2_ = ExpandSet::new(sets[1].as_ref());
|
||||||
complement: bool,
|
|
||||||
) -> TranslateAndSqueezeOperation {
|
|
||||||
TranslateAndSqueezeOperation {
|
TranslateAndSqueezeOperation {
|
||||||
translate: TranslateOperation::new(set1, set2, truncate, complement),
|
translate: TranslateOperation::new(set1, &mut set2, truncate, complement),
|
||||||
squeeze: SqueezeOperation::new(set2_, complement),
|
squeeze: SqueezeOperation::new(if complement { set1_ } else { set2_ }, complement),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -302,15 +300,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
let op = SqueezeOperation::new(set1, complement_flag);
|
let op = SqueezeOperation::new(set1, complement_flag);
|
||||||
translate_input(&mut locked_stdin, &mut buffered_stdout, op);
|
translate_input(&mut locked_stdin, &mut buffered_stdout, op);
|
||||||
} else {
|
} else {
|
||||||
let mut set2 = ExpandSet::new(sets[1].as_ref());
|
let op = TranslateAndSqueezeOperation::new(sets, truncate_flag, complement_flag);
|
||||||
let set2_ = ExpandSet::new(sets[1].as_ref());
|
|
||||||
let op = TranslateAndSqueezeOperation::new(
|
|
||||||
set1,
|
|
||||||
&mut set2,
|
|
||||||
set2_,
|
|
||||||
complement_flag,
|
|
||||||
truncate_flag,
|
|
||||||
);
|
|
||||||
translate_input(&mut locked_stdin, &mut buffered_stdout, op);
|
translate_input(&mut locked_stdin, &mut buffered_stdout, op);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -127,6 +127,15 @@ fn test_squeeze_complement() {
|
||||||
.stdout_is("aaBcDcc");
|
.stdout_is("aaBcDcc");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_squeeze_complement_two_sets() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-sc", "a", "_"])
|
||||||
|
.pipe_in("test a aa with 3 ___ spaaaces +++") // spell-checker:disable-line
|
||||||
|
.run()
|
||||||
|
.stdout_is("_a_aa_aaa_");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_translate_and_squeeze() {
|
fn test_translate_and_squeeze() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
|
Loading…
Reference in a new issue