use std::fs;
use std::path::Path;
use anyhow::Context;
use anyhow::Result;
pub struct HeaderSource;
impl HeaderSource {
pub fn read(path: &Path) -> Result<Vec<String>> {
let contents = fs::read_to_string(path)
.with_context(|| format!("failed to read header file {}", path.display()))?;
Ok(Self::parse(&contents))
}
pub fn parse(contents: &str) -> Vec<String> {
let contents = contents.strip_prefix('\u{feff}').unwrap_or(contents);
let mut lines: Vec<String> = contents
.split('\n')
.map(|line| line.strip_suffix('\r').unwrap_or(line).to_string())
.collect();
while lines.last().is_some_and(|line| line.trim().is_empty()) {
lines.pop();
}
lines
}
}