pub struct XmlParser<'a> {
pub input: &'a str,
pub offset: usize,
}Expand description
Hand-rolled recursive-descent parser for XML and basic HTML documents.
Produces an XmlTree where every node’s offset field is the exact byte
position of the opening < (elements) or first character (text nodes) in
input. This byte-accuracy is required when reading positions are
persisted across sessions.
The parser is intentionally lenient: unknown tags, processing instructions,
and CDATA sections are skipped silently. Self-closing tags (<br/>,
<img/>) are supported.
Fields§
§input: &'a strThe full source string being parsed.
offset: usizeCurrent byte offset into input.
Implementations§
Source§impl<'a> XmlParser<'a>
impl<'a> XmlParser<'a>
Sourcepub fn new(input: &str) -> XmlParser<'_>
pub fn new(input: &str) -> XmlParser<'_>
Creates a new parser positioned at the start of input.
Sourcefn starts_with(&self, s: &str) -> bool
fn starts_with(&self, s: &str) -> bool
Returns true if the remaining input starts with s.
Sourcefn advance_while<F>(&mut self, test: F)
fn advance_while<F>(&mut self, test: F)
Advances the cursor as long as test returns true for the next char.
Sourcefn advance_until(&mut self, target: &str)
fn advance_until(&mut self, target: &str)
Advances the cursor until target is found and consumes it.
Does nothing if target is never found before EOF.
Sourcefn parse_attributes(&mut self) -> Attributes
fn parse_attributes(&mut self) -> Attributes
Parses the attribute list of an open tag, stopping at > or /.
Both single- and double-quoted attribute values are supported. The
cursor is left immediately before the closing > or /.
Sourcefn parse_element(&mut self, tree: &mut XmlTree, parent_id: NodeId)
fn parse_element(&mut self, tree: &mut XmlTree, parent_id: NodeId)
Parses a single element (tag name + attributes + children) and appends
it to parent_id in tree.
The cursor must be positioned immediately after the opening < when
this function is called. After returning the cursor is positioned after
the element’s closing tag.
Sourcefn parse_nodes(&mut self, tree: &mut XmlTree, parent_id: NodeId)
fn parse_nodes(&mut self, tree: &mut XmlTree, parent_id: NodeId)
Parses all child nodes of parent_id until a matching closing tag or
EOF is reached.
Handles text nodes, whitespace, elements, processing instructions
(<?…?>), comments (<!--…-->), CDATA sections (<![…]]>), and
DOCTYPE declarations.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for XmlParser<'a>
impl<'a> RefUnwindSafe for XmlParser<'a>
impl<'a> Send for XmlParser<'a>
impl<'a> Sync for XmlParser<'a>
impl<'a> Unpin for XmlParser<'a>
impl<'a> UnsafeUnpin for XmlParser<'a>
impl<'a> UnwindSafe for XmlParser<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more