khash/
map.rs

1use std::ops::RangeInclusive;
2
3/// All valid kana for the digest
4pub const KANA: &[char; 92] = &[
5    'あ', 'い', 'う', 'え', 'お',
6    'か', 'き', 'く', 'け', 'こ',
7    'さ', 'し', 'す', 'せ', 'そ',
8    'た', 'ち', 'つ', 'て', 'と',
9    'な', 'に', 'ぬ', 'ね', 'の',
10    'は', 'ひ', 'ふ', 'へ', 'ほ',
11    'ま', 'み', 'む', 'め', 'も',
12    'ら', 'り', 'る', 'れ', 'ろ',
13    'や', 'ゆ', 'よ', 'わ', 'ん',
14    'を', //45
15    'ア', 'イ', 'ウ', 'エ', 'オ',
16    'カ', 'キ', 'ク', 'ケ', 'コ',
17    'サ', 'シ', 'ス', 'セ', 'ソ', 
18    'タ', 'チ', 'ツ', 'テ', 'ト', 
19    'ナ', 'ニ', 'ヌ', 'ネ', 'ノ', 
20    'ハ', 'ヒ', 'フ', 'ヘ', 'ホ', 
21    'マ', 'ミ', 'ム', 'メ', 'モ', 
22    'ラ', 'リ', 'ル', 'レ', 'ロ', 
23    'ヤ', 'ユ', 'ヨ', 'ワ', 'ン',
24    'ヲ', //91 
25];
26
27/// Valid kana for the first swap table
28pub const KANA_SWAP: &[Option<char>; 92] = &[
29    None, None, None, None, None, //a
30    Some('が'), Some('ぎ'), Some('ぐ'), Some('げ'), Some('ご'), //ka
31    None, None, None, None, None, //sa
32    Some('だ'), Some('ぢ'), Some('づ'), Some('で'), Some('ど'), //ta
33    None, None, None, None, None, //na
34    Some('ば'), Some('び'), Some('ぶ'), Some('べ'), Some('ぼ'), // ha
35    None, None, None, None, None, //ma
36    None, None, None, None, None, //ra
37    None, None, None, None, None, //ya
38    None, //wo (45)
39    None, None, None, None, None, //a
40    Some('ガ'), Some('ギ'), Some('グ'), Some('ゲ'), Some('ゴ'), //ka
41    None, None, None, None, None, //sa
42    Some('ダ'), Some('ヂ'), Some('ヅ'), Some('デ'), Some('ド'), //ta
43    None, None, None, None, None, //na
44    Some('バ'), Some('ビ'), Some('ブ'), Some('ベ'), Some('ボ'), // ha
45    None, None, None, None, None, //ma
46    None, None, None, None, None, //ra
47    None, None, None, None, None, //ya    
48    None, //wo (91)
49];
50
51/// Valid kana for the 2nd swap table
52pub const KANA_SWAP2: &[Option<char>; 92] = &[
53    None, None, None, None, None, //a
54    None, None, None, None, None, //ka
55    None, None, None, None, None, //sa
56    None, None, None, None, None, //ta
57    None, None, None, None, None, //na
58    Some('ぱ'), Some('ぴ'), Some('ぽ'), Some('ぺ'), Some('ぽ'), //ha
59    None, None, None, None, None, //ma
60    None, None, None, None, None, //ra
61    None, None, None, None, None, //ya
62    None, //wo (45)
63    None, None, None, None, None, //a
64    None, None, None, None, None, //ka
65    None, None, None, None, None, //sa
66    None, None, None, None, None, //ta
67    None, None, None, None, None, //na
68    Some('パ'), Some('ピ'), Some('プ'), Some('ペ'), Some('ポ'), //ha
69    None, None, None, None, None, //ma
70    None, None, None, None, None, //ra
71    None, None, None, None, None, //ya
72    None, //wo (91)
73];
74
75/// Ranges for the sign0 test
76pub const KANA_SIGN: &[RangeInclusive<usize>; 2] = &[
77    0..=45,
78    46..=91,
79];
80
81/// Valid kana for the subscript
82pub const KANA_SUB: &[char; 18] = &[
83    'ゃ',
84    'ゅ',
85    'ょ',
86    'ャ',
87    'ュ',
88    'ョ',
89    'っ',
90    'ッ',
91    'ぁ','ぃ','ぅ','ぇ','ぉ',
92    'ァ','ィ','ゥ','ェ','ォ',
93];
94
95use crate::def::Definition;
96
97/// Valid ranges for the subscript from the kana table
98pub const KANA_SUB_VALID_FOR: &[Definition; 18] = &[ // Should we properly restrict these to only ones that make sense? (i.e. KI SHI HI etc..)
99    Definition::single(5..=39),
100    Definition::single(5..=39),
101    Definition::single(5..=39),
102    Definition::single(51..=85),
103    Definition::single(51..=85),
104    Definition::single(51..=85),
105    
106    Definition::single(0..=45),
107    Definition::single(46..=91),
108    
109    Definition::single(5..=39),
110    Definition::single(5..=39),
111    Definition::single(5..=39),
112    Definition::single(5..=39),
113    Definition::single(5..=39),
114    Definition::single(51..=85),
115    Definition::single(51..=85),
116    Definition::single(51..=85),
117    Definition::single(51..=85),
118    Definition::single(51..=85),
119];
120
121/// Find all subs that are okay for this kana. If `kana` is not in `KANA`, return None.
122pub fn find_sub(kana: char) -> Option<Vec<char>>
123{
124    for (i,x) in (0..(KANA.len())).zip(KANA.iter()) {
125	if *x == kana {
126	    let mut output = Vec::with_capacity(KANA_SUB.len());
127	    for (def,sub) in KANA_SUB_VALID_FOR.iter().zip(KANA_SUB.iter())
128	    {
129		if def.contains(i) {
130		    output.push(sub.clone());
131		}
132	    }
133	    return Some(output);
134	}
135    }
136    None
137}
138
139/// Find subs by index.
140pub fn sub(i: usize) -> Option<[Option<char>; KANA_SUB.len()]>
141{
142    if i < KANA.len() {
143	let mut output = [None; KANA_SUB.len()];
144	for (j, (def,sub)) in (0..).zip(KANA_SUB_VALID_FOR.iter().zip(KANA_SUB.iter()))
145	{
146	    if def.contains(i) {
147		output[j] = Some(sub.clone());
148	    }
149	}
150	Some(output)
151    } else {
152	None
153    }
154}
155
156/// Get all valid subs for kana at index `i`.
157pub fn sub_all(i: usize) -> Option<Vec<char>>
158{
159    if i < KANA.len() {
160	let mut output = Vec::with_capacity(KANA_SUB.len());
161	for (def,sub) in KANA_SUB_VALID_FOR.iter().zip(KANA_SUB.iter())
162	{
163	    if def.contains(i) {
164		output.push(sub.clone());
165	    }
166	}
167	Some(output)
168    } else {
169	None
170    }
171}