pub struct Cursor<'a> { /* private fields */ }Expand description
A Cursor over a string.
Based on rustc’s Cursor
Implementations§
Source§impl<'a> Cursor<'a>
impl<'a> Cursor<'a>
pub fn new(source: &'a str) -> Self
Sourcepub fn offset(&self) -> TextSize
pub fn offset(&self) -> TextSize
Retrieves the current offset of the cursor within the source code.
Sourcepub fn first(&self) -> char
pub fn first(&self) -> char
Peeks the next character from the input stream without consuming it.
Returns EOF_CHAR if the file is at the end of the file.
Sourcepub fn second(&self) -> char
pub fn second(&self) -> char
Peeks the second character from the input stream without consuming it.
Returns EOF_CHAR if the position is past the end of the file.
Sourcepub fn last(&self) -> char
pub fn last(&self) -> char
Peeks the next character from the input stream without consuming it.
Returns EOF_CHAR if the file is at the end of the file.
pub fn text_len(&self) -> TextSize
pub fn token_len(&self) -> TextSize
pub fn start_token(&mut self)
pub fn eat_char(&mut self, c: char) -> bool
Sourcepub fn eat_char2(&mut self, c1: char, c2: char) -> bool
pub fn eat_char2(&mut self, c1: char, c2: char) -> bool
Eats the next two characters if they are c1 and c2. Does not
consume any input otherwise, even if the first character matches.
Sourcepub fn eat_char3(&mut self, c1: char, c2: char, c3: char) -> bool
pub fn eat_char3(&mut self, c1: char, c2: char, c3: char) -> bool
Eats the next three characters if they are c1, c2 and c3
Does not consume any input otherwise, even if the first character matches.
pub fn eat_char_back(&mut self, c: char) -> bool
Sourcepub fn eat_if(&mut self, predicate: impl FnMut(char) -> bool) -> bool
pub fn eat_if(&mut self, predicate: impl FnMut(char) -> bool) -> bool
Eats the next character if predicate returns true.
Sourcepub fn eat_while(&mut self, predicate: impl FnMut(char) -> bool)
pub fn eat_while(&mut self, predicate: impl FnMut(char) -> bool)
Eats symbols while predicate returns true or until the end of file is reached.
Sourcepub fn eat_back_while(&mut self, predicate: impl FnMut(char) -> bool)
pub fn eat_back_while(&mut self, predicate: impl FnMut(char) -> bool)
Eats symbols from the back while predicate returns true or until the beginning of file is reached.
Sourcepub fn skip_bytes(&mut self, count: usize)
pub fn skip_bytes(&mut self, count: usize)
Skips the next count bytes.
§Panics
- If
countis larger than the remaining bytes in the input stream. - If
countindexes into a multi-byte character.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Cursor<'a>
impl<'a> RefUnwindSafe for Cursor<'a>
impl<'a> Send for Cursor<'a>
impl<'a> Sync for Cursor<'a>
impl<'a> Unpin for Cursor<'a>
impl<'a> UnsafeUnpin for Cursor<'a>
impl<'a> UnwindSafe for Cursor<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more