use std::fmt;
pub const LOCAL_PREFIX: &str = "local-";
pub const SELECT_VARIABLE: &str = "CLI_CHAINS_CASE";
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct CaseId(pub u16);
impl CaseId {
#[must_use]
pub fn parse(text: &str) -> Option<Self> {
let digits = text.strip_prefix(LOCAL_PREFIX)?;
if digits.len() != 4 || !digits.bytes().all(|byte| byte.is_ascii_digit()) {
return None;
}
let number: u16 = digits.parse().ok()?;
(number > 0).then_some(Self(number))
}
}
impl fmt::Display for CaseId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{LOCAL_PREFIX}{:04}", self.0)
}
}
#[must_use]
pub fn fingerprint(text: &str) -> u64 {
let mut hash: u64 = 0xcbf2_9ce4_8422_2325;
for byte in text.bytes() {
hash ^= u64::from(byte);
hash = hash.wrapping_mul(0x0000_0100_0000_01b3);
}
hash
}