Struct xmlparser::Stream

source ·
pub struct Stream<'a> { /* private fields */ }
Expand description

A streaming text parsing interface.

Implementations§

Returns an underling string span.

Returns current position.

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.

Errors
  • UnexpectedEndOfStream

Returns a byte from a current stream position.

Panics
  • if the current position is after the end of the data

Checks that current byte is equal to provided.

Returns false if no bytes left.

Returns a byte from a current stream position if there is one.

Returns a next byte from a current stream position.

Errors
  • UnexpectedEndOfStream

Returns a char from a current stream position.

Errors
  • UnexpectedEndOfStream

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!().

Skips whitespaces.

Accepted values: ' ' \n \r \t &#x20; &#x9; &#xD; &#xA;.

Examples
use xmlparser::Stream;

let mut s = Stream::from(" \t\n\r &#x20; ");
s.skip_spaces();
assert_eq!(s.at_end(), true);

Skips ASCII whitespaces.

Accepted values: ' ' \n \r \t.

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);

Checks if the stream is starts with a space.

Uses skip_spaces() internally.

Consumes whitespaces.

Like skip_spaces(), but checks that first char is actually a space.

Errors
  • InvalidChar

Consumes current byte if it’s equal to the provided byte.

Errors
  • InvalidChar
  • UnexpectedEndOfStream
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

Consumes current byte if it’s equal to one of the provided bytes.

Returns a coincidental byte.

Errors
  • InvalidChar
  • UnexpectedEndOfStream

Consumes selected string.

Errors
  • InvalidChar

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 char
  • UnexpectedEndOfStream

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
  • UnexpectedEndOfStream

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
  • UnexpectedEndOfStream

Consumes =.

Consumes according to: https://www.w3.org/TR/xml/#NT-Eq

Errors
  • InvalidChar

Consumes quote.

Consumes ' or " and returns it.

Errors
  • InvalidQuote
  • UnexpectedEndOfStream

Consumes bytes by the predicate and returns them.

The result can be empty.

Consumes bytes by the predicate.

Consumes chars by the predicate and returns them.

The result can be empty.

Consumes chars by the predicate.

Consumes an XML character reference if there is one.

On error will reset the position to the original.

Consumes an XML reference.

Consumes according to: https://www.w3.org/TR/xml/#NT-Reference

Errors
  • InvalidReference
  • UnexpectedEndOfStream

Slices data from pos to the current position.

Slices data from the current position to the end.

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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.