]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/collationfcd.h
2 *******************************************************************************
3 * Copyright (C) 2012-2014, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
8 * created on: 2012aug18
9 * created by: Markus W. Scherer
12 #ifndef __COLLATIONFCD_H__
13 #define __COLLATIONFCD_H__
15 #include "unicode/utypes.h"
17 #if !UCONFIG_NO_COLLATION
19 #include "unicode/utf16.h"
24 * Data and functions for the FCD check fast path.
26 * The fast path looks at a pair of 16-bit code units and checks
27 * whether there is an FCD boundary between them;
28 * there is if the first unit has a trailing ccc=0 (!hasTccc(first))
29 * or the second unit has a leading ccc=0 (!hasLccc(second)),
31 * When the fast path finds a possible non-boundary,
32 * then the FCD check slow path looks at the actual sequence of FCD values.
34 * This is a pure optimization.
35 * The fast path must at least find all possible non-boundaries.
36 * If the fast path is too pessimistic, it costs performance.
38 * For a pair of BMP characters, the fast path tests are precise (1 bit per character).
40 * For a supplementary code point, the two units are its lead and trail surrogates.
41 * We set hasTccc(lead)=true if any of its 1024 associated supplementary code points
42 * has lccc!=0 or tccc!=0.
43 * We set hasLccc(trail)=true for all trail surrogates.
44 * As a result, we leave the fast path if the lead surrogate might start a
45 * supplementary code point that is not FCD-inert.
46 * (So the fast path need not detect that there is a surrogate pair,
47 * nor look ahead to the next full code point.)
49 * hasLccc(lead)=true if any of its 1024 associated supplementary code points
50 * has lccc!=0, for fast boundary checking between BMP & supplementary.
52 * hasTccc(trail)=false:
53 * It should only be tested for unpaired trail surrogates which are FCD-inert.
55 class U_I18N_API CollationFCD
{
57 static inline UBool
hasLccc(UChar32 c
) {
59 // c can be negative, e.g., U_SENTINEL from UCharIterator;
60 // that is handled in the first test.
63 // U+0300 is the first character with lccc!=0.
65 (i
= lcccIndex
[c
>> 5]) != 0 &&
66 (lcccBits
[i
] & ((uint32_t)1 << (c
& 0x1f))) != 0;
69 static inline UBool
hasTccc(UChar32 c
) {
71 // c can be negative, e.g., U_SENTINEL from UCharIterator;
72 // that is handled in the first test.
75 // U+00C0 is the first character with tccc!=0.
77 (i
= tcccIndex
[c
>> 5]) != 0 &&
78 (tcccBits
[i
] & ((uint32_t)1 << (c
& 0x1f))) != 0;
81 static inline UBool
mayHaveLccc(UChar32 c
) {
82 // Handles all of Unicode 0..10FFFF.
83 // c can be negative, e.g., U_SENTINEL.
84 // U+0300 is the first character with lccc!=0.
85 if(c
< 0x300) { return FALSE
; }
86 if(c
> 0xffff) { c
= U16_LEAD(c
); }
89 (i
= lcccIndex
[c
>> 5]) != 0 &&
90 (lcccBits
[i
] & ((uint32_t)1 << (c
& 0x1f))) != 0;
94 * Tibetan composite vowel signs (U+0F73, U+0F75, U+0F81)
95 * must be decomposed before reaching the core collation code,
96 * or else some sequences including them, even ones passing the FCD check,
97 * do not yield canonically equivalent results.
99 * This is a fast and imprecise test.
101 * @param c a code point
102 * @return TRUE if c is U+0F73, U+0F75 or U+0F81 or one of several other Tibetan characters
104 static inline UBool
maybeTibetanCompositeVowel(UChar32 c
) {
105 return (c
& 0x1fff01) == 0xf01;
109 * Tibetan composite vowel signs (U+0F73, U+0F75, U+0F81)
110 * must be decomposed before reaching the core collation code,
111 * or else some sequences including them, even ones passing the FCD check,
112 * do not yield canonically equivalent results.
114 * They have distinct lccc/tccc combinations: 129/130 or 129/132.
116 * @param fcd16 the FCD value (lccc/tccc combination) of a code point
117 * @return TRUE if fcd16 is from U+0F73, U+0F75 or U+0F81
119 static inline UBool
isFCD16OfTibetanCompositeVowel(uint16_t fcd16
) {
120 return fcd16
== 0x8182 || fcd16
== 0x8184;
124 CollationFCD(); // No instantiation.
126 static const uint8_t lcccIndex
[2048];
127 static const uint8_t tcccIndex
[2048];
128 static const uint32_t lcccBits
[];
129 static const uint32_t tcccBits
[];
134 #endif // !UCONFIG_NO_COLLATION
135 #endif // __COLLATIONFCD_H__