Skip to content

Commit

Permalink
Remove invalid substr bound for matches
Browse files Browse the repository at this point in the history
  • Loading branch information
l4l committed Jan 10, 2021
1 parent 3d7a54f commit 62c4aff
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/draw/list_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,16 @@ where
let match_ranges = item.match_mask.unwrap_or(&empty);

fn substr<'a, 'b: 'a>(x: &'b str, r: &Range<usize>) -> &'a str {
let chars_count = x.chars().count();
let start = x
.char_indices()
.nth(r.start)
.map(|x| x.0)
.unwrap_or_else(|| x.len())
.min(chars_count);
.unwrap_or_else(|| x.len());
let end = x
.char_indices()
.nth(r.end - 1)
.map(|l| l.0 + l.1.len_utf8())
.unwrap_or_else(|| x.len())
.min(chars_count);
.unwrap_or_else(|| x.len());
&x[start..end]
}

Expand Down

0 comments on commit 62c4aff

Please sign in to comment.