mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
add more comments
This commit is contained in:
parent
76f818da05
commit
4e2cfdb8ce
2 changed files with 8 additions and 2 deletions
|
@ -296,13 +296,17 @@ fn cut_fields_whitespace<R: Read>(
|
|||
// delimiter character positions, since each delimiter sequence length can vary.
|
||||
for &Range { low, high } in ranges {
|
||||
if low - fields_pos > 0 {
|
||||
// current field is not in the range, so jump to the field corresponding to the
|
||||
// beginning of the range if any
|
||||
low_idx = match delim_search.nth(low - fields_pos - 1) {
|
||||
Some((_, last)) => last,
|
||||
None => break,
|
||||
};
|
||||
}
|
||||
|
||||
// at this point, current field is the first in the range
|
||||
for _ in 0..=high - low {
|
||||
// skip printing delimiter if this is the first matching field for this line
|
||||
if print_delim {
|
||||
out.write_all(out_delim.as_bytes())?;
|
||||
} else {
|
||||
|
@ -310,6 +314,7 @@ fn cut_fields_whitespace<R: Read>(
|
|||
}
|
||||
|
||||
match delim_search.next() {
|
||||
// print the current field up to the next whitespace
|
||||
Some((first, last)) => {
|
||||
let segment = &line[low_idx..first];
|
||||
|
||||
|
@ -319,6 +324,7 @@ fn cut_fields_whitespace<R: Read>(
|
|||
fields_pos = high + 1;
|
||||
}
|
||||
None => {
|
||||
// this is the last field in the line, so print the rest
|
||||
let segment = &line[low_idx..];
|
||||
|
||||
out.write_all(segment)?;
|
||||
|
|
|
@ -25,8 +25,8 @@ impl<'a> Iterator for WhitespaceSearcher<'a> {
|
|||
type Item = (usize, usize);
|
||||
|
||||
// Iterate over sequences of consecutive whitespace (space and/or tab) characters.
|
||||
// Returns (first, last) positions of each sequence, where `first` is inclusive and `last` is exclusive.
|
||||
// The delimiter sequence byte-length is equal to `last - first`
|
||||
// Returns (first, last) positions of each sequence, where `haystack[first..last]`
|
||||
// corresponds to the delimiter.
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if let Some(match_idx) = memchr2(b' ', b'\t', self.haystack) {
|
||||
let mut skip = match_idx + 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue