diff options
author | 2024-11-10 22:28:55 +0000 | |
---|---|---|
committer | 2024-11-10 22:28:55 +0000 | |
commit | 6d4832480b1804652bb4faa33b361ffb43734270 (patch) | |
tree | c79d65f833283d43e75f1cb4518a682b7933a049 /src/xml | |
parent | 140af50536ebc32ae6461852daa2df0fc2d197ca (diff) | |
download | peanuts-6d4832480b1804652bb4faa33b361ffb43734270.tar.gz peanuts-6d4832480b1804652bb4faa33b361ffb43734270.tar.bz2 peanuts-6d4832480b1804652bb4faa33b361ffb43734270.zip |
WIP: impl Stream for Reader
Diffstat (limited to 'src/xml')
-rw-r--r-- | src/xml/composers.rs | 1 | ||||
-rw-r--r-- | src/xml/mod.rs | 18 | ||||
-rw-r--r-- | src/xml/parsers.rs | 17 |
3 files changed, 35 insertions, 1 deletions
diff --git a/src/xml/composers.rs b/src/xml/composers.rs index 949bb65..b8fbe13 100644 --- a/src/xml/composers.rs +++ b/src/xml/composers.rs @@ -817,6 +817,7 @@ impl<'s> Composer<'s> for Content<'s> { ContentItem::CDSect(cd_sect) => cd_sect.write(writer).await?, ContentItem::PI(pi) => pi.write(writer).await?, ContentItem::Comment(comment) => comment.write(writer).await?, + _ => todo!("verify no split chardata"), } if let Some(char_data) = char_data { char_data.write(writer).await?; diff --git a/src/xml/mod.rs b/src/xml/mod.rs index 221c334..9424d0b 100644 --- a/src/xml/mod.rs +++ b/src/xml/mod.rs @@ -47,6 +47,22 @@ pub enum QName<'s> { UnprefixedName(UnprefixedName<'s>), } +impl<'s> QName<'s> { + pub fn prefix(&self) -> Option<&'s str> { + match self { + QName::PrefixedName(prefixed_name) => return Some(**prefixed_name.prefix), + QName::UnprefixedName(_) => return None, + } + } + + pub fn local_part(&self) -> &str { + match self { + QName::PrefixedName(prefixed_name) => return **prefixed_name.local_part, + QName::UnprefixedName(unprefixed_name) => return ****unprefixed_name, + } + } +} + impl<'s> ToString for QName<'s> { fn to_string(&self) -> String { match self { @@ -473,7 +489,7 @@ pub struct ETag<'s> { #[derive(Debug, Clone)] pub enum ContentItem<'s> { - // CharData(&'s str), + CharData(CharData<'s>), Element(Element<'s>), Reference(Reference<'s>), CDSect(CDSect<'s>), diff --git a/src/xml/parsers.rs b/src/xml/parsers.rs index 3f67be7..3cbefd3 100644 --- a/src/xml/parsers.rs +++ b/src/xml/parsers.rs @@ -733,6 +733,23 @@ impl<'s> Parser<'s, ETag<'s>> for ETag<'s> { } } +impl<'s> Parser<'s, ContentItem<'s>> for ContentItem<'s> { + fn parse(input: &'s str) -> IResult<&str, ContentItem<'s>> { + alt(( + map(CharData::parse, |char_data| { + ContentItem::CharData(char_data) + }), + map(Element::parse, |element| ContentItem::Element(element)), + map(Reference::parse, |reference| { + ContentItem::Reference(reference) + }), + map(CDSect::parse, |cd_sect| ContentItem::CDSect(cd_sect)), + map(PI::parse, |pi| ContentItem::PI(pi)), + map(Comment::parse, |comment| ContentItem::Comment(comment)), + ))(input) + } +} + /// [43] content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)* impl<'s> Parser<'s, Content<'s>> for Content<'s> { fn parse(input: &'s str) -> IResult<&str, Content<'s>> { |