pub(super) fn family_alias(model: &str) -> Option<String> {
let (head, tail) = model.rsplit_once('-')?;
if !tail.is_empty() && tail.bytes().all(|b| b.is_ascii_digit()) {
if is_date_like(tail) {
return None;
}
Some(format!("{head}-x"))
} else {
None
}
}
pub(super) fn strip_trailing_date(model: &str) -> Option<String> {
if let Some((head, tail)) = model.rsplit_once('-') {
if is_compact_date(tail) {
return Some(head.to_string());
}
}
let parts: Vec<&str> = model.rsplitn(4, '-').collect();
if parts.len() == 4 {
let day = parts[0];
let month = parts[1];
let year = parts[2];
let head = parts[3];
if year.len() == 4
&& month.len() == 2
&& day.len() == 2
&& !head.is_empty()
&& year.bytes().all(|b| b.is_ascii_digit())
&& month.bytes().all(|b| b.is_ascii_digit())
&& day.bytes().all(|b| b.is_ascii_digit())
{
return Some(head.to_string());
}
}
None
}
fn is_compact_date(tail: &str) -> bool {
tail.len() == 8 && tail.bytes().all(|b| b.is_ascii_digit())
}
fn is_date_like(tail: &str) -> bool {
is_compact_date(tail)
}