diff --git a/rslib/src/cloze.rs b/rslib/src/cloze.rs index 2c0912a17..5027bc308 100644 --- a/rslib/src/cloze.rs +++ b/rslib/src/cloze.rs @@ -73,13 +73,12 @@ fn tokenize(mut text: &str) -> impl Iterator { nom::error::ErrorKind::Eof, ))); } - let mut index = 0; let mut other_token = alt((open_cloze, close_cloze)); - while other_token(&text[index..]).is_err() && index < text.len() { - if let Some(next_char) = text[index..].chars().next() { - // advance index by one scalar char - index += next_char.len_utf8(); - } else { + // start with the no-match case + let mut index = text.len(); + for (idx, _) in text.char_indices() { + if other_token(&text[idx..]).is_ok() { + index = idx; break; } }