diff options
| author | tslil clingman <tslil@posteo.de> | 2022-09-25 00:12:14 +0200 |
|---|---|---|
| committer | tslil clingman <tslil@posteo.de> | 2022-09-25 00:12:14 +0200 |
| commit | 1cac34b7ea939e0d0d1157de59e90c70b2831812 (patch) | |
| tree | a862e3bbc8b5b5175353e660b9efcdba2c9137ab /src/config.rs | |
| parent | 5ec1655971087ae556d3fc27e7b8a1eaa23944c5 (diff) | |
More efficient?
Diffstat (limited to 'src/config.rs')
| -rw-r--r-- | src/config.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..4449b7b --- /dev/null +++ b/src/config.rs @@ -0,0 +1,41 @@ +pub const NUM_KEYS: usize = 30; // you should not change this + +pub const KEY_CHARS: [char; NUM_KEYS] = [ + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', + 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '/', '.', ',', '\'', +]; + +pub const KEY_TO_FINGER: [usize; NUM_KEYS] = [ + 0, 1, 2, 3, 3, 4, 4, 5, 6, 7, 0, 1, 2, 3, 3, 4, 4, 5, 6, 7, 0, 1, 2, 3, 3, 4, 4, 5, 6, 7, +]; + +pub fn canonicalise(inp: char) -> Option<char> { + if inp.is_ascii_alphabetic() { + return Some(inp.to_ascii_uppercase()); + } else { + match inp { + '.' => Some('.'), + '>' => Some('.'), + ',' => Some(','), + '<' => Some(','), + '/' => Some('/'), + '?' => Some('/'), + '\'' => Some('\''), + '"' => Some('\''), + _ => None, + } + } +} + +const fn build_lookup_table() -> [usize; 128] { + let mut result = [0; 128]; + let mut i = 0; + + while i < NUM_KEYS { + result[KEY_CHARS[i] as usize] = i; + i += 1; + } + return result; +} + +pub const CHAR_TO_INDEX: [usize; 128] = build_lookup_table(); |
