use strop_core::Buffer;
pub fn search_backward(buf: &Buffer, from: usize, pat: &str) -> Option<usize> {
let from = from.min(buf.len_bytes());
if from == 0 {
return None;
}
let text = buf.rope.byte_slice(..from).to_string();
text.rfind(pat)
}
pub fn search_forward(buf: &Buffer, from: usize, pat: &str) -> Option<usize> {
let text = buf.rope.byte_slice(from.min(buf.len_bytes())..).to_string();
text.find(pat).map(|i| from + i)
}
pub fn search_all(buf: &Buffer, pat: &str) -> Vec<usize> {
if pat.is_empty() {
return vec![];
}
let text = buf.rope.to_string();
text.match_indices(pat).map(|(i, _)| i).collect()
}