able-script/ablescript/src/base_55.rs

24 lines
590 B
Rust
Raw Normal View History

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,
// 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-04-01 18:06:47 -05:00
'U' => -210,
'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,
}
}
#[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();
assert_eq!(chrs, &[-1, 2, 12, 5, -19, 3, 18, 9, 16, 20]);
}
2021-04-27 06:48:56 -05:00
}