pub(super) fn parse_imb_reference_at(bytes: &[u8], offset: usize) -> Option<String> {
    if offset > 0 {
        let previous = *bytes.get(offset - 1)?;
        if previous != 0 {
            return None;
        }
    }
    let slice = bytes.get(offset..)?;
    let nul = slice.iter().position(|byte| *byte == 0)?;
    let candidate = slice.get(..nul)?;
    if candidate.len() < 5 {
        return None;
    }
    let value = std::str::from_utf8(candidate).ok()?;
    if !value.ends_with(".imb") {
        return None;
    }
    if !value
        .bytes()
        .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'_' | b'-' | b'.' | b' '))
    {
        return None;
    }
    Some(value.to_string())
}

pub(super) fn parse_inline_ascii_name(bytes: &[u8], offset: usize) -> Option<String> {
    let prefix = *bytes.get(offset)?;
    if prefix != 0 {
        return None;
    }
    parse_imb_reference_at(bytes, offset + 1)
}
