pub struct Scanner<'a> { /* private fields */ }Expand description
A string scanner.
Implementations§
Source§impl<'a> Scanner<'a>
impl<'a> Scanner<'a>
Sourcepub fn new(string: &'a str) -> Self
pub fn new(string: &'a str) -> Self
Create a new string scanner, starting with a cursor position of 0.
Sourcepub fn from(&self, start: usize) -> &'a str
pub fn from(&self, start: usize) -> &'a str
The subslice from start to the cursor.
Snaps start into the bounds of the string and to the next character
boundary.
Sourcepub fn to(&self, end: usize) -> &'a str
pub fn to(&self, end: usize) -> &'a str
The subslice from the cursor to end.
Snaps end into the bounds of the string and to the next character
boundary.
Sourcepub fn get(&self, range: Range<usize>) -> &'a str
pub fn get(&self, range: Range<usize>) -> &'a str
The subslice from the start to end.
Snaps start and end into the bounds of the string and to the next character
boundary.
Sourcepub fn at<T>(&self, pat: impl Pattern<T>) -> bool
pub fn at<T>(&self, pat: impl Pattern<T>) -> bool
Whether the part right behind the cursor starts with the given pattern.
Sourcepub fn scout(&self, n: isize) -> Option<char>
pub fn scout(&self, n: isize) -> Option<char>
Look at the n-th character relative to the cursor without changing the cursor.
scout(-1)is the character before the cursor.scout(0)is the same aspeek().
Runs in O(|n|).
Sourcepub fn locate(&self, n: isize) -> usize
pub fn locate(&self, n: isize) -> usize
The byte index of the n-th character relative to the cursor.
locate(-1)is the byte position of the character before the cursor.locate(0)is the same ascursor().
Runs in O(|n|).
Sourcepub fn eat(&mut self) -> Option<char>
pub fn eat(&mut self) -> Option<char>
Consume and return the character right behind the cursor.
Sourcepub fn uneat(&mut self) -> Option<char>
pub fn uneat(&mut self) -> Option<char>
Consume and return the character right before the cursor, moving it back.
Sourcepub fn eat_if<T>(&mut self, pat: impl Pattern<T>) -> bool
pub fn eat_if<T>(&mut self, pat: impl Pattern<T>) -> bool
Consume the given pattern if that’s what’s right behind the cursor.
Returns true if the pattern was consumed.
Sourcepub fn eat_while<T>(&mut self, pat: impl Pattern<T>) -> &'a str
pub fn eat_while<T>(&mut self, pat: impl Pattern<T>) -> &'a str
Consume while the given pattern is what’s right behind the cursor.
Returns the consumed substring.
Sourcepub fn eat_until<T>(&mut self, pat: impl Pattern<T>) -> &'a str
pub fn eat_until<T>(&mut self, pat: impl Pattern<T>) -> &'a str
Consume until the given pattern is what’s right behind the cursor.
Returns the consumed substring.
Sourcepub fn eat_whitespace(&mut self) -> &'a str
pub fn eat_whitespace(&mut self) -> &'a str
Consume all whitespace until the next non-whitespace character.
Returns the consumed whitespace.