use std::borrow::Cow;
pub fn normalize_text(value: &str, multiline: bool) -> Cow<'_, str> {
if !value.contains(['\r', '\0']) && (multiline || !value.contains('\n')) {
return Cow::Borrowed(value);
}
let mut output = String::with_capacity(value.len());
let mut chars = value.chars().peekable();
while let Some(ch) = chars.next() {
match ch {
'\r' if multiline => {
if chars.peek() == Some(&'\n') {
chars.next();
}
output.push('\n');
}
'\r' | '\n' if !multiline => {}
'\0' => output.push('\u{fffd}'),
ch => output.push(ch),
}
}
Cow::Owned(output)
}