mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-15 11:36:16 +00:00
add comments on the function logic
This commit is contained in:
parent
9798ae7987
commit
27dfe63f4c
2 changed files with 7 additions and 1 deletions
|
@ -290,7 +290,10 @@ fn cut_fields_whitespace<R: Read>(
|
||||||
|
|
||||||
return Ok(true);
|
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 {
|
for &Range { low, high } in ranges {
|
||||||
if low - fields_pos > 0 {
|
if low - fields_pos > 0 {
|
||||||
low_idx = match delim_search.nth(low - fields_pos - 1) {
|
low_idx = match delim_search.nth(low - fields_pos - 1) {
|
||||||
|
|
|
@ -24,6 +24,9 @@ impl<'a> WhitespaceSearcher<'a> {
|
||||||
impl<'a> Iterator for WhitespaceSearcher<'a> {
|
impl<'a> Iterator for WhitespaceSearcher<'a> {
|
||||||
type Item = (usize, usize);
|
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> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
if let Some(match_idx) = memchr2(b' ', b'\t', self.haystack) {
|
if let Some(match_idx) = memchr2(b' ', b'\t', self.haystack) {
|
||||||
let mut skip = match_idx + 1;
|
let mut skip = match_idx + 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue