pub struct Stream<'a> { /* private fields */ }
Expand description
A streaming text parsing interface.
Implementations§
Source§impl<'a> Stream<'a>
impl<'a> Stream<'a>
Sourcepub fn calc_char_pos(&self) -> usize
pub fn calc_char_pos(&self) -> usize
Calculates the current position in chars.
Sourcepub fn calc_char_pos_at(&self, byte_pos: usize) -> usize
pub fn calc_char_pos_at(&self, byte_pos: usize) -> usize
Calculates the current position in chars.
Sourcepub fn jump_to_end(&mut self)
pub fn jump_to_end(&mut self)
Sets current position equal to the end.
Used to indicate end of parsing on error.
Sourcepub fn at_end(&self) -> bool
pub fn at_end(&self) -> bool
Checks if the stream is reached the end.
Any pos()
value larger than original text length indicates stream end.
Accessing stream after reaching end via safe methods will produce
an UnexpectedEndOfStream
error.
Accessing stream after reaching end via *_unchecked methods will produce a Rust’s bound checking error.
Sourcepub fn curr_byte_unchecked(&self) -> u8
pub fn curr_byte_unchecked(&self) -> u8
Returns a byte from a current stream position.
§Panics
- if the current position is after the end of the data
Sourcepub fn is_curr_byte_eq(&self, c: u8) -> bool
pub fn is_curr_byte_eq(&self, c: u8) -> bool
Checks that current byte is equal to provided.
Returns false
if no bytes left.
Sourcepub fn get_curr_byte(&self) -> Option<u8>
pub fn get_curr_byte(&self) -> Option<u8>
Returns a byte from a current stream position if there is one.
Sourcepub fn skip_spaces(&mut self)
pub fn skip_spaces(&mut self)
Skips whitespaces.
Accepted values: ' ' \n \r \t
.
Sourcepub fn starts_with(&self, text: &[u8]) -> bool
pub fn starts_with(&self, text: &[u8]) -> bool
Checks that the stream starts with a selected text.
We are using &[u8]
instead of &str
for performance reasons.
Sourcepub fn starts_with_space(&self) -> bool
pub fn starts_with_space(&self) -> bool
Checks if the stream is starts with a space.
Uses skip_spaces()
internally.
Sourcepub fn consume_bytes<F>(&mut self, f: F) -> &'a str
pub fn consume_bytes<F>(&mut self, f: F) -> &'a str
Consumes bytes by the predicate and returns them.
The result can be empty.
Sourcepub fn skip_bytes<F>(&mut self, f: F)
pub fn skip_bytes<F>(&mut self, f: F)
Consumes bytes by the predicate.
Sourcepub fn consume_ident(&mut self) -> &'a str
pub fn consume_ident(&mut self) -> &'a str
Consumes bytes by the predicate and returns them.
Sourcepub fn slice_back(&self, pos: usize) -> &'a str
pub fn slice_back(&self, pos: usize) -> &'a str
Slices data from pos
to the current position.
Sourcepub fn slice_tail(&self) -> &'a str
pub fn slice_tail(&self) -> &'a str
Slices data from the current position to the end.
Sourcepub fn parse_number(&mut self) -> Result<f64, Error>
pub fn parse_number(&mut self) -> Result<f64, Error>
Parses number from the stream.
This method will detect a number length and then
will pass a substring to the f64::from_str
method.
https://www.w3.org/TR/SVG11/types.html#DataTypeNumber
§Errors
Returns only InvalidNumber
.
Sourcepub fn parse_list_number(&mut self) -> Result<f64, Error>
pub fn parse_list_number(&mut self) -> Result<f64, Error>
Parses number from the list of numbers.
§Examples
Sourcepub fn parse_integer(&mut self) -> Result<i32, Error>
pub fn parse_integer(&mut self) -> Result<i32, Error>
Parses integer number from the stream.
Same as parse_number()
, but only for integer. Does not refer to any SVG type.
Sourcepub fn parse_list_integer(&mut self) -> Result<i32, Error>
pub fn parse_list_integer(&mut self) -> Result<i32, Error>
Parses integer from the list of numbers.
Sourcepub fn parse_length(&mut self) -> Result<Length, Error>
pub fn parse_length(&mut self) -> Result<Length, Error>
Parses length from the stream.
https://www.w3.org/TR/SVG11/types.html#DataTypeLength
§Examples
§Notes
- Suffix must be lowercase, otherwise it will be an error.
Sourcepub fn parse_list_length(&mut self) -> Result<Length, Error>
pub fn parse_list_length(&mut self) -> Result<Length, Error>
Parses length from the list of lengths.
Sourcepub fn parse_angle(&mut self) -> Result<Angle, Error>
pub fn parse_angle(&mut self) -> Result<Angle, Error>
Parses angle from the stream.
https://www.w3.org/TR/SVG11/types.html#DataTypeAngle
§Notes
- Suffix must be lowercase, otherwise it will be an error.
Sourcepub fn skip_digits(&mut self)
pub fn skip_digits(&mut self)
Skips digits.