1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-15 03:26:18 +00:00

add comments on the function logic

This commit is contained in:
TechHara 2022-12-13 20:57:46 -05:00
parent 9798ae7987
commit 27dfe63f4c
2 changed files with 7 additions and 1 deletions

View file

@ -290,7 +290,10 @@ fn cut_fields_whitespace<R: Read>(
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) {

View file

@ -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<Self::Item> {
if let Some(match_idx) = memchr2(b' ', b'\t', self.haystack) {
let mut skip = match_idx + 1;