mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-29 09:23:46 +00:00
Introduce State::advance_mut and State::consume_mut to simplify things
This commit is contained in:
parent
7a594901dd
commit
a1512dfd79
2 changed files with 36 additions and 29 deletions
|
@ -37,6 +37,25 @@ impl<'a> State<'a> {
|
|||
self.pos().offset - self.line_start.offset
|
||||
}
|
||||
|
||||
/// Mutably advance the state by a given offset
|
||||
#[inline(always)]
|
||||
pub(crate) fn advance_mut(&mut self, offset: usize) {
|
||||
self.offset += offset;
|
||||
}
|
||||
|
||||
/// If the next `text.len()` bytes of the input match the provided `text`,
|
||||
/// mutably advance the state by that much.
|
||||
#[inline(always)]
|
||||
pub(crate) fn consume_mut(&mut self, text: &str) -> bool {
|
||||
let found = self.bytes().starts_with(text.as_bytes());
|
||||
|
||||
if found {
|
||||
self.advance_mut(text.len());
|
||||
}
|
||||
|
||||
found
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
#[inline(always)]
|
||||
pub(crate) const fn advance(mut self, offset: usize) -> State<'a> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue