Skip to content

Commit

Permalink
Fix unwrap panic in next_boundary() (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
cardigan1008 committed Jul 29, 2024
1 parent 0fa7148 commit 0f55f70
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/grapheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,11 @@ impl GraphemeCursor {
if self.offset == self.len {
return Ok(None);
}
let mut iter = chunk[self.offset - chunk_start..].chars();
let mut ch = iter.next().unwrap();
let mut iter = chunk[self.offset.saturating_sub(chunk_start)..].chars();
let mut ch = match iter.next() {
Some(ch) => ch,
None => return Err(GraphemeIncomplete::NextChunk),
};
loop {
if self.resuming {
if self.cat_after.is_none() {
Expand Down

0 comments on commit 0f55f70

Please sign in to comment.