#[cfg(feature = "quality")]
pub mod quality;
#[cfg(feature = "quality")]
pub mod string_utils;
pub(crate) fn strip_bom(s: &str) -> &str {
s.strip_prefix('\u{FEFF}').unwrap_or(s)
}
pub mod json_utils;
pub mod markdown_utils;
pub mod pool;
pub mod pool_sizing;
pub mod string_pool;
pub mod xml_utils;
#[cfg(feature = "quality")]
pub(crate) use string_utils::safe_decode;
#[cfg(any(feature = "xml", feature = "office"))]
pub(crate) use xml_utils::xml_tag_name;
#[cfg(any(all(feature = "layout-detection", feature = "pdf"), feature = "office"))]
use std::borrow::Cow;
#[cfg(all(feature = "layout-detection", feature = "pdf"))]
#[inline]
pub(crate) fn escape_html_entities(text: &str) -> Cow<'_, str> {
let needs_amp = text.contains('&');
let needs_lt = text.contains('<');
let needs_gt = text.contains('>');
if !needs_amp && !needs_lt && !needs_gt {
return Cow::Borrowed(text);
}
let mut result = String::with_capacity(text.len() + 16);
for ch in text.chars() {
match ch {
'&' => result.push_str("&"),
'<' => result.push_str("<"),
'>' => result.push_str(">"),
_ => result.push(ch),
}
}
Cow::Owned(result)
}
#[cfg(feature = "office")]
#[inline]
#[cfg_attr(alef, alef(skip))]
pub(crate) fn normalize_whitespace(s: &str) -> Cow<'_, str> {
let needs_normalization = s
.as_bytes()
.windows(2)
.any(|w| w[0].is_ascii_whitespace() && w[1].is_ascii_whitespace())
|| s.bytes().any(|b| b != b' ' && b.is_ascii_whitespace());
if needs_normalization {
Cow::Owned(s.split_whitespace().collect::<Vec<_>>().join(" "))
} else {
Cow::Borrowed(s)
}
}