1/*!
2
3This library implements
4[Unicode Canonical Combining Class](https://unicode.org/reports/tr44/#Canonical_Combining_Class_Values) detection.
5
6```rust
7use unicode_ccc::*;
8
9assert_eq!(get_canonical_combining_class('A'), CanonicalCombiningClass::NotReordered);
10assert_eq!(get_canonical_combining_class('\u{0A3C}'), CanonicalCombiningClass::Nukta);
11assert_eq!(get_canonical_combining_class('\u{18A9}'), CanonicalCombiningClass::AboveLeft);
12```
13
14*/
15
16#![no_std]
17#![doc(html_root_url = "https://docs.rs/unicode-ccc/0.1.2")]
18
19#![forbid(unsafe_code)]
20
21/// The Unicode version.
22pub const UNICODE_VERSION: (u8, u8, u8) = (13, 0, 0);
23
24/// Character Canonical Combining Class.
25#[derive(Clone, Copy, PartialEq, Debug)]
26pub enum CanonicalCombiningClass {
27 NotReordered = 0,
28 Overlay = 1,
29 HanReading = 6,
30 Nukta = 7,
31 KanaVoicing = 8,
32 Virama = 9,
33 // Hebrew
34 CCC10 = 10,
35 CCC11 = 11,
36 CCC12 = 12,
37 CCC13 = 13,
38 CCC14 = 14,
39 CCC15 = 15,
40 CCC16 = 16,
41 CCC17 = 17,
42 CCC18 = 18,
43 CCC19 = 19,
44 CCC20 = 20,
45 CCC21 = 21,
46 CCC22 = 22,
47 CCC23 = 23,
48 CCC24 = 24,
49 CCC25 = 25,
50 CCC26 = 26,
51 // Arabic
52 CCC27 = 27,
53 CCC28 = 28,
54 CCC29 = 29,
55 CCC30 = 30,
56 CCC31 = 31,
57 CCC32 = 32,
58 CCC33 = 33,
59 CCC34 = 34,
60 CCC35 = 35,
61 // Syriac
62 CCC36 = 36,
63 // Telugu
64 CCC84 = 84,
65 CCC91 = 91,
66 // Thai
67 CCC103 = 103,
68 CCC107 = 107,
69 // Lao
70 CCC118 = 118,
71 CCC122 = 122,
72 // Tibetan
73 CCC129 = 129,
74 CCC130 = 130,
75 CCC132 = 132,
76 AttachedBelowLeft = 200,
77 AttachedBelow = 202,
78 AttachedAbove = 214,
79 AttachedAboveRight = 216,
80 BelowLeft = 218,
81 Below = 220,
82 BelowRight = 222,
83 Left = 224,
84 Right = 226,
85 AboveLeft = 228,
86 Above = 230,
87 AboveRight = 232,
88 DoubleBelow = 233,
89 DoubleAbove = 234,
90 IotaSubscript = 240,
91}
92
93/// Returns a Canonical Combining Class of a character.
94///
95/// Based on <https://www.unicode.org/Public/13.0.0/ucd/extracted/DerivedCombiningClass.txt>.
96pub fn get_canonical_combining_class(c: char) -> CanonicalCombiningClass {
97 use CanonicalCombiningClass::*;
98
99 match c as u32 {
100 0x0334..=0x0338 => Overlay,
101 0x1CD4 => Overlay,
102 0x1CE2..=0x1CE8 => Overlay,
103 0x20D2..=0x20D3 => Overlay,
104 0x20D8..=0x20DA => Overlay,
105 0x20E5..=0x20E6 => Overlay,
106 0x20EA..=0x20EB => Overlay,
107 0x10A39 => Overlay,
108 0x16AF0..=0x16AF4 => Overlay,
109 0x1BC9E => Overlay,
110 0x1D167..=0x1D169 => Overlay,
111 0x16FF0..=0x16FF1 => HanReading,
112 0x093C => Nukta,
113 0x09BC => Nukta,
114 0x0A3C => Nukta,
115 0x0ABC => Nukta,
116 0x0B3C => Nukta,
117 0x0CBC => Nukta,
118 0x1037 => Nukta,
119 0x1B34 => Nukta,
120 0x1BE6 => Nukta,
121 0x1C37 => Nukta,
122 0xA9B3 => Nukta,
123 0x110BA => Nukta,
124 0x11173 => Nukta,
125 0x111CA => Nukta,
126 0x11236 => Nukta,
127 0x112E9 => Nukta,
128 0x1133B..=0x1133C => Nukta,
129 0x11446 => Nukta,
130 0x114C3 => Nukta,
131 0x115C0 => Nukta,
132 0x116B7 => Nukta,
133 0x1183A => Nukta,
134 0x11943 => Nukta,
135 0x11D42 => Nukta,
136 0x1E94A => Nukta,
137 0x3099..=0x309A => KanaVoicing,
138 0x094D => Virama,
139 0x09CD => Virama,
140 0x0A4D => Virama,
141 0x0ACD => Virama,
142 0x0B4D => Virama,
143 0x0BCD => Virama,
144 0x0C4D => Virama,
145 0x0CCD => Virama,
146 0x0D3B..=0x0D3C => Virama,
147 0x0D4D => Virama,
148 0x0DCA => Virama,
149 0x0E3A => Virama,
150 0x0EBA => Virama,
151 0x0F84 => Virama,
152 0x1039..=0x103A => Virama,
153 0x1714 => Virama,
154 0x1734 => Virama,
155 0x17D2 => Virama,
156 0x1A60 => Virama,
157 0x1B44 => Virama,
158 0x1BAA => Virama,
159 0x1BAB => Virama,
160 0x1BF2..=0x1BF3 => Virama,
161 0x2D7F => Virama,
162 0xA806 => Virama,
163 0xA82C => Virama,
164 0xA8C4 => Virama,
165 0xA953 => Virama,
166 0xA9C0 => Virama,
167 0xAAF6 => Virama,
168 0xABED => Virama,
169 0x10A3F => Virama,
170 0x11046 => Virama,
171 0x1107F => Virama,
172 0x110B9 => Virama,
173 0x11133..=0x11134 => Virama,
174 0x111C0 => Virama,
175 0x11235 => Virama,
176 0x112EA => Virama,
177 0x1134D => Virama,
178 0x11442 => Virama,
179 0x114C2 => Virama,
180 0x115BF => Virama,
181 0x1163F => Virama,
182 0x116B6 => Virama,
183 0x1172B => Virama,
184 0x11839 => Virama,
185 0x1193D => Virama,
186 0x1193E => Virama,
187 0x119E0 => Virama,
188 0x11A34 => Virama,
189 0x11A47 => Virama,
190 0x11A99 => Virama,
191 0x11C3F => Virama,
192 0x11D44..=0x11D45 => Virama,
193 0x11D97 => Virama,
194 0x05B0 => CCC10,
195 0x05B1 => CCC11,
196 0x05B2 => CCC12,
197 0x05B3 => CCC13,
198 0x05B4 => CCC14,
199 0x05B5 => CCC15,
200 0x05B6 => CCC16,
201 0x05B7 => CCC17,
202 0x05B8 => CCC18,
203 0x05C7 => CCC18,
204 0x05B9..=0x05BA => CCC19,
205 0x05BB => CCC20,
206 0x05BC => CCC21,
207 0x05BD => CCC22,
208 0x05BF => CCC23,
209 0x05C1 => CCC24,
210 0x05C2 => CCC25,
211 0xFB1E => CCC26,
212 0x064B => CCC27,
213 0x08F0 => CCC27,
214 0x064C => CCC28,
215 0x08F1 => CCC28,
216 0x064D => CCC29,
217 0x08F2 => CCC29,
218 0x0618 => CCC30,
219 0x064E => CCC30,
220 0x0619 => CCC31,
221 0x064F => CCC31,
222 0x061A => CCC32,
223 0x0650 => CCC32,
224 0x0651 => CCC33,
225 0x0652 => CCC34,
226 0x0670 => CCC35,
227 0x0711 => CCC36,
228 0x0C55 => CCC84,
229 0x0C56 => CCC91,
230 0x0E38..=0x0E39 => CCC103,
231 0x0E48..=0x0E4B => CCC107,
232 0x0EB8..=0x0EB9 => CCC118,
233 0x0EC8..=0x0ECB => CCC122,
234 0x0F71 => CCC129,
235 0x0F72 => CCC130,
236 0x0F7A..=0x0F7D => CCC130,
237 0x0F80 => CCC130,
238 0x0F74 => CCC132,
239 0x0321..=0x0322 => AttachedBelow,
240 0x0327..=0x0328 => AttachedBelow,
241 0x1DD0 => AttachedBelow,
242 0x1DCE => AttachedAbove,
243 0x031B => AttachedAboveRight,
244 0x0F39 => AttachedAboveRight,
245 0x1D165..=0x1D166 => AttachedAboveRight,
246 0x1D16E..=0x1D172 => AttachedAboveRight,
247 0x302A => BelowLeft,
248 0x0316..=0x0319 => Below,
249 0x031C..=0x0320 => Below,
250 0x0323..=0x0326 => Below,
251 0x0329..=0x0333 => Below,
252 0x0339..=0x033C => Below,
253 0x0347..=0x0349 => Below,
254 0x034D..=0x034E => Below,
255 0x0353..=0x0356 => Below,
256 0x0359..=0x035A => Below,
257 0x0591 => Below,
258 0x0596 => Below,
259 0x059B => Below,
260 0x05A2..=0x05A7 => Below,
261 0x05AA => Below,
262 0x05C5 => Below,
263 0x0655..=0x0656 => Below,
264 0x065C => Below,
265 0x065F => Below,
266 0x06E3 => Below,
267 0x06EA => Below,
268 0x06ED => Below,
269 0x0731 => Below,
270 0x0734 => Below,
271 0x0737..=0x0739 => Below,
272 0x073B..=0x073C => Below,
273 0x073E => Below,
274 0x0742 => Below,
275 0x0744 => Below,
276 0x0746 => Below,
277 0x0748 => Below,
278 0x07F2 => Below,
279 0x07FD => Below,
280 0x0859..=0x085B => Below,
281 0x08D3 => Below,
282 0x08E3 => Below,
283 0x08E6 => Below,
284 0x08E9 => Below,
285 0x08ED..=0x08EF => Below,
286 0x08F6 => Below,
287 0x08F9..=0x08FA => Below,
288 0x0952 => Below,
289 0x0F18..=0x0F19 => Below,
290 0x0F35 => Below,
291 0x0F37 => Below,
292 0x0FC6 => Below,
293 0x108D => Below,
294 0x193B => Below,
295 0x1A18 => Below,
296 0x1A7F => Below,
297 0x1AB5..=0x1ABA => Below,
298 0x1ABD => Below,
299 0x1ABF..=0x1AC0 => Below,
300 0x1B6C => Below,
301 0x1CD5..=0x1CD9 => Below,
302 0x1CDC..=0x1CDF => Below,
303 0x1CED => Below,
304 0x1DC2 => Below,
305 0x1DCA => Below,
306 0x1DCF => Below,
307 0x1DF9 => Below,
308 0x1DFD => Below,
309 0x1DFF => Below,
310 0x20E8 => Below,
311 0x20EC..=0x20EF => Below,
312 0xA92B..=0xA92D => Below,
313 0xAAB4 => Below,
314 0xFE27..=0xFE2D => Below,
315 0x101FD => Below,
316 0x102E0 => Below,
317 0x10A0D => Below,
318 0x10A3A => Below,
319 0x10AE6 => Below,
320 0x10F46..=0x10F47 => Below,
321 0x10F4B => Below,
322 0x10F4D..=0x10F50 => Below,
323 0x1D17B..=0x1D182 => Below,
324 0x1D18A..=0x1D18B => Below,
325 0x1E8D0..=0x1E8D6 => Below,
326 0x059A => BelowRight,
327 0x05AD => BelowRight,
328 0x1939 => BelowRight,
329 0x302D => BelowRight,
330 0x302E..=0x302F => Left,
331 0x1D16D => Right,
332 0x05AE => AboveLeft,
333 0x18A9 => AboveLeft,
334 0x1DF7..=0x1DF8 => AboveLeft,
335 0x302B => AboveLeft,
336 0x0300..=0x0314 => Above,
337 0x033D..=0x0344 => Above,
338 0x0346 => Above,
339 0x034A..=0x034C => Above,
340 0x0350..=0x0352 => Above,
341 0x0357 => Above,
342 0x035B => Above,
343 0x0363..=0x036F => Above,
344 0x0483..=0x0487 => Above,
345 0x0592..=0x0595 => Above,
346 0x0597..=0x0599 => Above,
347 0x059C..=0x05A1 => Above,
348 0x05A8..=0x05A9 => Above,
349 0x05AB..=0x05AC => Above,
350 0x05AF => Above,
351 0x05C4 => Above,
352 0x0610..=0x0617 => Above,
353 0x0653..=0x0654 => Above,
354 0x0657..=0x065B => Above,
355 0x065D..=0x065E => Above,
356 0x06D6..=0x06DC => Above,
357 0x06DF..=0x06E2 => Above,
358 0x06E4 => Above,
359 0x06E7..=0x06E8 => Above,
360 0x06EB..=0x06EC => Above,
361 0x0730 => Above,
362 0x0732..=0x0733 => Above,
363 0x0735..=0x0736 => Above,
364 0x073A => Above,
365 0x073D => Above,
366 0x073F..=0x0741 => Above,
367 0x0743 => Above,
368 0x0745 => Above,
369 0x0747 => Above,
370 0x0749..=0x074A => Above,
371 0x07EB..=0x07F1 => Above,
372 0x07F3 => Above,
373 0x0816..=0x0819 => Above,
374 0x081B..=0x0823 => Above,
375 0x0825..=0x0827 => Above,
376 0x0829..=0x082D => Above,
377 0x08D4..=0x08E1 => Above,
378 0x08E4..=0x08E5 => Above,
379 0x08E7..=0x08E8 => Above,
380 0x08EA..=0x08EC => Above,
381 0x08F3..=0x08F5 => Above,
382 0x08F7..=0x08F8 => Above,
383 0x08FB..=0x08FF => Above,
384 0x0951 => Above,
385 0x0953..=0x0954 => Above,
386 0x09FE => Above,
387 0x0F82..=0x0F83 => Above,
388 0x0F86..=0x0F87 => Above,
389 0x135D..=0x135F => Above,
390 0x17DD => Above,
391 0x193A => Above,
392 0x1A17 => Above,
393 0x1A75..=0x1A7C => Above,
394 0x1AB0..=0x1AB4 => Above,
395 0x1ABB..=0x1ABC => Above,
396 0x1B6B => Above,
397 0x1B6D..=0x1B73 => Above,
398 0x1CD0..=0x1CD2 => Above,
399 0x1CDA..=0x1CDB => Above,
400 0x1CE0 => Above,
401 0x1CF4 => Above,
402 0x1CF8..=0x1CF9 => Above,
403 0x1DC0..=0x1DC1 => Above,
404 0x1DC3..=0x1DC9 => Above,
405 0x1DCB..=0x1DCC => Above,
406 0x1DD1..=0x1DF5 => Above,
407 0x1DFB => Above,
408 0x1DFE => Above,
409 0x20D0..=0x20D1 => Above,
410 0x20D4..=0x20D7 => Above,
411 0x20DB..=0x20DC => Above,
412 0x20E1 => Above,
413 0x20E7 => Above,
414 0x20E9 => Above,
415 0x20F0 => Above,
416 0x2CEF..=0x2CF1 => Above,
417 0x2DE0..=0x2DFF => Above,
418 0xA66F => Above,
419 0xA674..=0xA67D => Above,
420 0xA69E..=0xA69F => Above,
421 0xA6F0..=0xA6F1 => Above,
422 0xA8E0..=0xA8F1 => Above,
423 0xAAB0 => Above,
424 0xAAB2..=0xAAB3 => Above,
425 0xAAB7..=0xAAB8 => Above,
426 0xAABE..=0xAABF => Above,
427 0xAAC1 => Above,
428 0xFE20..=0xFE26 => Above,
429 0xFE2E..=0xFE2F => Above,
430 0x10376..=0x1037A => Above,
431 0x10A0F => Above,
432 0x10A38 => Above,
433 0x10AE5 => Above,
434 0x10D24..=0x10D27 => Above,
435 0x10EAB..=0x10EAC => Above,
436 0x10F48..=0x10F4A => Above,
437 0x10F4C => Above,
438 0x11100..=0x11102 => Above,
439 0x11366..=0x1136C => Above,
440 0x11370..=0x11374 => Above,
441 0x1145E => Above,
442 0x16B30..=0x16B36 => Above,
443 0x1D185..=0x1D189 => Above,
444 0x1D1AA..=0x1D1AD => Above,
445 0x1D242..=0x1D244 => Above,
446 0x1E000..=0x1E006 => Above,
447 0x1E008..=0x1E018 => Above,
448 0x1E01B..=0x1E021 => Above,
449 0x1E023..=0x1E024 => Above,
450 0x1E026..=0x1E02A => Above,
451 0x1E130..=0x1E136 => Above,
452 0x1E2EC..=0x1E2EF => Above,
453 0x1E944..=0x1E949 => Above,
454 0x0315 => AboveRight,
455 0x031A => AboveRight,
456 0x0358 => AboveRight,
457 0x1DF6 => AboveRight,
458 0x302C => AboveRight,
459 0x035C => DoubleBelow,
460 0x035F => DoubleBelow,
461 0x0362 => DoubleBelow,
462 0x1DFC => DoubleBelow,
463 0x035D..=0x035E => DoubleAbove,
464 0x0360..=0x0361 => DoubleAbove,
465 0x1DCD => DoubleAbove,
466 0x0345 => IotaSubscript,
467 _ => NotReordered,
468 }
469}
470