exarmo-core 0.1.2

Runtime support shared by the exarmo-aarch64 and exarmo-aarch32 disassemblers
Documentation
//! Names packed into one string, as the generated tables hold them.
//!
//! A table of thousands of names as `&str`s is a pointer and a length per
//! name, and a relocation for each. The generated tables run the names
//! together into one string and keep where each ends.

/// The name at `index` of a table whose names are packed into `text`, with
/// `ends[i]` the offset just past name `i`.
///
/// It is `const` so that a C face can lay a whole table out as a constant.
pub const fn name_at(text: &'static str, ends: &[u32], index: usize) -> &'static str {
    let start = if index == 0 {
        0
    } else {
        ends[index - 1] as usize
    };
    let (_, rest) = text.as_bytes().split_at(start);
    let (name, _) = rest.split_at(ends[index] as usize - start);
    match core::str::from_utf8(name) {
        Ok(name) => name,
        Err(_) => panic!("a table's ends fall inside a character"),
    }
}