pub struct SourceCursor<'s, S: Source + ?Sized> { /* private fields */ }Expand description
A cursor over a source that allows for efficient navigation and scanning.
Implementations§
Source§impl<'s, S: Source + ?Sized> SourceCursor<'s, S>
impl<'s, S: Source + ?Sized> SourceCursor<'s, S>
Sourcepub fn new_at(source: &'s S, offset: usize) -> Self
pub fn new_at(source: &'s S, offset: usize) -> Self
Creates a new SourceCursor at the specified offset.
Sourcepub fn set_position(&mut self, offset: usize) -> usize
pub fn set_position(&mut self, offset: usize) -> usize
Sets the current byte offset of the cursor. Returns the previous offset.
Sourcepub fn peek_char(&mut self) -> Option<char>
pub fn peek_char(&mut self) -> Option<char>
Peeks at the next character without advancing the cursor.
Sourcepub fn skip_ascii_whitespace(&mut self) -> Range<usize>
pub fn skip_ascii_whitespace(&mut self) -> Range<usize>
Skips common ASCII whitespace using SIMD if possible.
Sourcepub fn skip_ascii_digits(&mut self) -> Range<usize>
pub fn skip_ascii_digits(&mut self) -> Range<usize>
Skips ASCII digits using SIMD if possible.
Sourcepub fn skip_ascii_ident_continue(&mut self) -> Range<usize>
pub fn skip_ascii_ident_continue(&mut self) -> Range<usize>
Skips ASCII identifier continue characters using SIMD if possible.
Sourcepub fn skip_until(&mut self, target: u8) -> Range<usize>
pub fn skip_until(&mut self, target: u8) -> Range<usize>
Skips until the specified byte is found.
Sourcepub fn peek_byte(&mut self) -> Option<u8>
pub fn peek_byte(&mut self) -> Option<u8>
Peeks at the next byte without advancing. the cursor.
Sourcepub fn advance_bytes(&mut self, len: usize) -> usize
pub fn advance_bytes(&mut self, len: usize) -> usize
Advances the cursor by the specified number of bytes.
Sourcepub fn advance_char(&mut self) -> Option<char>
pub fn advance_char(&mut self) -> Option<char>
Advances the cursor by one character and returns it.
Sourcepub fn advance_byte(&mut self) -> Option<u8>
pub fn advance_byte(&mut self) -> Option<u8>
Advances the cursor by one byte and returns it.
Sourcepub fn take_while(&mut self, pred: impl FnMut(char) -> bool) -> Range<usize>
pub fn take_while(&mut self, pred: impl FnMut(char) -> bool) -> Range<usize>
Advances the cursor while the predicate is true and returns the range.
Sourcepub fn take_while_byte(&mut self, pred: impl FnMut(u8) -> bool) -> Range<usize>
pub fn take_while_byte(&mut self, pred: impl FnMut(u8) -> bool) -> Range<usize>
Advances the cursor while the byte predicate is true and returns the range.
Sourcepub fn starts_with(&mut self, pattern: &str) -> bool
pub fn starts_with(&mut self, pattern: &str) -> bool
Returns true if the source text at the current position starts with the given pattern.
Sourcepub fn consume_if_starts_with(&mut self, pattern: &str) -> bool
pub fn consume_if_starts_with(&mut self, pattern: &str) -> bool
Consumes the given pattern if it matches at the current position.