Struct xmlparser::Stream [−][src]
pub struct Stream<'a> { /* fields omitted */ }Expand description
A streaming XML parsing interface.
Implementations
Creates a new stream from a specified text substring.
Sets current position equal to the end.
Used to indicate end of parsing on error.
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.
Returns a byte from a current stream position.
Panics
- if the current position is after the end of the data
Advances by n bytes.
Examples
use xmlparser::Stream; let mut s = Stream::from("text"); s.advance(2); // ok s.advance(20); // will cause a panic via debug_assert!().
Checks that the stream starts with a selected text.
We are using &[u8] instead of &str for performance reasons.
Examples
use xmlparser::Stream; let mut s = Stream::from("Some text."); s.advance(5); assert_eq!(s.starts_with(b"text"), true); assert_eq!(s.starts_with(b"long"), false);
Consumes the current byte if it’s equal to the provided byte.
Errors
InvalidCharUnexpectedEndOfStream
Examples
use xmlparser::Stream; let mut s = Stream::from("Some text."); assert!(s.consume_byte(b'S').is_ok()); assert!(s.consume_byte(b'o').is_ok()); assert!(s.consume_byte(b'm').is_ok()); assert!(s.consume_byte(b'q').is_err());
Tries to consume the current byte if it’s equal to the provided byte.
Unlike consume_byte() will not return any errors.
Consumes bytes by the predicate and returns them.
The result can be empty.
Skips bytes by the predicate.
pub fn consume_chars<F>(&mut self, f: F) -> Result<StrSpan<'a>, StreamError> where
F: Fn(&Stream<'_>, char) -> bool,
pub fn consume_chars<F>(&mut self, f: F) -> Result<StrSpan<'a>, StreamError> where
F: Fn(&Stream<'_>, char) -> bool, Consumes chars by the predicate and returns them.
The result can be empty.
pub fn skip_chars<F>(&mut self, f: F) -> Result<(), StreamError> where
F: Fn(&Stream<'_>, char) -> bool,
pub fn skip_chars<F>(&mut self, f: F) -> Result<(), StreamError> where
F: Fn(&Stream<'_>, char) -> bool, Skips chars by the predicate.
Slices data from pos to the current position.
Slices data from the current position to the end.
Skips whitespaces.
Accepted values: ' ' \n \r \t.
Checks if the stream is starts with a space.
Consumes whitespaces.
Like skip_spaces(), but checks that first char is actually a space.
Errors
InvalidSpace
Consumes an XML character reference if there is one.
On error will reset the position to the original.
See consume_reference() for details.
Consumes an XML reference.
Consumes according to: https://www.w3.org/TR/xml/#NT-Reference
Errors
InvalidReference
Examples
Escaped character:
use xmlparser::{Stream, Reference}; let mut stream = Stream::from("ณ"); assert_eq!(stream.consume_reference().unwrap(), Reference::Char('\u{e13}'));
Predefined references will not be expanded. Details.
use xmlparser::{Stream, Reference}; let mut stream = Stream::from("≤"); assert_eq!(stream.consume_reference().unwrap(), Reference::Entity("le"));
Named reference:
use xmlparser::{Stream, Reference}; let mut stream = Stream::from("&other;"); assert_eq!(stream.consume_reference().unwrap(), Reference::Entity("other"));
Consumes an XML name and returns it.
Consumes according to: https://www.w3.org/TR/xml/#NT-Name
Errors
InvalidName- if name is empty or starts with an invalid charUnexpectedEndOfStream
Skips an XML name.
The same as consume_name(), but does not return a consumed name.
Errors
InvalidName- if name is empty or starts with an invalid char
Consumes a qualified XML name and returns it.
Consumes according to: https://www.w3.org/TR/xml-names/#ns-qualnames
Errors
InvalidName- if name is empty or starts with an invalid char
Consumes =.
Consumes according to: https://www.w3.org/TR/xml/#NT-Eq
Errors
InvalidCharUnexpectedEndOfStream
Calculates a current absolute position.
This operation is very expensive. Use only for errors.
Calculates an absolute position at pos.
This operation is very expensive. Use only for errors.
Examples
let s = xmlparser::Stream::from("text"); assert_eq!(s.gen_text_pos_from(2), xmlparser::TextPos::new(1, 3)); assert_eq!(s.gen_text_pos_from(9999), xmlparser::TextPos::new(1, 5));
Trait Implementations
Auto Trait Implementations
impl<'a> RefUnwindSafe for Stream<'a>impl<'a> UnwindSafe for Stream<'a>Blanket Implementations
Mutably borrows from an owned value. Read more