pub(crate) fn tl_id(definition: &str) -> u32 {
let cleaned = if let Some(hash_pos) = definition.find('#') {
let after_hash = &definition[hash_pos + 1..];
let id_len = after_hash
.find(|c: char| !c.is_ascii_hexdigit())
.unwrap_or(after_hash.len());
let rest = &after_hash[id_len..];
format!("{}{}", definition[..hash_pos].trim_end(), rest)
} else {
definition.to_owned()
};
crc32(cleaned.trim())
}
fn crc32(data: &str) -> u32 {
let mut crc: u32 = 0xFFFF_FFFF;
for byte in data.bytes() {
crc ^= u32::from(byte);
for _ in 0..8 {
if crc & 1 != 0 {
crc = (crc >> 1) ^ 0xEDB8_8320;
} else {
crc >>= 1;
}
}
}
!crc
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn known_id() {
let def = "boolFalse = Bool";
assert_eq!(tl_id(def), 0xbc799737);
}
}