mirror of
https://github.com/lennart-k/rustical.git
synced 2026-01-30 06:58:26 +00:00
xml: Implement namespace for Unparsed
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use quick_xml::name::Namespace;
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
|
||||
pub struct NamespaceOwned(pub Vec<u8>);
|
||||
|
||||
impl<'a> From<Namespace<'a>> for NamespaceOwned {
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
use std::io::BufRead;
|
||||
|
||||
use quick_xml::events::BytesStart;
|
||||
use quick_xml::{events::BytesStart, name::ResolveResult};
|
||||
|
||||
use crate::{XmlDeserialize, XmlError};
|
||||
use crate::{NamespaceOwned, XmlDeserialize, XmlError};
|
||||
|
||||
// TODO: actually implement
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Unparsed(String);
|
||||
pub struct Unparsed(pub Option<NamespaceOwned>, pub String);
|
||||
|
||||
impl Unparsed {
|
||||
#[must_use]
|
||||
pub fn tag_name(&self) -> String {
|
||||
// TODO: respect namespace?
|
||||
self.0.clone()
|
||||
pub const fn ns(&self) -> Option<&NamespaceOwned> {
|
||||
self.0.as_ref()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub const fn tag_name(&self) -> &str {
|
||||
self.1.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +30,12 @@ impl XmlDeserialize for Unparsed {
|
||||
let mut buf = vec![];
|
||||
reader.read_to_end_into(start.name(), &mut buf)?;
|
||||
}
|
||||
let tag_name = String::from_utf8_lossy(start.local_name().as_ref()).to_string();
|
||||
Ok(Self(tag_name))
|
||||
let (ns, tag_name) = reader.resolver().resolve_element(start.name());
|
||||
let ns: Option<NamespaceOwned> = match ns {
|
||||
ResolveResult::Bound(ns) => Some(ns.into()),
|
||||
ResolveResult::Unbound | ResolveResult::Unknown(_) => None,
|
||||
};
|
||||
let tag_name = String::from_utf8_lossy(tag_name.as_ref()).to_string();
|
||||
Ok(Self(ns, tag_name))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user