pub struct Stream<'a> {
text: &'a str,
pos: usize,
}
Expand description
A streaming text parsing interface.
Fields§
§text: &'a str
§pos: usize
Implementations§
Source§impl Stream<'_>
impl Stream<'_>
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/SVG2/types.html#InterfaceSVGAngle
§Notes
- Suffix must be lowercase, otherwise it will be an error.
Source§impl Stream<'_>
impl Stream<'_>
Sourcepub fn try_parse_color(&mut self) -> Option<Color>
pub fn try_parse_color(&mut self) -> Option<Color>
Tries to parse a color, but doesn’t advance on error.
Sourcepub fn parse_color(&mut self) -> Result<Color, Error>
pub fn parse_color(&mut self) -> Result<Color, Error>
Parses a color.
Source§impl Stream<'_>
impl Stream<'_>
Sourcepub fn parse_directional_position(
&mut self,
) -> Result<DirectionalPosition, Error>
pub fn parse_directional_position( &mut self, ) -> Result<DirectionalPosition, Error>
Parses a directional position [left
, center
, right
, bottom
, top
] from the stream.
Source§impl Stream<'_>
impl Stream<'_>
pub fn parse_font_families(&mut self) -> Result<Vec<FontFamily>, Error>
Source§impl Stream<'_>
impl Stream<'_>
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/SVG2/types.html#InterfaceSVGLength
§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 a list of lengths.
Source§impl Stream<'_>
impl Stream<'_>
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/SVG2/types.html#InterfaceSVGNumber
§Errors
Returns only InvalidNumber
.
fn parse_number_impl(&mut self) -> Result<f64, Error>
Sourcepub fn parse_list_number(&mut self) -> Result<f64, Error>
pub fn parse_list_number(&mut self) -> Result<f64, Error>
Parses number from a list of numbers.
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.
pub fn chars(&self) -> Chars<'a>
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 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 parse_ident(&mut self) -> Result<&'a str, Error>
pub fn parse_ident(&mut self) -> Result<&'a str, Error>
Sourcepub fn consume_ascii_ident(&mut self) -> &'a str
pub fn consume_ascii_ident(&mut self) -> &'a str
Consumes a single ident consisting of ASCII characters, if available.
Sourcepub fn parse_quoted_string(&mut self) -> Result<&'a str, Error>
pub fn parse_quoted_string(&mut self) -> Result<&'a str, Error>
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 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_or_percent(&mut self) -> Result<f64, Error>
pub fn parse_number_or_percent(&mut self) -> Result<f64, Error>
Parses number or percent from the stream.
Percent value will be normalized.
Sourcepub fn parse_list_number_or_percent(&mut self) -> Result<f64, Error>
pub fn parse_list_number_or_percent(&mut self) -> Result<f64, Error>
Parses number or percent from a list of numbers and/or percents.
Sourcepub fn skip_digits(&mut self)
pub fn skip_digits(&mut self)
Skips digits.