mirror of
https://github.com/RGBCube/cstree
synced 2025-08-01 11:37:46 +00:00
text: add SyntaxText::rfind_char
This commit is contained in:
parent
a8ebf29808
commit
c35e88c3da
1 changed files with 12 additions and 0 deletions
|
@ -91,6 +91,18 @@ impl<'n, 'i, I: Resolver<TokenKey> + ?Sized, S: Syntax, D> SyntaxText<'n, 'i, I,
|
|||
found(res)
|
||||
}
|
||||
|
||||
/// If `self.contains_char(c)`, returns `Some(pos)`, where `pos` is the byte position of the
|
||||
/// last appearance of `c`. Otherwise, returns `None`.
|
||||
pub fn rfind_char(&self, c: char) -> Option<TextSize> {
|
||||
let mut acc: TextSize = 0.into();
|
||||
let mut res = None;
|
||||
self.for_each_chunk(|chunk| {
|
||||
res = chunk.rfind(c).map(|pos| acc + TextSize::from(pos as u32)).or(res);
|
||||
acc += TextSize::of(chunk);
|
||||
});
|
||||
res
|
||||
}
|
||||
|
||||
/// If `offset < self.len()`, returns `Some(c)`, where `c` is the first `char` at or after
|
||||
/// `offset` (in bytes). Otherwise, returns `None`.
|
||||
pub fn char_at(&self, offset: TextSize) -> Option<char> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue