Skip to main content

icu_normalizer/
harfbuzz.rs

1// This file is part of ICU4X. For terms of use, please see the file
2// called LICENSE at the top level of the ICU4X source tree
3// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4
5use crate::properties::{
6    CanonicalCombiningClassMap, CanonicalCombiningClassMapBorrowed, CanonicalComposition,
7    CanonicalCompositionBorrowed, CanonicalDecomposition, CanonicalDecompositionBorrowed,
8    Decomposed,
9};
10use harfbuzz_traits::{CombiningClassFunc, ComposeFunc, DecomposeFunc};
11
12/// ✨ *Enabled with the `harfbuzz_traits` Cargo feature.*
13impl ComposeFunc for CanonicalCompositionBorrowed<'_> {
14    fn compose(&self, a: char, b: char) -> Option<char> {
15        CanonicalCompositionBorrowed::compose(*self, a, b)
16    }
17}
18
19/// ✨ *Enabled with the `harfbuzz_traits` Cargo feature.*
20impl ComposeFunc for CanonicalComposition {
21    fn compose(&self, a: char, b: char) -> Option<char> {
22        ComposeFunc::compose(&self.as_borrowed(), a, b)
23    }
24}
25
26/// ✨ *Enabled with the `harfbuzz_traits` Cargo feature.*
27impl ComposeFunc for &'_ CanonicalComposition {
28    fn compose(&self, a: char, b: char) -> Option<char> {
29        ComposeFunc::compose(&self.as_borrowed(), a, b)
30    }
31}
32
33/// ✨ *Enabled with the `harfbuzz_traits` Cargo feature.*
34impl DecomposeFunc for CanonicalDecompositionBorrowed<'_> {
35    fn decompose(&self, ab: char) -> Option<(char, char)> {
36        match CanonicalDecompositionBorrowed::decompose(self, ab) {
37            Decomposed::Default => None,
38            Decomposed::Expansion(first, second) => Some((first, second)),
39            Decomposed::Singleton(single) => Some((single, '\0')),
40        }
41    }
42}
43
44/// ✨ *Enabled with the `harfbuzz_traits` Cargo feature.*
45impl DecomposeFunc for CanonicalDecomposition {
46    fn decompose(&self, ab: char) -> Option<(char, char)> {
47        DecomposeFunc::decompose(&self.as_borrowed(), ab)
48    }
49}
50
51/// ✨ *Enabled with the `harfbuzz_traits` Cargo feature.*
52impl DecomposeFunc for &'_ CanonicalDecomposition {
53    fn decompose(&self, ab: char) -> Option<(char, char)> {
54        DecomposeFunc::decompose(&self.as_borrowed(), ab)
55    }
56}
57
58/// ✨ *Enabled with the `harfbuzz_traits` Cargo feature.*
59impl CombiningClassFunc for CanonicalCombiningClassMapBorrowed<'_> {
60    fn combining_class(&self, ch: char) -> u8 {
61        self.get_u8(ch)
62    }
63}
64
65/// ✨ *Enabled with the `harfbuzz_traits` Cargo feature.*
66impl CombiningClassFunc for CanonicalCombiningClassMap {
67    fn combining_class(&self, ch: char) -> u8 {
68        CombiningClassFunc::combining_class(&self.as_borrowed(), ch)
69    }
70}
71
72/// ✨ *Enabled with the `harfbuzz_traits` Cargo feature.*
73impl CombiningClassFunc for &'_ CanonicalCombiningClassMap {
74    fn combining_class(&self, ch: char) -> u8 {
75        CombiningClassFunc::combining_class(&self.as_borrowed(), ch)
76    }
77}