1#![allow(
2 dead_code,
3 non_upper_case_globals,
4 unused_assignments,
5 unused_parens,
6 while_true,
7 clippy::assign_op_pattern,
8 clippy::collapsible_if,
9 clippy::comparison_chain,
10 clippy::double_parens,
11 clippy::unnecessary_cast,
12 clippy::single_match,
13 clippy::never_loop
14)]
15
16use super::buffer::{hb_buffer_t, HB_BUFFER_SCRATCH_FLAG_HAS_BROKEN_SYLLABLE};
17
18static _khmer_syllable_machine_actions: [i8; 29] = [
19 0, 1, 0, 1, 1, 1, 2, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 2, 2, 3, 2, 2, 4, 0, 0,
20];
21static _khmer_syllable_machine_key_offsets: [i16; 45] = [
22 0, 5, 8, 11, 15, 18, 21, 25, 28, 32, 35, 40, 45, 48, 51, 55, 58, 61, 65, 68, 72, 75, 90, 100,
23 103, 113, 122, 123, 129, 134, 141, 149, 158, 168, 171, 181, 190, 191, 197, 202, 209, 217, 226,
24 0, 0,
25];
26static _khmer_syllable_machine_trans_keys: [u8; 232] = [
27 20, 25, 26, 5, 6, 26, 5, 6, 15, 1, 2, 20, 26, 5, 6, 26, 5, 6, 26, 5, 6, 20, 26, 5, 6, 26, 5, 6,
28 20, 26, 5, 6, 26, 5, 6, 20, 25, 26, 5, 6, 20, 25, 26, 5, 6, 26, 5, 6, 15, 1, 2, 20, 26, 5, 6,
29 26, 5, 6, 26, 5, 6, 20, 26, 5, 6, 26, 5, 6, 20, 26, 5, 6, 26, 5, 6, 4, 15, 20, 21, 22, 23, 25,
30 26, 27, 1, 2, 5, 6, 10, 11, 4, 20, 21, 22, 23, 25, 26, 27, 5, 6, 15, 1, 2, 4, 20, 21, 22, 23,
31 25, 26, 27, 5, 6, 4, 20, 21, 22, 23, 26, 27, 5, 6, 27, 4, 23, 26, 27, 5, 6, 4, 26, 27, 5, 6, 4,
32 20, 23, 26, 27, 5, 6, 4, 20, 21, 23, 26, 27, 5, 6, 4, 20, 21, 22, 23, 26, 27, 5, 6, 4, 20, 21,
33 22, 23, 25, 26, 27, 5, 6, 15, 1, 2, 4, 20, 21, 22, 23, 25, 26, 27, 5, 6, 4, 20, 21, 22, 23, 26,
34 27, 5, 6, 27, 4, 23, 26, 27, 5, 6, 4, 26, 27, 5, 6, 4, 20, 23, 26, 27, 5, 6, 4, 20, 21, 23, 26,
35 27, 5, 6, 4, 20, 21, 22, 23, 26, 27, 5, 6, 20, 26, 5, 6, 0, 0,
36];
37static _khmer_syllable_machine_single_lengths: [i8; 45] = [
38 3, 1, 1, 2, 1, 1, 2, 1, 2, 1, 3, 3, 1, 1, 2, 1, 1, 2, 1, 2, 1, 9, 8, 1, 8, 7, 1, 4, 3, 5, 6, 7,
39 8, 1, 8, 7, 1, 4, 3, 5, 6, 7, 2, 0, 0,
40];
41static _khmer_syllable_machine_range_lengths: [i8; 45] = [
42 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
43 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0,
44];
45static _khmer_syllable_machine_index_offsets: [i16; 45] = [
46 0, 5, 8, 11, 15, 18, 21, 25, 28, 32, 35, 40, 45, 48, 51, 55, 58, 61, 65, 68, 72, 75, 88, 98,
47 101, 111, 120, 122, 128, 133, 140, 148, 157, 167, 170, 180, 189, 191, 197, 202, 209, 217, 226,
48 0, 0,
49];
50static _khmer_syllable_machine_cond_targs: [i8; 275] = [
51 27, 31, 25, 1, 21, 25, 1, 21, 26, 26, 21, 27, 25, 1, 21, 27, 4, 21, 28, 5, 21, 27, 29, 7, 21,
52 29, 7, 21, 27, 30, 9, 21, 30, 9, 21, 27, 32, 25, 1, 21, 37, 41, 35, 12, 21, 35, 12, 21, 36, 36,
53 21, 37, 35, 12, 21, 37, 15, 21, 38, 16, 21, 37, 39, 18, 21, 39, 18, 21, 37, 40, 20, 21, 40, 20,
54 21, 33, 22, 37, 39, 40, 38, 41, 35, 36, 22, 42, 32, 21, 23, 27, 29, 30, 28, 32, 25, 26, 10, 21,
55 24, 24, 21, 23, 27, 29, 30, 28, 31, 25, 26, 0, 21, 2, 27, 29, 30, 28, 25, 26, 3, 21, 26, 21, 2,
56 28, 27, 26, 4, 21, 2, 28, 26, 5, 21, 2, 27, 28, 29, 26, 6, 21, 2, 27, 29, 28, 30, 26, 8, 21,
57 23, 27, 29, 30, 28, 25, 26, 3, 21, 23, 27, 29, 30, 28, 31, 25, 26, 3, 21, 34, 34, 21, 33, 37,
58 39, 40, 38, 41, 35, 36, 11, 21, 13, 37, 39, 40, 38, 35, 36, 14, 21, 36, 21, 13, 38, 37, 36, 15,
59 21, 13, 38, 36, 16, 21, 13, 37, 38, 39, 36, 17, 21, 13, 37, 39, 38, 40, 36, 19, 21, 33, 37, 39,
60 40, 38, 35, 36, 14, 21, 37, 35, 12, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
61 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
62 21, 21, 21, 21, 21, 0, 0,
63];
64static _khmer_syllable_machine_cond_actions: [i8; 275] = [
65 5, 5, 5, 0, 15, 5, 0, 15, 0, 0, 15, 5, 5, 0, 15, 5, 0, 15, 5, 0, 15, 5, 5, 0, 15, 5, 0, 15, 5,
66 5, 0, 15, 5, 0, 15, 5, 5, 5, 0, 15, 5, 21, 21, 0, 17, 21, 0, 19, 0, 0, 17, 5, 21, 0, 17, 5, 0,
67 17, 5, 0, 17, 5, 5, 0, 17, 5, 0, 17, 5, 5, 0, 17, 5, 0, 17, 0, 5, 5, 5, 5, 5, 21, 21, 0, 5, 24,
68 5, 7, 0, 5, 5, 5, 5, 5, 5, 0, 0, 9, 5, 5, 9, 0, 5, 5, 5, 5, 5, 5, 0, 0, 9, 0, 5, 5, 5, 5, 5, 0,
69 0, 9, 0, 9, 0, 5, 5, 0, 0, 9, 0, 5, 0, 0, 9, 0, 5, 5, 5, 0, 0, 9, 0, 5, 5, 5, 5, 0, 0, 9, 0, 5,
70 5, 5, 5, 5, 0, 0, 9, 0, 5, 5, 5, 5, 5, 5, 0, 0, 9, 21, 21, 11, 0, 5, 5, 5, 5, 21, 21, 0, 0, 11,
71 0, 5, 5, 5, 5, 21, 0, 0, 11, 0, 11, 0, 5, 5, 0, 0, 11, 0, 5, 0, 0, 11, 0, 5, 5, 5, 0, 0, 11, 0,
72 5, 5, 5, 5, 0, 0, 11, 0, 5, 5, 5, 5, 21, 0, 0, 11, 5, 21, 0, 13, 15, 15, 15, 15, 15, 15, 15,
73 15, 15, 15, 15, 17, 19, 17, 17, 17, 17, 17, 17, 17, 17, 0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 11,
74 11, 11, 11, 11, 11, 11, 11, 11, 13, 0, 0,
75];
76static _khmer_syllable_machine_to_state_actions: [i8; 45] = [
77 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
78 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
79];
80static _khmer_syllable_machine_from_state_actions: [i8; 45] = [
81 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
82 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
83];
84static _khmer_syllable_machine_eof_trans: [i16; 45] = [
85 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249,
86 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268,
87 269, 270, 271, 272, 273, 0, 0,
88];
89static khmer_syllable_machine_start: i32 = 21;
90static khmer_syllable_machine_first_final: i32 = 21;
91static khmer_syllable_machine_error: i32 = -1;
92static khmer_syllable_machine_en_main: i32 = 21;
93#[derive(Clone, Copy)]
94pub enum SyllableType {
95 ConsonantSyllable = 0,
96 BrokenCluster,
97 NonKhmerCluster,
98}
99
100pub fn find_syllables_khmer(buffer: &mut hb_buffer_t) {
101 let mut cs = 0;
102 let mut ts = 0;
103 let mut te = 0;
104 let mut act = 0;
105 let mut p = 0;
106 let pe = buffer.len;
107 let eof = buffer.len;
108 let mut syllable_serial = 1u8;
109
110 macro_rules! found_syllable {
111 ($kind:expr) => {{
112 found_syllable(ts, te, &mut syllable_serial, $kind, buffer);
113 }};
114 }
115
116 {
117 cs = (khmer_syllable_machine_start) as i32;
118 ts = 0;
119 te = 0;
120 act = 0;
121 }
122
123 {
124 let mut _klen = 0;
125 let mut _trans = 0;
126 let mut _keys: i32 = 0;
127 let mut _acts: i32 = 0;
128 let mut _nacts = 0;
129 let mut __have = 0;
130 '_resume: while (p != pe || p == eof) {
131 '_again: while (true) {
132 _acts = (_khmer_syllable_machine_from_state_actions[(cs) as usize]) as i32;
133 _nacts = (_khmer_syllable_machine_actions[(_acts) as usize]) as u32;
134 _acts += 1;
135 while (_nacts > 0) {
136 match (_khmer_syllable_machine_actions[(_acts) as usize]) {
137 1 => {
138 ts = p;
139 }
140
141 _ => {}
142 }
143 _nacts -= 1;
144 _acts += 1;
145 }
146 if (p == eof) {
147 {
148 if (_khmer_syllable_machine_eof_trans[(cs) as usize] > 0) {
149 {
150 _trans =
151 (_khmer_syllable_machine_eof_trans[(cs) as usize]) as u32 - 1;
152 }
153 }
154 }
155 } else {
156 {
157 _keys = (_khmer_syllable_machine_key_offsets[(cs) as usize]) as i32;
158 _trans = (_khmer_syllable_machine_index_offsets[(cs) as usize]) as u32;
159 _klen = (_khmer_syllable_machine_single_lengths[(cs) as usize]) as i32;
160 __have = 0;
161 if (_klen > 0) {
162 {
163 let mut _lower: i32 = _keys;
164 let mut _upper: i32 = _keys + _klen - 1;
165 let mut _mid: i32 = 0;
166 while (true) {
167 if (_upper < _lower) {
168 {
169 _keys += _klen;
170 _trans += (_klen) as u32;
171 break;
172 }
173 }
174 _mid = _lower + ((_upper - _lower) >> 1);
175 if ((buffer.info[p].khmer_category() as u8)
176 < _khmer_syllable_machine_trans_keys[(_mid) as usize])
177 {
178 _upper = _mid - 1;
179 } else if ((buffer.info[p].khmer_category() as u8)
180 > _khmer_syllable_machine_trans_keys[(_mid) as usize])
181 {
182 _lower = _mid + 1;
183 } else {
184 {
185 __have = 1;
186 _trans += (_mid - _keys) as u32;
187 break;
188 }
189 }
190 }
191 }
192 }
193 _klen = (_khmer_syllable_machine_range_lengths[(cs) as usize]) as i32;
194 if (__have == 0 && _klen > 0) {
195 {
196 let mut _lower: i32 = _keys;
197 let mut _upper: i32 = _keys + (_klen << 1) - 2;
198 let mut _mid: i32 = 0;
199 while (true) {
200 if (_upper < _lower) {
201 {
202 _trans += (_klen) as u32;
203 break;
204 }
205 }
206 _mid = _lower + (((_upper - _lower) >> 1) & !1);
207 if ((buffer.info[p].khmer_category() as u8)
208 < _khmer_syllable_machine_trans_keys[(_mid) as usize])
209 {
210 _upper = _mid - 2;
211 } else if ((buffer.info[p].khmer_category() as u8)
212 > _khmer_syllable_machine_trans_keys[(_mid + 1) as usize])
213 {
214 _lower = _mid + 2;
215 } else {
216 {
217 _trans += ((_mid - _keys) >> 1) as u32;
218 break;
219 }
220 }
221 }
222 }
223 }
224 }
225 }
226 cs = (_khmer_syllable_machine_cond_targs[(_trans) as usize]) as i32;
227 if (_khmer_syllable_machine_cond_actions[(_trans) as usize] != 0) {
228 {
229 _acts = (_khmer_syllable_machine_cond_actions[(_trans) as usize]) as i32;
230 _nacts = (_khmer_syllable_machine_actions[(_acts) as usize]) as u32;
231 _acts += 1;
232 while (_nacts > 0) {
233 match (_khmer_syllable_machine_actions[(_acts) as usize]) {
234 2 => {
235 te = p + 1;
236 }
237 3 => {
238 act = 2;
239 }
240 4 => {
241 act = 3;
242 }
243 5 => {
244 te = p + 1;
245 {
246 found_syllable!(SyllableType::NonKhmerCluster);
247 }
248 }
249 6 => {
250 te = p;
251 p = p - 1;
252 {
253 found_syllable!(SyllableType::ConsonantSyllable);
254 }
255 }
256 7 => {
257 te = p;
258 p = p - 1;
259 {
260 found_syllable!(SyllableType::BrokenCluster);
261 buffer.scratch_flags |=
262 HB_BUFFER_SCRATCH_FLAG_HAS_BROKEN_SYLLABLE;
263 }
264 }
265 8 => {
266 te = p;
267 p = p - 1;
268 {
269 found_syllable!(SyllableType::NonKhmerCluster);
270 }
271 }
272 9 => {
273 p = (te) - 1;
274 {
275 found_syllable!(SyllableType::ConsonantSyllable);
276 }
277 }
278 10 => {
279 p = (te) - 1;
280 {
281 found_syllable!(SyllableType::BrokenCluster);
282 buffer.scratch_flags |=
283 HB_BUFFER_SCRATCH_FLAG_HAS_BROKEN_SYLLABLE;
284 }
285 }
286 11 => match (act) {
287 2 => {
288 p = (te) - 1;
289 {
290 found_syllable!(SyllableType::BrokenCluster);
291 buffer.scratch_flags |=
292 HB_BUFFER_SCRATCH_FLAG_HAS_BROKEN_SYLLABLE;
293 }
294 }
295 3 => {
296 p = (te) - 1;
297 {
298 found_syllable!(SyllableType::NonKhmerCluster);
299 }
300 }
301
302 _ => {}
303 },
304
305 _ => {}
306 }
307 _nacts -= 1;
308 _acts += 1;
309 }
310 }
311 }
312 break '_again;
313 }
314 if (p == eof) {
315 {
316 if (cs >= 21) {
317 break '_resume;
318 }
319 }
320 } else {
321 {
322 _acts = (_khmer_syllable_machine_to_state_actions[(cs) as usize]) as i32;
323 _nacts = (_khmer_syllable_machine_actions[(_acts) as usize]) as u32;
324 _acts += 1;
325 while (_nacts > 0) {
326 match (_khmer_syllable_machine_actions[(_acts) as usize]) {
327 0 => {
328 ts = 0;
329 }
330
331 _ => {}
332 }
333 _nacts -= 1;
334 _acts += 1;
335 }
336 p += 1;
337 continue '_resume;
338 }
339 }
340 break '_resume;
341 }
342 }
343}
344
345#[inline]
346fn found_syllable(
347 start: usize,
348 end: usize,
349 syllable_serial: &mut u8,
350 kind: SyllableType,
351 buffer: &mut hb_buffer_t,
352) {
353 for i: usize in start..end {
354 buffer.info[i].set_syllable((*syllable_serial << 4) | kind as u8);
355 }
356
357 *syllable_serial += 1;
358
359 if *syllable_serial == 16 {
360 *syllable_serial = 1;
361 }
362}
363