Struct xmlparser::Stream [−][src]
pub struct Stream<'a> { /* fields omitted */ }A streaming text parsing interface.
Methods
impl<'a> Stream<'a>[src]
impl<'a> Stream<'a>pub fn span(&self) -> StrSpan<'a>[src]
pub fn span(&self) -> StrSpan<'a>Returns an underling string span.
pub fn pos(&self) -> usize[src]
pub fn pos(&self) -> usizeReturns current position.
pub fn jump_to_end(&mut self)[src]
pub fn jump_to_end(&mut self)Sets current position equal to the end.
Used to indicate end of parsing on error.
pub fn at_end(&self) -> bool[src]
pub fn at_end(&self) -> boolChecks 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 curr_byte(&self) -> Result<u8, StreamError>[src]
pub fn curr_byte(&self) -> Result<u8, StreamError>pub fn is_curr_byte_eq(&self, c: u8) -> bool[src]
pub fn is_curr_byte_eq(&self, c: u8) -> boolChecks that current byte is equal to provided.
Returns false if no bytes left.
pub fn get_curr_byte(&self) -> Option<u8>[src]
pub fn get_curr_byte(&self) -> Option<u8>Returns a byte from a current stream position if there is one.
pub fn next_byte(&self) -> Result<u8, StreamError>[src]
pub fn next_byte(&self) -> Result<u8, StreamError>pub fn curr_char(&self) -> Result<char, StreamError>[src]
pub fn curr_char(&self) -> Result<char, StreamError>pub fn advance(&mut self, n: usize)[src]
pub fn advance(&mut self, n: usize)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!().
pub fn skip_spaces(&mut self)[src]
pub fn skip_spaces(&mut self)Skips whitespaces.
Accepted values: ' ' \n \r \t   	 
 
.
Examples
use xmlparser::Stream; let mut s = Stream::from(" \t\n\r   "); s.skip_spaces(); assert_eq!(s.at_end(), true);
pub fn skip_ascii_spaces(&mut self)[src]
pub fn skip_ascii_spaces(&mut self)Skips ASCII whitespaces.
Accepted values: ' ' \n \r \t.
pub fn starts_with(&self, text: &[u8]) -> bool[src]
pub fn starts_with(&self, text: &[u8]) -> boolChecks 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);
pub fn starts_with_space(&self) -> bool[src]
pub fn starts_with_space(&self) -> boolChecks if the stream is starts with a space.
Uses skip_spaces() internally.
pub fn consume_spaces(&mut self) -> Result<(), StreamError>[src]
pub fn consume_spaces(&mut self) -> Result<(), StreamError>Consumes whitespaces.
Like skip_spaces(), but checks that first char is actually a space.
Errors
InvalidChar
pub fn consume_byte(&mut self, c: u8) -> Result<(), StreamError>[src]
pub fn consume_byte(&mut self, c: u8) -> Result<(), StreamError>Consumes current byte if it's equal to the provided byte.
Errors
InvalidCharUnexpectedEndOfStream
Examples
use xmlparser::Stream; let mut s = Stream::from("Some text."); s.consume_byte(b'S').unwrap(); s.consume_byte(b'o').unwrap(); s.consume_byte(b'm').unwrap(); // s.consume_byte(b'q').unwrap(); // will produce an error
pub fn consume_either(&mut self, list: &[u8]) -> Result<u8, StreamError>[src]
pub fn consume_either(&mut self, list: &[u8]) -> Result<u8, StreamError>Consumes current byte if it's equal to one of the provided bytes.
Returns a coincidental byte.
Errors
InvalidCharUnexpectedEndOfStream
pub fn skip_string(&mut self, text: &[u8]) -> Result<(), StreamError>[src]
pub fn skip_string(&mut self, text: &[u8]) -> Result<(), StreamError>pub fn consume_name(&mut self) -> Result<StrSpan<'a>, StreamError>[src]
pub fn consume_name(&mut self) -> Result<StrSpan<'a>, StreamError>Consumes an XML name and returns it.
Consumes according to: https://www.w3.org/TR/xml/#NT-Name
Errors
InvalidNameToken- if name is empty or starts with an invalid charUnexpectedEndOfStream
pub fn skip_name(&mut self) -> Result<(), StreamError>[src]
pub fn skip_name(&mut self) -> Result<(), StreamError>Skips an XML name.
The same as consume_name(), but does not return a consumed name.
Errors
InvalidNameToken- if name is empty or starts with an invalid charUnexpectedEndOfStream
pub fn consume_qname(
&mut self
) -> Result<(StrSpan<'a>, StrSpan<'a>), StreamError>[src]
pub fn consume_qname(
&mut self
) -> Result<(StrSpan<'a>, StrSpan<'a>), StreamError>Consumes a qualified XML name and returns it.
Consumes according to: https://www.w3.org/TR/xml-names/#ns-qualnames
Errors
InvalidNameToken- if name is empty or starts with an invalid charUnexpectedEndOfStream
pub fn consume_eq(&mut self) -> Result<(), StreamError>[src]
pub fn consume_eq(&mut self) -> Result<(), StreamError>pub fn consume_quote(&mut self) -> Result<u8, StreamError>[src]
pub fn consume_quote(&mut self) -> Result<u8, StreamError>pub fn consume_bytes<F>(&mut self, f: F) -> StrSpan<'a> where
F: Fn(&Stream, u8) -> bool, [src]
pub fn consume_bytes<F>(&mut self, f: F) -> StrSpan<'a> where
F: Fn(&Stream, u8) -> bool, Consumes bytes by the predicate and returns them.
The result can be empty.
pub fn skip_bytes<F>(&mut self, f: F) where
F: Fn(&Stream, u8) -> bool, [src]
pub fn skip_bytes<F>(&mut self, f: F) where
F: Fn(&Stream, u8) -> bool, Consumes bytes by the predicate.
pub fn consume_chars<F>(&mut self, f: F) -> StrSpan<'a> where
F: Fn(&Stream, char) -> bool, [src]
pub fn consume_chars<F>(&mut self, f: F) -> StrSpan<'a> 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) where
F: Fn(&Stream, char) -> bool, [src]
pub fn skip_chars<F>(&mut self, f: F) where
F: Fn(&Stream, char) -> bool, Consumes chars by the predicate.
pub fn try_consume_reference(&mut self) -> Option<Reference<'a>>[src]
pub fn try_consume_reference(&mut self) -> Option<Reference<'a>>Consumes an XML character reference if there is one.
On error will reset the position to the original.
pub fn consume_reference(&mut self) -> Result<Reference<'a>, StreamError>[src]
pub fn consume_reference(&mut self) -> Result<Reference<'a>, StreamError>Consumes an XML reference.
Consumes according to: https://www.w3.org/TR/xml/#NT-Reference
Errors
InvalidReferenceUnexpectedEndOfStream
pub fn slice_back(&self, pos: usize) -> StrSpan<'a>[src]
pub fn slice_back(&self, pos: usize) -> StrSpan<'a>Slices data from pos to the current position.
pub fn slice_tail(&self) -> StrSpan<'a>[src]
pub fn slice_tail(&self) -> StrSpan<'a>Slices data from the current position to the end.
pub fn gen_error_pos(&self) -> TextPos[src]
pub fn gen_error_pos(&self) -> TextPosCalculates a current absolute position.
This operation is very expensive. Use only for errors.
pub fn gen_error_pos_from(&self, pos: usize) -> TextPos[src]
pub fn gen_error_pos_from(&self, pos: usize) -> TextPosCalculates an absolute position at pos.
This operation is very expensive. Use only for errors.
Trait Implementations
impl<'a> PartialEq for Stream<'a>[src]
impl<'a> PartialEq for Stream<'a>fn eq(&self, other: &Stream<'a>) -> bool[src]
fn eq(&self, other: &Stream<'a>) -> boolThis method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Stream<'a>) -> bool[src]
fn ne(&self, other: &Stream<'a>) -> boolThis method tests for !=.
impl<'a> Clone for Stream<'a>[src]
impl<'a> Clone for Stream<'a>fn clone(&self) -> Stream<'a>[src]
fn clone(&self) -> Stream<'a>Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)Performs copy-assignment from source. Read more
impl<'a> Copy for Stream<'a>[src]
impl<'a> Copy for Stream<'a>impl<'a> Debug for Stream<'a>[src]
impl<'a> Debug for Stream<'a>fn fmt(&self, f: &mut Formatter) -> Result[src]
fn fmt(&self, f: &mut Formatter) -> ResultFormats the value using the given formatter. Read more
impl<'a> From<&'a str> for Stream<'a>[src]
impl<'a> From<&'a str> for Stream<'a>impl<'a> From<StrSpan<'a>> for Stream<'a>[src]
impl<'a> From<StrSpan<'a>> for Stream<'a>