helix-mods/helix-core/src/search.rs
Nathan Vegdahl f96b8b769b Switch to a cleaner range-head moving abstraction.
Also fix a bunch of bugs related to it.
2021-07-24 07:44:11 -07:00

45 lines
801 B
Rust

use crate::RopeSlice;
pub fn find_nth_next(text: RopeSlice, ch: char, mut pos: usize, n: usize) -> Option<usize> {
if pos >= text.len_chars() || n == 0 {
return None;
}
let mut chars = text.chars_at(pos);
for _ in 0..n {
loop {
let c = chars.next()?;
pos += 1;
if c == ch {
break;
}
}
}
Some(pos - 1)
}
pub fn find_nth_prev(text: RopeSlice, ch: char, mut pos: usize, n: usize) -> Option<usize> {
if pos == 0 || n == 0 {
return None;
}
let mut chars = text.chars_at(pos);
for _ in 0..n {
loop {
let c = chars.prev()?;
pos -= 1;
if c == ch {
break;
}
}
}
Some(pos)
}