const COMMENT: &str = "//@";
pub(crate) struct HeaderLine<'ln> {
pub(crate) line_number: usize,
pub(crate) revision: Option<&'ln str>,
pub(crate) directive: &'ln str,
}
pub(crate) fn iter_header<'ln>(contents: &'ln str, it: &mut dyn FnMut(HeaderLine<'ln>)) {
for (line_number, ln) in (1..).zip(contents.lines()) {
let ln = ln.trim();
let Some(remainder) = ln.strip_prefix(COMMENT) else {
continue;
};
if let Some(remainder) = remainder.trim_start().strip_prefix('[') {
let Some((revision, remainder)) = remainder.split_once(']') else {
panic!("malformed revision directive: expected `//@[rev]`, found `{ln}`");
};
it(HeaderLine { line_number, revision: Some(revision), directive: remainder.trim() });
} else {
it(HeaderLine { line_number, revision: None, directive: remainder.trim() });
}
}
}