Struct xmlparser::Stream
[−]
[src]
pub struct Stream<'a> { /* fields omitted */ }
Streaming text parsing interface.
Methods
impl<'a> Stream<'a>
[src]
fn from_span(span: StrSpan<'a>) -> Stream
[src]
Constructs a new Stream
from a string span.
fn from_str(text: &str) -> Stream
[src]
Constructs a new Stream
from a string.
fn span(&self) -> StrSpan<'a>
[src]
Returns an underling string span.
fn pos(&self) -> usize
[src]
Returns current position.
fn jump_to_end(&mut self)
[src]
Sets current position equal to the end.
Used to indicate end of parsing on error.
fn at_end(&self) -> bool
[src]
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.
fn curr_byte(&self) -> Result<u8, StreamError>
[src]
Returns a byte from a current stream position.
Errors
Returns UnexpectedEndOfStream
if we are at the end of the stream.
fn is_curr_byte_eq(&self, c: u8) -> bool
[src]
Checks that current byte is equal to provided.
Returns false
if no bytes left.
fn get_curr_byte(&self) -> Option<u8>
[src]
Returns a byte from a current stream position if there is one.
fn next_byte(&self) -> Result<u8, StreamError>
[src]
Returns a next byte from a current stream position.
Errors
Returns UnexpectedEndOfStream
if we are at the end of the stream.
fn curr_char(&self) -> Result<char, StreamError>
[src]
Returns a char from a current stream position.
Errors
Returns UnexpectedEndOfStream
if we are at the end of the stream.
fn advance(&mut self, n: usize)
[src]
Advances by n
bytes.
Examples
use xmlparser::Stream; let mut s = Stream::from_str("text"); s.advance(2); // ok s.advance(20); // will cause a panic via debug_assert!().
fn skip_spaces(&mut self)
[src]
Skips whitespaces.
Accepted values: ' ' \n \r \t   	 
 

.
Examples
use xmlparser::Stream; let mut s = Stream::from_str(" \t\n\r   "); s.skip_spaces(); assert_eq!(s.at_end(), true);
fn starts_with(&self, text: &[u8]) -> bool
[src]
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_str("Some text."); s.advance(5); assert_eq!(s.starts_with(b"text"), true); assert_eq!(s.starts_with(b"long"), false);
fn starts_with_space(&self) -> bool
[src]
Checks if the stream is starts with a space.
Uses skip_spaces()
internally.
fn consume_spaces(&mut self) -> Result<(), StreamError>
[src]
Consumes whitespaces.
Like skip_spaces()
, but checks that first char is actually a space.
fn consume_byte(&mut self, c: u8) -> Result<(), StreamError>
[src]
Consumes current byte if it's equal to the provided byte.
Errors
InvalidChar
Examples
use xmlparser::Stream; let mut s = Stream::from_str("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
fn consume_either(&mut self, list: &[u8]) -> Result<u8, StreamError>
[src]
Consumes current byte if it's equal to one of the provided bytes.
Returns a coincidental byte.
Errors
InvalidChar
fn skip_string(&mut self, text: &[u8]) -> Result<(), StreamError>
[src]
fn consume_name(&mut self) -> Result<StrSpan<'a>, StreamError>
[src]
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
fn skip_name(&mut self) -> Result<(), StreamError>
[src]
Skips an XML name.
The same as consume_name()
, but does not return a consumed name.
fn consume_eq(&mut self) -> Result<(), StreamError>
[src]
fn consume_quote(&mut self) -> Result<u8, StreamError>
[src]
fn consume_bytes<F>(&mut self, f: F) -> StrSpan<'a> where
F: Fn(&Stream, u8) -> bool,
[src]
F: Fn(&Stream, u8) -> bool,
Consumes bytes by predicate and returns them.
Result can be empty.
fn skip_bytes<F>(&mut self, f: F) where
F: Fn(&Stream, u8) -> bool,
[src]
F: Fn(&Stream, u8) -> bool,
Consumes bytes by predicate.
fn consume_chars<F>(&mut self, f: F) -> StrSpan<'a> where
F: Fn(&Stream, char) -> bool,
[src]
F: Fn(&Stream, char) -> bool,
Consumes chars by predicate and returns them.
Result can be empty.
fn skip_chars<F>(&mut self, f: F) where
F: Fn(&Stream, char) -> bool,
[src]
F: Fn(&Stream, char) -> bool,
Consumes chars by predicate.
fn try_consume_char_reference(&mut self) -> Option<char>
[src]
Consumes an XML character reference if there is one.
On error will reset the position to the original.
fn consume_reference(&mut self) -> Result<Reference<'a>, StreamError>
[src]
Consumes an XML reference.
Consumes according to: https://www.w3.org/TR/xml/#NT-Reference
fn slice_back(&mut self, pos: usize) -> StrSpan<'a>
[src]
Slices data from pos
to the current position.
fn slice_tail(&mut self) -> StrSpan<'a>
[src]
Slices data from the current position to the end.
fn gen_error_pos(&self) -> ErrorPos
[src]
Calculates a current absolute position.
This operation is very expensive. Use only for errors.
fn gen_error_pos_from(&mut self, pos: usize) -> ErrorPos
[src]
Calculates a current absolute position.
This operation is very expensive. Use only for errors.
Trait Implementations
impl<'a> PartialEq for Stream<'a>
[src]
fn eq(&self, __arg_0: &Stream<'a>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Stream<'a>) -> bool
[src]
This method tests for !=
.
impl<'a> Clone for Stream<'a>
[src]
fn clone(&self) -> Stream<'a>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more