|
|
|
@ -17,40 +17,6 @@ impl<F: Fn(&char) -> bool> CharMatcher for F {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn find_nth_next_tag(
|
|
|
|
|
text: RopeSlice,
|
|
|
|
|
tag: &str,
|
|
|
|
|
mut pos: usize,
|
|
|
|
|
n: usize,
|
|
|
|
|
) -> Option<Vec<usize>> {
|
|
|
|
|
if pos >= text.len_chars() || n == 0 {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut chars = text.chars_at(pos);
|
|
|
|
|
|
|
|
|
|
let tag = format!("</{tag}>");
|
|
|
|
|
let len = tag.len();
|
|
|
|
|
|
|
|
|
|
for _ in 0..n {
|
|
|
|
|
loop {
|
|
|
|
|
let c = chars.next()?;
|
|
|
|
|
let cloned_chars = chars.clone();
|
|
|
|
|
let stri: String = cloned_chars.take(len).collect();
|
|
|
|
|
|
|
|
|
|
pos += 1;
|
|
|
|
|
|
|
|
|
|
if stri == tag {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let range: Vec<usize> = (pos - 1..pos + len - 1).collect();
|
|
|
|
|
|
|
|
|
|
Some(range)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn find_nth_next<M: CharMatcher>(
|
|
|
|
|
text: RopeSlice,
|
|
|
|
|
char_matcher: M,
|
|
|
|
|