atmos/os_lib/util/
ordinal.rs1pub fn number_to_alpha(mut n: u32, upper: bool) -> alloc::string::String {
5 if n == 0 {
6 n = 1;
7 }
8 let mut letters = alloc::vec::Vec::new();
9 while n > 0 {
10 let rem = ((n - 1) % 26) as u8;
11 let base = if upper { b'A' } else { b'a' };
12 letters.push((base + rem) as char);
13 n = (n - 1) / 26;
14 }
15 letters.iter().rev().collect()
16}
17
18pub fn number_to_roman(n: u32, upper: bool) -> alloc::string::String {
20 if n == 0 || n > 3999 {
21 return alloc::format!("{}", n);
22 }
23 const VALUES: &[(u32, &str)] = &[
24 (1000, "M"), (900, "CM"), (500, "D"), (400, "CD"),
25 (100, "C"), (90, "XC"), (50, "L"), (40, "XL"),
26 (10, "X"), (9, "IX"), (5, "V"), (4, "IV"), (1, "I"),
27 ];
28 let mut remaining = n;
29 let mut out = alloc::string::String::new();
30 for (value, symbol) in VALUES {
31 while remaining >= *value {
32 out.push_str(symbol);
33 remaining -= value;
34 }
35 }
36 if upper {
37 out
38 } else {
39 out.to_ascii_lowercase()
40 }
41}