pub(crate) mod decode;
use super::DecodedEntity;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EntityContext {
Text,
Attribute,
}
#[inline]
pub fn needs_decoding(bytes: &[u8]) -> bool {
bytes.contains(&b'&')
}
#[inline]
pub fn decode_one(input: &[u8], context: EntityContext) -> Option<(DecodedEntity, usize)> {
let context = match context {
EntityContext::Text => htmlize::Context::General,
EntityContext::Attribute => htmlize::Context::Attribute,
};
decode::try_decode_entity(input, context)
}
#[cfg(test)]
mod tests {
use super::needs_decoding;
#[test]
fn only_ampersands_need_decoding() {
assert!(!needs_decoding(b"a || b"));
assert!(needs_decoding(b"a && b"));
}
}