text_reader: support quick-xml without encoding_rs dependency

This commit is contained in:
Matt Bilker
2019-08-30 21:12:44 +00:00
parent 3edc7026e4
commit bb34602daa
2 changed files with 10 additions and 2 deletions

View File

@@ -68,6 +68,12 @@ impl EncodingType {
Ok(val)
}
pub fn from_label(label: &[u8]) -> Result<Self, KbinError> {
Encoding::for_label(label)
.ok_or(KbinErrorKind::UnknownEncoding.into())
.and_then(Self::from_encoding)
}
pub fn to_byte(&self) -> u8 {
match *self {
EncodingType::None => 0x00, // 0x00 >> 5 = 0

View File

@@ -216,8 +216,10 @@ impl<'a> TextXmlReader<'a> {
parent_collection.children_mut().push_back(collection);
}
},
Ok(Event::Decl(_)) => {
self.encoding = EncodingType::from_encoding(self.xml_reader.encoding())?;
Ok(Event::Decl(e)) => {
if let Some(encoding) = e.encoding() {
self.encoding = EncodingType::from_label(&encoding?)?;
}
},
Ok(Event::Eof) => break,
Ok(_) => {},