Skip to content

The size_hint() of SentenceBreaks, UWordBounds and Graphemes iterators return an incorrect number of minimum of elements. #146

Closed
@slatian

Description

@slatian

fn size_hint(&self) -> (usize, Option<usize>) {
let slen = self.string.len();
// A sentence could be one character
(cmp::min(slen, 2), Some(slen + 1))
}

According to the Iterator documentation on size_hint

returns a tuple where the first element is the lower bound, and the second element is the upper bound.

… and …

A buggy iterator may yield less than the lower bound or more than the upper bound of elements.

This however returns what is almost the upper bound of the iterator as the lower one.

A quickfix would be changing the return statement to:

(2, Some(slen + 1)) 

Same problem for the word iterator:

fn size_hint(&self) -> (usize, Option<usize>) {
let slen = self.string.len();
(cmp::min(slen, 1), Some(slen))
}

Similar problem in the grapheme iterators:

fn size_hint(&self) -> (usize, Option<usize>) {
let slen = self.cursor_back.cur_cursor() - self.cursor.cur_cursor();
(cmp::min(slen, 1), Some(slen))
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions