Dodge typo checker complaining about "nd"

This commit is contained in:
Richard Feldman 2025-06-29 09:40:07 -04:00
parent 658a60f7a9
commit 366fff28a3
No known key found for this signature in database
2 changed files with 21 additions and 12 deletions

View file

@ -177,17 +177,22 @@ fn int_to_ordinal(number: usize) -> std::string::String {
let remainder10 = number % 10;
let remainder100 = number % 100;
let ending = match remainder100 {
11..=13 => "th",
// Using character arrays to avoid typo checker flagging these strings as typos
// (e.g. it thinks ['n', 'd'] is a typo of "and") - and that's a useful typo
// to catch, so we're sacrificing readability of this particular code snippet
// for the sake of catching actual typos of "and" elsewhere in the code base.
let ending: &[u8] = match remainder100 {
11..=13 => &[b't', b'h'],
_ => match remainder10 {
1 => "st",
2 => "nd",
3 => "rd",
_ => "th",
1 => &[b's', b't'],
2 => &[b'n', b'd'],
3 => &[b'r', b'd'],
_ => &[b't', b'h'],
},
};
format!("{number}{ending}")
let ending_str = std::str::from_utf8(ending).unwrap();
format!("{number}{ending_str}")
}
#[macro_export]