mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
csplit: use assert! instead of if then panic!
This commit is contained in:
parent
71b7d6b57d
commit
06ae968ecf
1 changed files with 17 additions and 14 deletions
|
@ -320,18 +320,19 @@ impl<'a> SplitWriter<'a> {
|
||||||
let l = line?;
|
let l = line?;
|
||||||
match n.cmp(&(&ln + 1)) {
|
match n.cmp(&(&ln + 1)) {
|
||||||
Ordering::Less => {
|
Ordering::Less => {
|
||||||
if input_iter.add_line_to_buffer(ln, l).is_some() {
|
assert!(
|
||||||
panic!("the buffer is big enough to contain 1 line");
|
input_iter.add_line_to_buffer(ln, l).is_none(),
|
||||||
}
|
"the buffer is big enough to contain 1 line"
|
||||||
|
);
|
||||||
ret = Ok(());
|
ret = Ok(());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Ordering::Equal => {
|
Ordering::Equal => {
|
||||||
if !self.options.suppress_matched
|
assert!(
|
||||||
&& input_iter.add_line_to_buffer(ln, l).is_some()
|
self.options.suppress_matched
|
||||||
{
|
|| input_iter.add_line_to_buffer(ln, l).is_none(),
|
||||||
panic!("the buffer is big enough to contain 1 line");
|
"the buffer is big enough to contain 1 line"
|
||||||
}
|
);
|
||||||
ret = Ok(());
|
ret = Ok(());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -378,9 +379,10 @@ impl<'a> SplitWriter<'a> {
|
||||||
match (self.options.suppress_matched, offset) {
|
match (self.options.suppress_matched, offset) {
|
||||||
// no offset, add the line to the next split
|
// no offset, add the line to the next split
|
||||||
(false, 0) => {
|
(false, 0) => {
|
||||||
if input_iter.add_line_to_buffer(ln, l).is_some() {
|
assert!(
|
||||||
panic!("the buffer is big enough to contain 1 line");
|
input_iter.add_line_to_buffer(ln, l).is_none(),
|
||||||
}
|
"the buffer is big enough to contain 1 line"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// a positive offset, some more lines need to be added to the current split
|
// a positive offset, some more lines need to be added to the current split
|
||||||
(false, _) => self.writeln(l)?,
|
(false, _) => self.writeln(l)?,
|
||||||
|
@ -425,9 +427,10 @@ impl<'a> SplitWriter<'a> {
|
||||||
if !self.options.suppress_matched {
|
if !self.options.suppress_matched {
|
||||||
// add 1 to the buffer size to make place for the matched line
|
// add 1 to the buffer size to make place for the matched line
|
||||||
input_iter.set_size_of_buffer(offset_usize + 1);
|
input_iter.set_size_of_buffer(offset_usize + 1);
|
||||||
if input_iter.add_line_to_buffer(ln, l).is_some() {
|
assert!(
|
||||||
panic!("should be big enough to hold every lines");
|
input_iter.add_line_to_buffer(ln, l).is_none(),
|
||||||
}
|
"should be big enough to hold every lines"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
self.finish_split();
|
self.finish_split();
|
||||||
if input_iter.buffer_len() < offset_usize {
|
if input_iter.buffer_len() < offset_usize {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue