use super::FileProcessor;
use anyhow::Result;
use chardetng::EncodingDetector;
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();
detector.feed(content, true);
let encoding = detector.guess(None, true);
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()),
}
}
}