2022-04-12 07:16:34 -05:00
|
|
|
pub const fn char2num(c: char) -> isize {
|
2022-04-01 18:06:47 -05:00
|
|
|
match c {
|
2021-04-11 11:47:35 -05:00
|
|
|
' ' => 0,
|
2021-04-11 11:59:26 -05:00
|
|
|
// NOTE(Able): Why does it jump to 53 here? MY REASONS ARE BEYOND YOUR UNDERSTANDING MORTAL
|
2021-04-11 11:47:35 -05:00
|
|
|
'/' => 53,
|
|
|
|
'\\' => 54,
|
|
|
|
'.' => 55,
|
2022-06-02 16:56:32 -05:00
|
|
|
'U' => -210, // Backwards compatibility
|
2022-04-02 06:44:29 -05:00
|
|
|
'A'..='Z' => -(c as isize) + 64,
|
2022-04-01 18:06:47 -05:00
|
|
|
'a'..='z' => (c as isize) - 96,
|
2021-04-11 13:22:59 -05:00
|
|
|
_ => 0,
|
|
|
|
}
|
|
|
|
}
|
2021-04-27 04:09:19 -05:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2021-04-27 06:48:56 -05:00
|
|
|
#[test]
|
|
|
|
fn str_to_base55() {
|
2022-02-12 17:55:51 -06:00
|
|
|
let chrs: Vec<isize> = "AbleScript".chars().map(char2num).collect();
|
2021-04-27 04:09:19 -05:00
|
|
|
assert_eq!(chrs, &[-1, 2, 12, 5, -19, 3, 18, 9, 16, 20]);
|
|
|
|
}
|
2021-04-27 06:48:56 -05:00
|
|
|
}
|