| 1 |
. |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#ifndef __COLLATIONBUILDER_H__ |
| 15 |
#define __COLLATIONBUILDER_H__ |
| 16 |
|
| 17 |
#include "unicode/utypes.h" |
| 18 |
|
| 19 |
#if !UCONFIG_NO_COLLATION |
| 20 |
|
| 21 |
#include "unicode/uniset.h" |
| 22 |
#include "unicode/unistr.h" |
| 23 |
#include "collationrootelements.h" |
| 24 |
#include "collationruleparser.h" |
| 25 |
#include "uvectr32.h" |
| 26 |
#include "uvectr64.h" |
| 27 |
|
| 28 |
struct UParseError; |
| 29 |
|
| 30 |
U_NAMESPACE_BEGIN |
| 31 |
|
| 32 |
struct CollationData; |
| 33 |
struct CollationTailoring; |
| 34 |
|
| 35 |
class CEFinalizer; |
| 36 |
class CollationDataBuilder; |
| 37 |
class Normalizer2; |
| 38 |
class Normalizer2Impl; |
| 39 |
|
| 40 |
class U_I18N_API CollationBuilder : public CollationRuleParser::Sink { |
| 41 |
public: |
| 42 |
CollationBuilder(const CollationTailoring *b, UBool icu4xMode, UErrorCode &errorCode); |
| 43 |
CollationBuilder(const CollationTailoring *base, UErrorCode &errorCode); |
| 44 |
virtual ~CollationBuilder(); |
| 45 |
|
| 46 |
void disableFastLatin() { fastLatinEnabled = false; } |
| 47 |
|
| 48 |
CollationTailoring *parseAndBuild(const UnicodeString &ruleString, |
| 49 |
const UVersionInfo rulesVersion, |
| 50 |
CollationRuleParser::Importer *importer, |
| 51 |
UParseError *outParseError, |
| 52 |
UErrorCode &errorCode); |
| 53 |
|
| 54 |
const char *getErrorReason() const { return errorReason; } |
| 55 |
|
| 56 |
private: |
| 57 |
friend class CEFinalizer; |
| 58 |
|
| 59 |
|
| 60 |
virtual void addReset(int32_t strength, const UnicodeString &str, |
| 61 |
const char *&errorReason, UErrorCode &errorCode) override; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
uint32_t getWeight16Before(int32_t index, int64_t node, int32_t level); |
| 67 |
|
| 68 |
int64_t getSpecialResetPosition(const UnicodeString &str, |
| 69 |
const char *&parserErrorReason, UErrorCode &errorCode); |
| 70 |
|
| 71 |
|
| 72 |
virtual void addRelation(int32_t strength, const UnicodeString &prefix, |
| 73 |
const UnicodeString &str, const UnicodeString &extension, |
| 74 |
const char *&errorReason, UErrorCode &errorCode) override; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
int32_t findOrInsertNodeForCEs(int32_t strength, const char *&parserErrorReason, |
| 81 |
UErrorCode &errorCode); |
| 82 |
int32_t findOrInsertNodeForRootCE(int64_t ce, int32_t strength, UErrorCode &errorCode); |
| 83 |
|
| 84 |
int32_t findOrInsertNodeForPrimary(uint32_t p, UErrorCode &errorCode); |
| 85 |
|
| 86 |
int32_t findOrInsertWeakNode(int32_t index, uint32_t weight16, int32_t level, |
| 87 |
UErrorCode &errorCode); |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
int32_t insertTailoredNodeAfter(int32_t index, int32_t strength, UErrorCode &errorCode); |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
int32_t insertNodeBetween(int32_t index, int32_t nextIndex, int64_t node, |
| 103 |
UErrorCode &errorCode); |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
int32_t findCommonNode(int32_t index, int32_t strength) const; |
| 113 |
|
| 114 |
void setCaseBits(const UnicodeString &nfdString, |
| 115 |
const char *&parserErrorReason, UErrorCode &errorCode); |
| 116 |
|
| 117 |
|
| 118 |
virtual void suppressContractions(const UnicodeSet &set, const char *&parserErrorReason, |
| 119 |
UErrorCode &errorCode) override; |
| 120 |
|
| 121 |
|
| 122 |
virtual void optimize(const UnicodeSet &set, const char *&parserErrorReason, |
| 123 |
UErrorCode &errorCode) override; |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
uint32_t addWithClosure(const UnicodeString &nfdPrefix, const UnicodeString &nfdString, |
| 131 |
const int64_t newCEs[], int32_t newCEsLength, uint32_t ce32, |
| 132 |
UErrorCode &errorCode); |
| 133 |
uint32_t addOnlyClosure(const UnicodeString &nfdPrefix, const UnicodeString &nfdString, |
| 134 |
const int64_t newCEs[], int32_t newCEsLength, uint32_t ce32, |
| 135 |
UErrorCode &errorCode); |
| 136 |
void addTailComposites(const UnicodeString &nfdPrefix, const UnicodeString &nfdString, |
| 137 |
UErrorCode &errorCode); |
| 138 |
UBool mergeCompositeIntoString(const UnicodeString &nfdString, int32_t indexAfterLastStarter, |
| 139 |
UChar32 composite, const UnicodeString &decomp, |
| 140 |
UnicodeString &newNFDString, UnicodeString &newString, |
| 141 |
UErrorCode &errorCode) const; |
| 142 |
|
| 143 |
UBool ignorePrefix(const UnicodeString &s, UErrorCode &errorCode) const; |
| 144 |
UBool ignoreString(const UnicodeString &s, UErrorCode &errorCode) const; |
| 145 |
UBool isFCD(const UnicodeString &s, UErrorCode &errorCode) const; |
| 146 |
|
| 147 |
void closeOverComposites(UErrorCode &errorCode); |
| 148 |
|
| 149 |
uint32_t addIfDifferent(const UnicodeString &prefix, const UnicodeString &str, |
| 150 |
const int64_t newCEs[], int32_t newCEsLength, uint32_t ce32, |
| 151 |
UErrorCode &errorCode); |
| 152 |
static UBool sameCEs(const int64_t ces1[], int32_t ces1Length, |
| 153 |
const int64_t ces2[], int32_t ces2Length); |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
void makeTailoredCEs(UErrorCode &errorCode); |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
static int32_t countTailoredNodes(const int64_t *nodesArray, int32_t i, int32_t strength); |
| 166 |
|
| 167 |
|
| 168 |
void finalizeCEs(UErrorCode &errorCode); |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
static inline int64_t tempCEFromIndexAndStrength(int32_t index, int32_t strength) { |
| 184 |
return |
| 185 |
|
| 186 |
INT64_C(0x4040000006002000) + |
| 187 |
|
| 188 |
(static_cast<int64_t>(index & 0xfe000) << 43) + |
| 189 |
|
| 190 |
(static_cast<int64_t>(index & 0x1fc0) << 42) + |
| 191 |
|
| 192 |
((index & 0x3f) << 24) + |
| 193 |
|
| 194 |
(strength << 8); |
| 195 |
} |
| 196 |
static inline int32_t indexFromTempCE(int64_t tempCE) { |
| 197 |
tempCE -= INT64_C(0x4040000006002000); |
| 198 |
return |
| 199 |
(static_cast<int32_t>(tempCE >> 43) & 0xfe000) | |
| 200 |
(static_cast<int32_t>(tempCE >> 42) & 0x1fc0) | |
| 201 |
(static_cast<int32_t>(tempCE >> 24) & 0x3f); |
| 202 |
} |
| 203 |
static inline int32_t strengthFromTempCE(int64_t tempCE) { |
| 204 |
return (static_cast<int32_t>(tempCE) >> 8) & 3; |
| 205 |
} |
| 206 |
static inline UBool isTempCE(int64_t ce) { |
| 207 |
uint32_t sec = static_cast<uint32_t>(ce) >> 24; |
| 208 |
return 6 <= sec && sec <= 0x45; |
| 209 |
} |
| 210 |
|
| 211 |
static inline int32_t indexFromTempCE32(uint32_t tempCE32) { |
| 212 |
tempCE32 -= 0x40400620; |
| 213 |
return |
| 214 |
(static_cast<int32_t>(tempCE32 >> 11) & 0xfe000) | |
| 215 |
(static_cast<int32_t>(tempCE32 >> 10) & 0x1fc0) | |
| 216 |
(static_cast<int32_t>(tempCE32 >> 8) & 0x3f); |
| 217 |
} |
| 218 |
static inline UBool isTempCE32(uint32_t ce32) { |
| 219 |
return |
| 220 |
(ce32 & 0xff) >= 2 && |
| 221 |
6 <= ((ce32 >> 8) & 0xff) && ((ce32 >> 8) & 0xff) <= 0x45; |
| 222 |
} |
| 223 |
|
| 224 |
static int32_t ceStrength(int64_t ce); |
| 225 |
|
| 226 |
|
| 227 |
static const int32_t MAX_INDEX = 0xfffff; |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
static const int32_t HAS_BEFORE2 = 0x40; |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
static const int32_t HAS_BEFORE3 = 0x20; |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
static const int32_t IS_TAILORED = 8; |
| 243 |
|
| 244 |
static inline int64_t nodeFromWeight32(uint32_t weight32) { |
| 245 |
return static_cast<int64_t>(weight32) << 32; |
| 246 |
} |
| 247 |
static inline int64_t nodeFromWeight16(uint32_t weight16) { |
| 248 |
return static_cast<int64_t>(weight16) << 48; |
| 249 |
} |
| 250 |
static inline int64_t nodeFromPreviousIndex(int32_t previous) { |
| 251 |
return static_cast<int64_t>(previous) << 28; |
| 252 |
} |
| 253 |
static inline int64_t nodeFromNextIndex(int32_t next) { |
| 254 |
return next << 8; |
| 255 |
} |
| 256 |
static inline int64_t nodeFromStrength(int32_t strength) { |
| 257 |
return strength; |
| 258 |
} |
| 259 |
|
| 260 |
static inline uint32_t weight32FromNode(int64_t node) { |
| 261 |
return static_cast<uint32_t>(node >> 32); |
| 262 |
} |
| 263 |
static inline uint32_t weight16FromNode(int64_t node) { |
| 264 |
return static_cast<uint32_t>(node >> 48) & 0xffff; |
| 265 |
} |
| 266 |
static inline int32_t previousIndexFromNode(int64_t node) { |
| 267 |
return static_cast<int32_t>(node >> 28) & MAX_INDEX; |
| 268 |
} |
| 269 |
static inline int32_t nextIndexFromNode(int64_t node) { |
| 270 |
return (static_cast<int32_t>(node) >> 8) & MAX_INDEX; |
| 271 |
} |
| 272 |
static inline int32_t strengthFromNode(int64_t node) { |
| 273 |
return static_cast<int32_t>(node) & 3; |
| 274 |
} |
| 275 |
|
| 276 |
static inline UBool nodeHasBefore2(int64_t node) { |
| 277 |
return (node & HAS_BEFORE2) != 0; |
| 278 |
} |
| 279 |
static inline UBool nodeHasBefore3(int64_t node) { |
| 280 |
return (node & HAS_BEFORE3) != 0; |
| 281 |
} |
| 282 |
static inline UBool nodeHasAnyBefore(int64_t node) { |
| 283 |
return (node & (HAS_BEFORE2 | HAS_BEFORE3)) != 0; |
| 284 |
} |
| 285 |
static inline UBool isTailoredNode(int64_t node) { |
| 286 |
return (node & IS_TAILORED) != 0; |
| 287 |
} |
| 288 |
|
| 289 |
static inline int64_t changeNodePreviousIndex(int64_t node, int32_t previous) { |
| 290 |
return (node & INT64_C(0xffff00000fffffff)) | nodeFromPreviousIndex(previous); |
| 291 |
} |
| 292 |
static inline int64_t changeNodeNextIndex(int64_t node, int32_t next) { |
| 293 |
return (node & INT64_C(0xfffffffff00000ff)) | nodeFromNextIndex(next); |
| 294 |
} |
| 295 |
|
| 296 |
const Normalizer2 &nfd, &fcd; |
| 297 |
const Normalizer2Impl &nfcImpl; |
| 298 |
|
| 299 |
const CollationTailoring *base; |
| 300 |
const CollationData *baseData; |
| 301 |
const CollationRootElements rootElements; |
| 302 |
uint32_t variableTop; |
| 303 |
|
| 304 |
CollationDataBuilder *dataBuilder; |
| 305 |
UBool fastLatinEnabled; |
| 306 |
UBool icu4xMode; |
| 307 |
UnicodeSet optimizeSet; |
| 308 |
const char *errorReason; |
| 309 |
|
| 310 |
int64_t ces[Collation::MAX_EXPANSION_LENGTH]; |
| 311 |
int32_t cesLength; |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
UVector32 rootPrimaryIndexes; |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
UVector64 nodes; |
| 406 |
}; |
| 407 |
|
| 408 |
U_NAMESPACE_END |
| 409 |
|
| 410 |
#endif |
| 411 |
#endif |