pub struct Parser<'input> { /* private fields */ }Expand description
A parser containing state for the active parsing of an SVG value
Implementations§
Source§impl<'input> Parser<'input>
impl<'input> Parser<'input>
Sourcepub fn try_parse<T, E, F: FnOnce(&mut Self) -> Result<T, E>>(
&mut self,
f: F,
) -> Result<T, E>
pub fn try_parse<T, E, F: FnOnce(&mut Self) -> Result<T, E>>( &mut self, f: F, ) -> Result<T, E>
Try parsing a portion of the input, reverting to the original state if failed
§Errors
If the attempted parsing fails
Sourcepub fn take_slice(&mut self) -> &'input str
pub fn take_slice(&mut self) -> &'input str
Get remaining slice of input and advance to the end of the input
Sourcepub fn slice_from(&self, start: usize) -> &'input str
pub fn slice_from(&self, start: usize) -> &'input str
Get slice from start position to current position
Sourcepub fn take_matches<F: FnMut(char) -> bool>(&mut self, f: F) -> &'input str
pub fn take_matches<F: FnMut(char) -> bool>(&mut self, f: F) -> &'input str
Move the cursor forward while the characters match the given predicate
Returns the skipped content as a slice
Sourcepub fn skip_matches<F: FnMut(char) -> bool>(&mut self, pat: F)
pub fn skip_matches<F: FnMut(char) -> bool>(&mut self, pat: F)
Moves the cursor forward the number of matching characters
Sourcepub fn skip_char(&mut self, char: char)
pub fn skip_char(&mut self, char: char)
Moves the cursor forward the number of matching characters
Sourcepub fn skip_whitespace(&mut self)
pub fn skip_whitespace(&mut self)
Moves the cursor forward the number of whitespace characters
Sourcepub fn expect_done(&self) -> Result<(), Error<'input>>
pub fn expect_done(&self) -> Result<(), Error<'input>>
Sourcepub fn expect_char(&mut self, expected: char) -> Result<(), Error<'input>>
pub fn expect_char(&mut self, expected: char) -> Result<(), Error<'input>>
Read and assert the next character matches the expected character
§Errors
If the end of the input is reached, or the character does not match
Sourcepub fn expect_matches<F: Fn(char) -> Result<bool, &'static str>>(
&mut self,
expected: &'static str,
f: F,
) -> Result<&'input str, Error<'input>>
pub fn expect_matches<F: Fn(char) -> Result<bool, &'static str>>( &mut self, expected: &'static str, f: F, ) -> Result<&'input str, Error<'input>>
Read and assert a set of characters matches the expected pattern.
§Errors
- If the end of the input is reached
- If none of the characters match the expected pattern
- If the patterns matcher asserts an error
Sourcepub fn expect_whitespace(&mut self) -> Result<(), Error<'input>>
pub fn expect_whitespace(&mut self) -> Result<(), Error<'input>>
Read and assert a set of characters is whitespace
§Errors
If none of the next characters are whitespace
Sourcepub fn expect_str(
&mut self,
expected: &'static str,
) -> Result<(), Error<'input>>
pub fn expect_str( &mut self, expected: &'static str, ) -> Result<(), Error<'input>>
Read and assert a set of characters matches the given string
§Errors
If the next set of characters does not match the given string