| 1 |
. |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#ifndef __COLLATIONDATA_H__ |
| 15 |
#define __COLLATIONDATA_H__ |
| 16 |
|
| 17 |
#include "unicode/utypes.h" |
| 18 |
|
| 19 |
#if !UCONFIG_NO_COLLATION |
| 20 |
|
| 21 |
#include "unicode/ucol.h" |
| 22 |
#include "unicode/uniset.h" |
| 23 |
#include "collation.h" |
| 24 |
#include "normalizer2impl.h" |
| 25 |
#include "utrie2.h" |
| 26 |
|
| 27 |
struct UDataMemory; |
| 28 |
|
| 29 |
U_NAMESPACE_BEGIN |
| 30 |
|
| 31 |
class UVector32; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
struct U_I18N_API CollationData : public UMemory { |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
static constexpr int32_t REORDER_RESERVED_BEFORE_LATIN = UCOL_REORDER_CODE_FIRST + 14; |
| 45 |
static constexpr int32_t REORDER_RESERVED_AFTER_LATIN = REORDER_RESERVED_BEFORE_LATIN + 1; |
| 46 |
|
| 47 |
static constexpr int32_t MAX_NUM_SPECIAL_REORDER_CODES = 8; |
| 48 |
|
| 49 |
static constexpr int32_t MAX_NUM_SCRIPT_RANGES = 256; |
| 50 |
|
| 51 |
CollationData(const Normalizer2Impl &nfc) |
| 52 |
: trie(nullptr), |
| 53 |
ce32s(nullptr), ces(nullptr), contexts(nullptr), base(nullptr), |
| 54 |
jamoCE32s(nullptr), |
| 55 |
nfcImpl(nfc), |
| 56 |
numericPrimary(0x12000000), |
| 57 |
ce32sLength(0), cesLength(0), contextsLength(0), |
| 58 |
compressibleBytes(nullptr), |
| 59 |
unsafeBackwardSet(nullptr), |
| 60 |
fastLatinTable(nullptr), fastLatinTableLength(0), |
| 61 |
numScripts(0), scriptsIndex(nullptr), scriptStarts(nullptr), scriptStartsLength(0), |
| 62 |
rootElements(nullptr), rootElementsLength(0) {} |
| 63 |
|
| 64 |
uint32_t getCE32(UChar32 c) const { |
| 65 |
return UTRIE2_GET32(trie, c); |
| 66 |
} |
| 67 |
|
| 68 |
uint32_t getCE32FromSupplementary(UChar32 c) const { |
| 69 |
return UTRIE2_GET32_FROM_SUPP(trie, c); |
| 70 |
} |
| 71 |
|
| 72 |
UBool isDigit(UChar32 c) const { |
| 73 |
return c < 0x660 ? c <= 0x39 && 0x30 <= c : |
| 74 |
Collation::hasCE32Tag(getCE32(c), Collation::DIGIT_TAG); |
| 75 |
} |
| 76 |
|
| 77 |
UBool isUnsafeBackward(UChar32 c, UBool numeric) const { |
| 78 |
return unsafeBackwardSet->contains(c) || (numeric && isDigit(c)); |
| 79 |
} |
| 80 |
|
| 81 |
UBool isCompressibleLeadByte(uint32_t b) const { |
| 82 |
return compressibleBytes[b]; |
| 83 |
} |
| 84 |
|
| 85 |
inline UBool isCompressiblePrimary(uint32_t p) const { |
| 86 |
return isCompressibleLeadByte(p >> 24); |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
static uint32_t readCE32(const char16_t *p) { |
| 94 |
return (static_cast<uint32_t>(p[0]) << 16) | p[1]; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
uint32_t getIndirectCE32(uint32_t ce32) const; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
uint32_t getFinalCE32(uint32_t ce32) const; |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
int64_t getCEFromOffsetCE32(UChar32 c, uint32_t ce32) const { |
| 112 |
int64_t dataCE = ces[Collation::indexFromCE32(ce32)]; |
| 113 |
return Collation::makeCE(Collation::getThreeBytePrimaryForOffsetData(c, dataCE)); |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
int64_t getSingleCE(UChar32 c, UErrorCode &errorCode) const; |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
uint16_t getFCD16(UChar32 c) const { |
| 126 |
return nfcImpl.getFCD16(c); |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
uint32_t getFirstPrimaryForGroup(int32_t script) const; |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
uint32_t getLastPrimaryForGroup(int32_t script) const; |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
int32_t getGroupForPrimary(uint32_t p) const; |
| 150 |
|
| 151 |
int32_t getEquivalentScripts(int32_t script, |
| 152 |
int32_t dest[], int32_t capacity, UErrorCode &errorCode) const; |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
void makeReorderRanges(const int32_t *reorder, int32_t length, |
| 165 |
UVector32 &ranges, UErrorCode &errorCode) const; |
| 166 |
|
| 167 |
|
| 168 |
static const int32_t JAMO_CE32S_LENGTH = 19 + 21 + 27; |
| 169 |
|
| 170 |
|
| 171 |
const UTrie2 *trie; |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
const uint32_t *ce32s; |
| 178 |
|
| 179 |
const int64_t *ces; |
| 180 |
|
| 181 |
const char16_t *contexts; |
| 182 |
|
| 183 |
const CollationData *base; |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
const uint32_t *jamoCE32s; |
| 190 |
const Normalizer2Impl &nfcImpl; |
| 191 |
|
| 192 |
uint32_t numericPrimary; |
| 193 |
|
| 194 |
int32_t ce32sLength; |
| 195 |
int32_t cesLength; |
| 196 |
int32_t contextsLength; |
| 197 |
|
| 198 |
|
| 199 |
const UBool *compressibleBytes; |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
const UnicodeSet *unsafeBackwardSet; |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
const uint16_t *fastLatinTable; |
| 211 |
int32_t fastLatinTableLength; |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
int32_t numScripts; |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
const uint16_t *scriptsIndex; |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
const uint16_t *scriptStarts; |
| 236 |
int32_t scriptStartsLength; |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
const uint32_t *rootElements; |
| 244 |
int32_t rootElementsLength; |
| 245 |
|
| 246 |
private: |
| 247 |
int32_t getScriptIndex(int32_t script) const; |
| 248 |
void makeReorderRanges(const int32_t *reorder, int32_t length, |
| 249 |
UBool latinMustMove, |
| 250 |
UVector32 &ranges, UErrorCode &errorCode) const; |
| 251 |
int32_t addLowScriptRange(uint8_t table[], int32_t index, int32_t lowStart) const; |
| 252 |
int32_t addHighScriptRange(uint8_t table[], int32_t index, int32_t highLimit) const; |
| 253 |
}; |
| 254 |
|
| 255 |
U_NAMESPACE_END |
| 256 |
|
| 257 |
#endif |
| 258 |
#endif |