const CATALOG: &str = include_str!("../../docs/error-codes.md");
#[cfg(test)]
pub const RETIRED: &[&str] = &["Q0219"];
pub fn normalize(arg: &str) -> Option<String> {
let code = arg.trim().to_ascii_uppercase();
let digits = code.strip_prefix('Q')?;
(digits.len() == 4 && digits.bytes().all(|b| b.is_ascii_digit())).then_some(code)
}
pub fn entries() -> Vec<(String, String)> {
let text = CATALOG.replace("\r\n", "\n");
let mut out = Vec::new();
for section in text.split("\n## ").skip(1) {
let Some((code, _)) = section.split_once(':') else {
continue;
};
if normalize(code).as_deref() == Some(code) {
out.push((code.to_string(), section.trim_end().to_string()));
}
}
out
}
pub fn explain(code: &str) -> Option<String> {
entries()
.into_iter()
.find(|(c, _)| c == code)
.map(|(_, text)| format!("{text}\n"))
}