use super::FileProcessor;
use anyhow::Result;
use chardetng::{EncodingDetector, Iso2022JpDetection, Utf8Detection};
use std::path::Path;
pub struct DefaultTextProcessor;
impl FileProcessor for DefaultTextProcessor {
fn process(&self, content: &[u8], _path: &Path) -> Result<String> {
let mut detector = EncodingDetector::new(Iso2022JpDetection::Deny);
detector.feed(content, true);
let encoding = detector.guess(None, Utf8Detection::Allow);
let (cow, _encoding_used, _had_errors) = encoding.decode(content);
match cow {
std::borrow::Cow::Owned(s) => Ok(s),
std::borrow::Cow::Borrowed(s) => Ok(s.to_string()),
}
}
}