use core::fmt;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ParseStringError {
UnexpectedEnd,
InvalidEscape(char),
InvalidUnicodeEscape(char),
MissingHighSurrogate {
low: u16,
},
MissingLowSurrogate {
high: u16,
},
InvalidLowSurrogate {
high: u16,
low: u16,
},
}
impl fmt::Display for ParseStringError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::UnexpectedEnd => {
write!(f, "Unexpected end of JSON string (missing \")!")
}
Self::InvalidEscape(c) => write!(f, "Invalid escape character ({c}) in JSON string!"),
Self::InvalidUnicodeEscape(c) => {
write!(
f,
"Invalid character ({c}) in unicode escape in JSON string!"
)
}
Self::MissingHighSurrogate { low } => {
write!(
f,
"Found a low surrogate (\\u{low:0>4x}) not prefixed with a high surrogate!"
)
}
Self::MissingLowSurrogate { high } => {
write!(
f,
"Found a high surrogate (\\u{high:0>4x}) not followed by a low surrogate!"
)
}
Self::InvalidLowSurrogate { high, low } => {
write!(f, "Invalid low surrogate (\\u{low:0>4x}) after a high surrogate (\\u{high:0>4x}!)")
}
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for ParseStringError {}