mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
cut: don't merge adjacent ranges
This commit is contained in:
parent
913d5d413b
commit
392c48002c
2 changed files with 4 additions and 9 deletions
|
@ -91,7 +91,7 @@ impl Range {
|
|||
Ok(Self::merge(ranges))
|
||||
}
|
||||
|
||||
/// Merge any overlapping ranges
|
||||
/// Merge any overlapping ranges. Adjacent ranges are *NOT* merged.
|
||||
///
|
||||
/// Is guaranteed to return only disjoint ranges in a sorted order.
|
||||
fn merge(mut ranges: Vec<Self>) -> Vec<Self> {
|
||||
|
@ -101,10 +101,7 @@ impl Range {
|
|||
for i in 0..ranges.len() {
|
||||
let j = i + 1;
|
||||
|
||||
// The +1 is a small optimization, because we can merge adjacent Ranges.
|
||||
// For example (1,3) and (4,6), because in the integers, there are no
|
||||
// possible values between 3 and 4, this is equivalent to (1,6).
|
||||
while j < ranges.len() && ranges[j].low <= ranges[i].high + 1 {
|
||||
while j < ranges.len() && ranges[j].low <= ranges[i].high {
|
||||
let j_high = ranges.remove(j).high;
|
||||
ranges[i].high = max(ranges[i].high, j_high);
|
||||
}
|
||||
|
@ -216,8 +213,8 @@ mod test {
|
|||
&[r(10, 40), r(50, 60)],
|
||||
);
|
||||
|
||||
// Merge adjacent ranges
|
||||
m(vec![r(1, 3), r(4, 6)], &[r(1, 6)]);
|
||||
// Don't merge adjacent ranges
|
||||
m(vec![r(1, 3), r(4, 6)], &[r(1, 3), r(4, 6)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -350,7 +350,6 @@ fn test_newline_preservation_with_f1_option() {
|
|||
ucmd.args(&["-f1-", "1"]).succeeds().stdout_is(expected);
|
||||
}
|
||||
|
||||
#[ignore = "Not yet implemented"]
|
||||
#[test]
|
||||
fn test_output_delimiter_with_character_ranges() {
|
||||
new_ucmd!()
|
||||
|
@ -360,7 +359,6 @@ fn test_output_delimiter_with_character_ranges() {
|
|||
.stdout_only("bc:defg\n");
|
||||
}
|
||||
|
||||
#[ignore = "Not yet implemented"]
|
||||
#[test]
|
||||
fn test_output_delimiter_with_adjacent_ranges() {
|
||||
new_ucmd!()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue