diff options
Diffstat (limited to 'src/launcher')
| -rw-r--r-- | src/launcher/strsub.rs | 16 |
1 files changed, 2 insertions, 14 deletions
diff --git a/src/launcher/strsub.rs b/src/launcher/strsub.rs index 447021a..a50555d 100644 --- a/src/launcher/strsub.rs +++ b/src/launcher/strsub.rs @@ -6,20 +6,8 @@ const VAR_BEGIN: &str = "${"; const VAR_END: &str = "}"; const VAR_DEFAULT: &str = ":-"; -fn prev_char(slice: &str, mut idx: usize) -> Option<(usize, char)> { - if idx == 0 || idx >= slice.len() { - return None; - } - - loop { - // will never panic because the condition always succeeds for idx == 0 - // (the precondition will handle cases where the slice is empty) - idx -= 1; - - if slice.is_char_boundary(idx) { - return Some((idx, slice[idx..].chars().next().unwrap())) - } - } +fn prev_char(slice: &str, idx: usize) -> Option<(usize, char)> { + slice[..idx].char_indices().rev().next() } // basically the same thing as replace_string, but it creates the String itself and returns it. |
