diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index 7e4991179..2645a2dee 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -290,7 +290,10 @@ fn cut_fields_whitespace( return Ok(true); } - + // The logic is identical to `cut_fields_delimiter` function above, which uses + // `Searcher` that iterates over and returns the first position of the delimiter character. + // The main difference is that `WhitespaceSearcher` returns a pair of the first and last + // delimiter character positions, since each delimiter sequence length can vary. for &Range { low, high } in ranges { if low - fields_pos > 0 { low_idx = match delim_search.nth(low - fields_pos - 1) { diff --git a/src/uu/cut/src/whitespace_searcher.rs b/src/uu/cut/src/whitespace_searcher.rs index e35b03bca..b17910c7a 100644 --- a/src/uu/cut/src/whitespace_searcher.rs +++ b/src/uu/cut/src/whitespace_searcher.rs @@ -24,6 +24,9 @@ impl<'a> WhitespaceSearcher<'a> { 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` fn next(&mut self) -> Option { if let Some(match_idx) = memchr2(b' ', b'\t', self.haystack) { let mut skip = match_idx + 1;