#[inline]
pub(crate) fn is_xml_whitespace_only(text: &str) -> bool {
text.chars()
.all(|ch| matches!(ch, ' ' | '\t' | '\r' | '\n'))
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct XmlBase64NormalizeError {
pub invalid_byte: u8,
pub normalized_offset: usize,
}
pub(crate) fn normalize_xml_base64_text(
text: &str,
normalized: &mut String,
) -> Result<(), XmlBase64NormalizeError> {
for ch in text.chars() {
if matches!(ch, ' ' | '\t' | '\r' | '\n') {
continue;
}
if ch.is_ascii_whitespace() {
let mut utf8 = [0_u8; 4];
let encoded = ch.encode_utf8(&mut utf8);
let invalid_byte = encoded.as_bytes()[0];
return Err(XmlBase64NormalizeError {
invalid_byte,
normalized_offset: normalized.len(),
});
}
normalized.push(ch);
}
Ok(())
}