#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct BomResult {
pub(crate) bom: String,
pub(crate) text: String,
}
pub(crate) fn strip_utf8_bom(text: &str) -> BomResult {
if let Some(stripped) = text.strip_prefix('\u{FEFF}') {
return BomResult {
bom: "\u{FEFF}".to_string(),
text: stripped.to_string(),
};
}
BomResult {
bom: String::new(),
text: text.to_string(),
}
}
pub(crate) fn normalize_to_lf(text: &str) -> String {
text.replace("\r\n", "\n").replace('\r', "\n")
}
pub(crate) fn normalize_for_snapshot_storage(text: &str) -> String {
normalize_to_lf(&strip_utf8_bom(text).text)
}