aboutsummaryrefslogtreecommitdiffstats
path: root/src/xml/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/xml/mod.rs')
-rw-r--r--src/xml/mod.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/xml/mod.rs b/src/xml/mod.rs
index 43f3027..3982070 100644
--- a/src/xml/mod.rs
+++ b/src/xml/mod.rs
@@ -2,7 +2,7 @@ use std::{char, convert::Infallible, ops::Deref, str::FromStr};
use parsers_complete::Parser;
-use crate::error::Error;
+use crate::error::{CharRefError, Error};
pub mod composers;
pub mod parsers;
@@ -736,23 +736,23 @@ impl<'s> CharRef<'s> {
let int: u32;
match self {
CharRef::Decimal(dec) => {
- int = dec.parse()?;
+ int = dec
+ .parse()
+ .map_err(|e| Error::InvalidCharRef(CharRefError::ParseInt(e)))?;
}
CharRef::Hexadecimal(hex) => {
- int = <u32>::from_str_radix(hex, 16)?;
+ int = <u32>::from_str_radix(hex, 16)
+ .map_err(|e| Error::InvalidCharRef(CharRefError::ParseInt(e)))?;
}
}
let c = std::char::from_u32(int);
- let c = c.ok_or_else(|| Error::InvalidCharRef(int.to_string()))?;
+ let c = c.ok_or_else(|| Error::InvalidCharRef(CharRefError::IntegerNotAChar(int)))?;
if matches!(c, '\u{9}' | '\u{A}' | '\u{D}' | '\u{20}'..='\u{D7FF}' | '\u{E000}'..='\u{FFFD}' | '\u{10000}'..='\u{10FFFF}')
{
return Ok(c);
} else {
- return Err(Error::InvalidCharRef(format!(
- "{} is not a valid xml char",
- c
- )));
+ return Err(Error::InvalidCharRef(CharRefError::InvalidXMLChar(c)));
};
}
}