use anyhow::{Context, Result};
use std::fs;
use std::path::Path;
const IGNORE_MARKER: &[u8] = b"linecheck\x3aignore";
pub fn file_info(path: &Path) -> Result<(usize, bool)> {
let data = fs::read(path).with_context(|| format!("reading {}", path.display()))?;
let ignored = data
.windows(IGNORE_MARKER.len())
.any(|w| w == IGNORE_MARKER);
Ok((count_newlines(&data), ignored))
}
pub fn count_newlines(data: &[u8]) -> usize {
if data.is_empty() {
return 0;
}
let newlines = data.iter().filter(|&&b| b == b'\n').count();
if data.last() != Some(&b'\n') {
newlines + 1
} else {
newlines
}
}
#[cfg(test)]
#[path = "lines_tests.rs"]
mod tests;