From d294fff882c7a38b6f129c054392edf981b8e9b4 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 19 Dec 2022 18:13:02 +1000 Subject: [PATCH] Simplify solution for #2279 --- rslib/src/cloze.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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; } }