#[derive(Debug)]
pub(crate) struct Loc {
pub(crate) parent: u16,
pub(crate) digits: u16,
pub(crate) decimal: u16,
pub(crate) group: u16,
pub(crate) cur_decimal: u16,
pub(crate) cur_group: u16,
pub(crate) nan: u16,
pub(crate) infinity: u16,
pub(crate) decimal_pat: u16,
pub(crate) percent_pat: u16,
pub(crate) currency_pat: u16,
pub(crate) min_grouping: u8,
pub(crate) compact: u16,
pub(crate) compact_len: u8,
pub(crate) currencies: u16,
pub(crate) currencies_len: u16,
pub(crate) autonym: u16,
pub(crate) plural: u8,
#[cfg(feature = "currency-names")]
pub(crate) units: [u16; 6],
#[cfg(feature = "currency-names")]
pub(crate) names: u32,
#[cfg(feature = "currency-names")]
pub(crate) names_len: u16,
#[cfg(feature = "currency-names")]
pub(crate) name_cur: bool,
pub(crate) dpats: u16,
pub(crate) dtimes: u16,
pub(crate) dnames: u16,
pub(crate) drel: u16,
pub(crate) db: u16,
pub(crate) dover: u32,
pub(crate) dover_len: u16,
pub(crate) hc12: u8,
pub(crate) hc24: u8,
}
#[derive(Debug)]
pub(crate) struct Pat {
pub(crate) pp: u16,
pub(crate) ps: u16,
pub(crate) np: u16,
pub(crate) ns: u16,
pub(crate) g1: u8,
pub(crate) g2: u8,
}
#[derive(Debug)]
pub(crate) struct Compact {
pub(crate) mag: u8,
pub(crate) cat: u8,
pub(crate) pp: u16,
pub(crate) ps: u16,
pub(crate) np: u16,
pub(crate) ns: u16,
pub(crate) zeros: u8,
}
#[derive(Debug)]
pub(crate) struct Currency {
pub(crate) code: [u8; 3],
pub(crate) symbol: u16,
pub(crate) narrow: u16,
pub(crate) pattern: u16,
pub(crate) decimal: u16,
pub(crate) group: u16,
}
#[cfg(feature = "currency-names")]
#[derive(Debug)]
pub(crate) struct Name {
pub(crate) code: [u8; 3],
pub(crate) cat: u8,
pub(crate) name: u32,
}
include!(concat!(env!("OUT_DIR"), "/numbers.rs"));
#[inline]
pub(crate) fn key(name: &str) -> Option<u128> {
let b = name.as_bytes();
let mut a = [0u8; 16];
a.get_mut(..b.len())?.copy_from_slice(b);
Some(u128::from_be_bytes(a))
}
pub(crate) fn numbering(digits: u16) -> &'static str {
if digits == 0 {
return "latn";
}
NUMBERING
.iter()
.find(|&&(d, _)| d == digits)
.map_or("", |&(_, name)| s(name))
}
#[inline]
fn at<E: Copy + Into<u32>>(text: &'static str, ends: &[E], i: usize) -> &'static str {
let start = i
.checked_sub(1)
.and_then(|j| ends.get(j))
.map_or(0, |&e| e.into() as usize);
let end = ends.get(i).map_or(start, |&e| e.into() as usize);
text.get(start..end).unwrap_or("")
}
#[inline]
pub(crate) fn s(i: u16) -> &'static str {
at(STR, &ENDS, usize::from(i))
}
#[inline]
pub(crate) fn dpat(i: u16) -> &'static str {
at(DPAT_STR, &DPAT_ENDS, usize::from(i))
}
#[inline]
pub(crate) fn dname(i: u16) -> &'static str {
at(DNAME_STR, &DNAME_ENDS, usize::from(i))
}
#[cfg(feature = "currency-names")]
pub(crate) fn name_str(i: u32) -> &'static str {
at(NAME_STR, &NAME_ENDS, i as usize)
}