unicode-rs / unicode-segmentation

Grapheme Cluster and Word boundaries according to UAX#29 rules
https://unicode-rs.github.io/unicode-segmentation
Other
571 stars 56 forks source link

`next_boundary()` panics when cursor is at the end of the given chunk #135

Open truchi opened 5 months ago

truchi commented 5 months ago

Hello,

In prev_boundary we have this check (for the following unwrap not to panic):

if self.offset == chunk_start {
    return Err(GraphemeIncomplete::PrevChunk);
}

I suggest this in next_boundary() (for the same reason):

if self.offset == chunk_start + chunk.len() {
    return Err(GraphemeIncomplete::NextChunk);
}

Thank you!