1 // © 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 /* 4 ******************************************************************************* 5 * 6 * Copyright (C) 2009-2014, International Business Machines 7 * Corporation and others. All Rights Reserved. 8 * 9 ******************************************************************************* 10 * file name: normalizer2impl.h 11 * encoding: UTF-8 12 * tab size: 8 (not used) 13 * indentation:4 14 * 15 * created on: 2009nov22 16 * created by: Markus W. Scherer 17 */ 18 19 #ifndef __NORMALIZER2IMPL_H__ 20 #define __NORMALIZER2IMPL_H__ 21 22 #include "unicode/utypes.h" 23 24 #if !UCONFIG_NO_NORMALIZATION 25 26 #include "unicode/normalizer2.h" 27 #include "unicode/ucptrie.h" 28 #include "unicode/unistr.h" 29 #include "unicode/unorm.h" 30 #include "unicode/utf.h" 31 #include "unicode/utf16.h" 32 #include "mutex.h" 33 #include "udataswp.h" 34 #include "uset_imp.h" 35 36 // When the nfc.nrm data is *not* hardcoded into the common library 37 // (with this constant set to 0), 38 // then it needs to be built into the data package: 39 // Add nfc.nrm to icu4c/source/data/Makefile.in DAT_FILES_SHORT 40 #define NORM2_HARDCODE_NFC_DATA 1 41 42 U_NAMESPACE_BEGIN 43 44 struct CanonIterData; 45 46 class ByteSink; 47 class Edits; 48 class InitCanonIterData; 49 class LcccContext; 50 51 class U_COMMON_API Hangul { 52 public: 53 /* Korean Hangul and Jamo constants */ 54 enum { 55 JAMO_L_BASE=0x1100, /* "lead" jamo */ 56 JAMO_L_END=0x1112, 57 JAMO_V_BASE=0x1161, /* "vowel" jamo */ 58 JAMO_V_END=0x1175, 59 JAMO_T_BASE=0x11a7, /* "trail" jamo */ 60 JAMO_T_END=0x11c2, 61 62 HANGUL_BASE=0xac00, 63 HANGUL_END=0xd7a3, 64 65 JAMO_L_COUNT=19, 66 JAMO_V_COUNT=21, 67 JAMO_T_COUNT=28, 68 69 JAMO_VT_COUNT=JAMO_V_COUNT*JAMO_T_COUNT, 70 71 HANGUL_COUNT=JAMO_L_COUNT*JAMO_V_COUNT*JAMO_T_COUNT, 72 HANGUL_LIMIT=HANGUL_BASE+HANGUL_COUNT 73 }; 74 isHangul(UChar32 c)75 static inline UBool isHangul(UChar32 c) { 76 return HANGUL_BASE<=c && c<HANGUL_LIMIT; 77 } 78 static inline UBool isHangulLV(UChar32 c)79 isHangulLV(UChar32 c) { 80 c-=HANGUL_BASE; 81 return 0<=c && c<HANGUL_COUNT && c%JAMO_T_COUNT==0; 82 } isJamoL(UChar32 c)83 static inline UBool isJamoL(UChar32 c) { 84 return static_cast<uint32_t>(c - JAMO_L_BASE) < JAMO_L_COUNT; 85 } isJamoV(UChar32 c)86 static inline UBool isJamoV(UChar32 c) { 87 return static_cast<uint32_t>(c - JAMO_V_BASE) < JAMO_V_COUNT; 88 } isJamoT(UChar32 c)89 static inline UBool isJamoT(UChar32 c) { 90 int32_t t=c-JAMO_T_BASE; 91 return 0<t && t<JAMO_T_COUNT; // not JAMO_T_BASE itself 92 } isJamo(UChar32 c)93 static UBool isJamo(UChar32 c) { 94 return JAMO_L_BASE<=c && c<=JAMO_T_END && 95 (c<=JAMO_L_END || (JAMO_V_BASE<=c && c<=JAMO_V_END) || JAMO_T_BASE<c); 96 } 97 98 /** 99 * Decomposes c, which must be a Hangul syllable, into buffer 100 * and returns the length of the decomposition (2 or 3). 101 */ decompose(UChar32 c,char16_t buffer[3])102 static inline int32_t decompose(UChar32 c, char16_t buffer[3]) { 103 c-=HANGUL_BASE; 104 UChar32 c2=c%JAMO_T_COUNT; 105 c/=JAMO_T_COUNT; 106 buffer[0] = static_cast<char16_t>(JAMO_L_BASE + c / JAMO_V_COUNT); 107 buffer[1] = static_cast<char16_t>(JAMO_V_BASE + c % JAMO_V_COUNT); 108 if(c2==0) { 109 return 2; 110 } else { 111 buffer[2] = static_cast<char16_t>(JAMO_T_BASE + c2); 112 return 3; 113 } 114 } 115 116 /** 117 * Decomposes c, which must be a Hangul syllable, into buffer. 118 * This is the raw, not recursive, decomposition. Its length is always 2. 119 */ getRawDecomposition(UChar32 c,char16_t buffer[2])120 static inline void getRawDecomposition(UChar32 c, char16_t buffer[2]) { 121 UChar32 orig=c; 122 c-=HANGUL_BASE; 123 UChar32 c2=c%JAMO_T_COUNT; 124 if(c2==0) { 125 c/=JAMO_T_COUNT; 126 buffer[0] = static_cast<char16_t>(JAMO_L_BASE + c / JAMO_V_COUNT); 127 buffer[1] = static_cast<char16_t>(JAMO_V_BASE + c % JAMO_V_COUNT); 128 } else { 129 buffer[0] = static_cast<char16_t>(orig - c2); // LV syllable 130 buffer[1] = static_cast<char16_t>(JAMO_T_BASE + c2); 131 } 132 } 133 private: 134 Hangul() = delete; // no instantiation 135 }; 136 137 class Normalizer2Impl; 138 139 class U_COMMON_API ReorderingBuffer : public UMemory { 140 public: 141 /** Constructs only; init() should be called. */ ReorderingBuffer(const Normalizer2Impl & ni,UnicodeString & dest)142 ReorderingBuffer(const Normalizer2Impl &ni, UnicodeString &dest) : 143 impl(ni), str(dest), 144 start(nullptr), reorderStart(nullptr), limit(nullptr), 145 remainingCapacity(0), lastCC(0) {} 146 /** Constructs, removes the string contents, and initializes for a small initial capacity. */ 147 ReorderingBuffer(const Normalizer2Impl &ni, UnicodeString &dest, UErrorCode &errorCode); ~ReorderingBuffer()148 ~ReorderingBuffer() { 149 if (start != nullptr) { 150 str.releaseBuffer(static_cast<int32_t>(limit - start)); 151 } 152 } 153 UBool init(int32_t destCapacity, UErrorCode &errorCode); 154 isEmpty()155 UBool isEmpty() const { return start==limit; } length()156 int32_t length() const { return static_cast<int32_t>(limit - start); } getStart()157 char16_t *getStart() { return start; } getLimit()158 char16_t *getLimit() { return limit; } getLastCC()159 uint8_t getLastCC() const { return lastCC; } 160 161 UBool equals(const char16_t *start, const char16_t *limit) const; 162 UBool equals(const uint8_t *otherStart, const uint8_t *otherLimit) const; 163 append(UChar32 c,uint8_t cc,UErrorCode & errorCode)164 UBool append(UChar32 c, uint8_t cc, UErrorCode &errorCode) { 165 return (c<=0xffff) ? 166 appendBMP(static_cast<char16_t>(c), cc, errorCode) : 167 appendSupplementary(c, cc, errorCode); 168 } 169 UBool append(const char16_t *s, int32_t length, UBool isNFD, 170 uint8_t leadCC, uint8_t trailCC, 171 UErrorCode &errorCode); appendBMP(char16_t c,uint8_t cc,UErrorCode & errorCode)172 UBool appendBMP(char16_t c, uint8_t cc, UErrorCode &errorCode) { 173 if(remainingCapacity==0 && !resize(1, errorCode)) { 174 return false; 175 } 176 if(lastCC<=cc || cc==0) { 177 *limit++=c; 178 lastCC=cc; 179 if(cc<=1) { 180 reorderStart=limit; 181 } 182 } else { 183 insert(c, cc); 184 } 185 --remainingCapacity; 186 return true; 187 } 188 UBool appendZeroCC(UChar32 c, UErrorCode &errorCode); 189 UBool appendZeroCC(const char16_t *s, const char16_t *sLimit, UErrorCode &errorCode); 190 void remove(); 191 void removeSuffix(int32_t suffixLength); setReorderingLimit(char16_t * newLimit)192 void setReorderingLimit(char16_t *newLimit) { 193 remainingCapacity += static_cast<int32_t>(limit - newLimit); 194 reorderStart=limit=newLimit; 195 lastCC=0; 196 } copyReorderableSuffixTo(UnicodeString & s)197 void copyReorderableSuffixTo(UnicodeString &s) const { 198 s.setTo(ConstChar16Ptr(reorderStart), static_cast<int32_t>(limit - reorderStart)); 199 } 200 private: 201 /* 202 * TODO: Revisit whether it makes sense to track reorderStart. 203 * It is set to after the last known character with cc<=1, 204 * which stops previousCC() before it reads that character and looks up its cc. 205 * previousCC() is normally only called from insert(). 206 * In other words, reorderStart speeds up the insertion of a combining mark 207 * into a multi-combining mark sequence where it does not belong at the end. 208 * This might not be worth the trouble. 209 * On the other hand, it's not a huge amount of trouble. 210 * 211 * We probably need it for UNORM_SIMPLE_APPEND. 212 */ 213 214 UBool appendSupplementary(UChar32 c, uint8_t cc, UErrorCode &errorCode); 215 void insert(UChar32 c, uint8_t cc); writeCodePoint(char16_t * p,UChar32 c)216 static void writeCodePoint(char16_t *p, UChar32 c) { 217 if(c<=0xffff) { 218 *p = static_cast<char16_t>(c); 219 } else { 220 p[0]=U16_LEAD(c); 221 p[1]=U16_TRAIL(c); 222 } 223 } 224 UBool resize(int32_t appendLength, UErrorCode &errorCode); 225 226 const Normalizer2Impl &impl; 227 UnicodeString &str; 228 char16_t *start, *reorderStart, *limit; 229 int32_t remainingCapacity; 230 uint8_t lastCC; 231 232 // private backward iterator setIterator()233 void setIterator() { codePointStart=limit; } 234 void skipPrevious(); // Requires start<codePointStart. 235 uint8_t previousCC(); // Returns 0 if there is no previous character. 236 237 char16_t *codePointStart, *codePointLimit; 238 }; 239 240 /** 241 * Low-level implementation of the Unicode Normalization Algorithm. 242 * For the data structure and details see the documentation at the end of 243 * this normalizer2impl.h and in the design doc at 244 * https://unicode-org.github.io/icu/design/normalization/custom.html 245 */ 246 class U_COMMON_API Normalizer2Impl : public UObject { 247 public: Normalizer2Impl()248 Normalizer2Impl() : normTrie(nullptr), fCanonIterData(nullptr) {} 249 virtual ~Normalizer2Impl(); 250 251 void init(const int32_t *inIndexes, const UCPTrie *inTrie, 252 const uint16_t *inExtraData, const uint8_t *inSmallFCD); 253 254 void addLcccChars(UnicodeSet &set) const; 255 void addPropertyStarts(const USetAdder *sa, UErrorCode &errorCode) const; 256 void addCanonIterPropertyStarts(const USetAdder *sa, UErrorCode &errorCode) const; 257 258 // low-level properties ------------------------------------------------ *** 259 260 UBool ensureCanonIterData(UErrorCode &errorCode) const; 261 262 // The trie stores values for lead surrogate code *units*. 263 // Surrogate code *points* are inert. getNorm16(UChar32 c)264 uint16_t getNorm16(UChar32 c) const { 265 return U_IS_LEAD(c) ? 266 static_cast<uint16_t>(INERT) : 267 UCPTRIE_FAST_GET(normTrie, UCPTRIE_16, c); 268 } getRawNorm16(UChar32 c)269 uint16_t getRawNorm16(UChar32 c) const { return UCPTRIE_FAST_GET(normTrie, UCPTRIE_16, c); } 270 getCompQuickCheck(uint16_t norm16)271 UNormalizationCheckResult getCompQuickCheck(uint16_t norm16) const { 272 if(norm16<minNoNo || MIN_YES_YES_WITH_CC<=norm16) { 273 return UNORM_YES; 274 } else if(minMaybeNo<=norm16) { 275 return UNORM_MAYBE; 276 } else { 277 return UNORM_NO; 278 } 279 } isAlgorithmicNoNo(uint16_t norm16)280 UBool isAlgorithmicNoNo(uint16_t norm16) const { return limitNoNo<=norm16 && norm16<minMaybeNo; } isCompNo(uint16_t norm16)281 UBool isCompNo(uint16_t norm16) const { return minNoNo<=norm16 && norm16<minMaybeNo; } isDecompYes(uint16_t norm16)282 UBool isDecompYes(uint16_t norm16) const { return norm16<minYesNo || minMaybeYes<=norm16; } 283 getCC(uint16_t norm16)284 uint8_t getCC(uint16_t norm16) const { 285 if(norm16>=MIN_NORMAL_MAYBE_YES) { 286 return getCCFromNormalYesOrMaybe(norm16); 287 } 288 if(norm16<minNoNo || limitNoNo<=norm16) { 289 return 0; 290 } 291 return getCCFromNoNo(norm16); 292 } getCCFromNormalYesOrMaybe(uint16_t norm16)293 static uint8_t getCCFromNormalYesOrMaybe(uint16_t norm16) { 294 return static_cast<uint8_t>(norm16 >> OFFSET_SHIFT); 295 } getCCFromYesOrMaybeYes(uint16_t norm16)296 static uint8_t getCCFromYesOrMaybeYes(uint16_t norm16) { 297 return norm16>=MIN_NORMAL_MAYBE_YES ? getCCFromNormalYesOrMaybe(norm16) : 0; 298 } getCCFromYesOrMaybeYesCP(UChar32 c)299 uint8_t getCCFromYesOrMaybeYesCP(UChar32 c) const { 300 if (c < minCompNoMaybeCP) { return 0; } 301 return getCCFromYesOrMaybeYes(getNorm16(c)); 302 } 303 304 /** 305 * Returns the FCD data for code point c. 306 * @param c A Unicode code point. 307 * @return The lccc(c) in bits 15..8 and tccc(c) in bits 7..0. 308 */ getFCD16(UChar32 c)309 uint16_t getFCD16(UChar32 c) const { 310 if(c<minDecompNoCP) { 311 return 0; 312 } else if(c<=0xffff) { 313 if(!singleLeadMightHaveNonZeroFCD16(c)) { return 0; } 314 } 315 return getFCD16FromNormData(c); 316 } 317 /** 318 * Returns the FCD data for the next code point (post-increment). 319 * Might skip only a lead surrogate rather than the whole surrogate pair if none of 320 * the supplementary code points associated with the lead surrogate have non-zero FCD data. 321 * @param s A valid pointer into a string. Requires s!=limit. 322 * @param limit The end of the string, or NULL. 323 * @return The lccc(c) in bits 15..8 and tccc(c) in bits 7..0. 324 */ nextFCD16(const char16_t * & s,const char16_t * limit)325 uint16_t nextFCD16(const char16_t *&s, const char16_t *limit) const { 326 UChar32 c=*s++; 327 if(c<minDecompNoCP || !singleLeadMightHaveNonZeroFCD16(c)) { 328 return 0; 329 } 330 char16_t c2; 331 if(U16_IS_LEAD(c) && s!=limit && U16_IS_TRAIL(c2=*s)) { 332 c=U16_GET_SUPPLEMENTARY(c, c2); 333 ++s; 334 } 335 return getFCD16FromNormData(c); 336 } 337 /** 338 * Returns the FCD data for the previous code point (pre-decrement). 339 * @param start The start of the string. 340 * @param s A valid pointer into a string. Requires start<s. 341 * @return The lccc(c) in bits 15..8 and tccc(c) in bits 7..0. 342 */ previousFCD16(const char16_t * start,const char16_t * & s)343 uint16_t previousFCD16(const char16_t *start, const char16_t *&s) const { 344 UChar32 c=*--s; 345 if(c<minDecompNoCP) { 346 return 0; 347 } 348 if(!U16_IS_TRAIL(c)) { 349 if(!singleLeadMightHaveNonZeroFCD16(c)) { 350 return 0; 351 } 352 } else { 353 char16_t c2; 354 if(start<s && U16_IS_LEAD(c2=*(s-1))) { 355 c=U16_GET_SUPPLEMENTARY(c2, c); 356 --s; 357 } 358 } 359 return getFCD16FromNormData(c); 360 } 361 362 /** Returns true if the single-or-lead code unit c might have non-zero FCD data. */ singleLeadMightHaveNonZeroFCD16(UChar32 lead)363 UBool singleLeadMightHaveNonZeroFCD16(UChar32 lead) const { 364 // 0<=lead<=0xffff 365 uint8_t bits=smallFCD[lead>>8]; 366 if(bits==0) { return false; } 367 return (bits >> ((lead >> 5) & 7)) & 1; 368 } 369 /** Returns the FCD value from the regular normalization data. */ 370 uint16_t getFCD16FromNormData(UChar32 c) const; 371 372 uint16_t getFCD16FromMaybeOrNonZeroCC(uint16_t norm16) const; 373 374 /** 375 * Gets the decomposition for one code point. 376 * @param c code point 377 * @param buffer out-only buffer for algorithmic decompositions 378 * @param length out-only, takes the length of the decomposition, if any 379 * @return pointer to the decomposition, or NULL if none 380 */ 381 const char16_t *getDecomposition(UChar32 c, char16_t buffer[4], int32_t &length) const; 382 383 /** 384 * Gets the raw decomposition for one code point. 385 * @param c code point 386 * @param buffer out-only buffer for algorithmic decompositions 387 * @param length out-only, takes the length of the decomposition, if any 388 * @return pointer to the decomposition, or NULL if none 389 */ 390 const char16_t *getRawDecomposition(UChar32 c, char16_t buffer[30], int32_t &length) const; 391 392 UChar32 composePair(UChar32 a, UChar32 b) const; 393 394 UBool isCanonSegmentStarter(UChar32 c) const; 395 UBool getCanonStartSet(UChar32 c, UnicodeSet &set) const; 396 397 enum { 398 // Fixed norm16 values. 399 MIN_YES_YES_WITH_CC=0xfe02, 400 JAMO_VT=0xfe00, 401 MIN_NORMAL_MAYBE_YES=0xfc00, 402 JAMO_L=2, // offset=1 hasCompBoundaryAfter=false 403 INERT=1, // offset=0 hasCompBoundaryAfter=true 404 405 // norm16 bit 0 is comp-boundary-after. 406 HAS_COMP_BOUNDARY_AFTER=1, 407 OFFSET_SHIFT=1, 408 409 // For algorithmic one-way mappings, norm16 bits 2..1 indicate the 410 // tccc (0, 1, >1) for quick FCC boundary-after tests. 411 DELTA_TCCC_0=0, 412 DELTA_TCCC_1=2, 413 DELTA_TCCC_GT_1=4, 414 DELTA_TCCC_MASK=6, 415 DELTA_SHIFT=3, 416 417 MAX_DELTA=0x40 418 }; 419 420 enum { 421 // Byte offsets from the start of the data, after the generic header. 422 IX_NORM_TRIE_OFFSET, 423 IX_EXTRA_DATA_OFFSET, 424 IX_SMALL_FCD_OFFSET, 425 IX_RESERVED3_OFFSET, 426 IX_RESERVED4_OFFSET, 427 IX_RESERVED5_OFFSET, 428 IX_RESERVED6_OFFSET, 429 IX_TOTAL_SIZE, 430 431 // Code point thresholds for quick check codes. 432 IX_MIN_DECOMP_NO_CP, 433 IX_MIN_COMP_NO_MAYBE_CP, 434 435 // Norm16 value thresholds for quick check combinations and types of extra data. 436 437 /** Mappings & compositions in [minYesNo..minYesNoMappingsOnly[. */ 438 IX_MIN_YES_NO, 439 /** Mappings are comp-normalized. */ 440 IX_MIN_NO_NO, 441 IX_LIMIT_NO_NO, 442 IX_MIN_MAYBE_YES, 443 444 /** Mappings only in [minYesNoMappingsOnly..minNoNo[. */ 445 IX_MIN_YES_NO_MAPPINGS_ONLY, 446 /** Mappings are not comp-normalized but have a comp boundary before. */ 447 IX_MIN_NO_NO_COMP_BOUNDARY_BEFORE, 448 /** Mappings do not have a comp boundary before. */ 449 IX_MIN_NO_NO_COMP_NO_MAYBE_CC, 450 /** Mappings to the empty string. */ 451 IX_MIN_NO_NO_EMPTY, 452 453 IX_MIN_LCCC_CP, 454 IX_RESERVED19, 455 456 /** Two-way mappings; each starts with a character that combines backward. */ 457 IX_MIN_MAYBE_NO, // 20 458 /** Two-way mappings & compositions. */ 459 IX_MIN_MAYBE_NO_COMBINES_FWD, 460 461 IX_COUNT // 22 462 }; 463 464 enum { 465 MAPPING_HAS_CCC_LCCC_WORD=0x80, 466 MAPPING_HAS_RAW_MAPPING=0x40, 467 // unused bit 0x20, 468 MAPPING_LENGTH_MASK=0x1f 469 }; 470 471 enum { 472 COMP_1_LAST_TUPLE=0x8000, 473 COMP_1_TRIPLE=1, 474 COMP_1_TRAIL_LIMIT=0x3400, 475 COMP_1_TRAIL_MASK=0x7ffe, 476 COMP_1_TRAIL_SHIFT=9, // 10-1 for the "triple" bit 477 COMP_2_TRAIL_SHIFT=6, 478 COMP_2_TRAIL_MASK=0xffc0 479 }; 480 481 // higher-level functionality ------------------------------------------ *** 482 483 // NFD without an NFD Normalizer2 instance. 484 UnicodeString &decompose(const UnicodeString &src, UnicodeString &dest, 485 UErrorCode &errorCode) const; 486 /** 487 * Decomposes [src, limit[ and writes the result to dest. 488 * limit can be NULL if src is NUL-terminated. 489 * destLengthEstimate is the initial dest buffer capacity and can be -1. 490 */ 491 void decompose(const char16_t *src, const char16_t *limit, 492 UnicodeString &dest, int32_t destLengthEstimate, 493 UErrorCode &errorCode) const; 494 495 const char16_t *decompose(const char16_t *src, const char16_t *limit, 496 ReorderingBuffer *buffer, UErrorCode &errorCode) const; 497 void decomposeAndAppend(const char16_t *src, const char16_t *limit, 498 UBool doDecompose, 499 UnicodeString &safeMiddle, 500 ReorderingBuffer &buffer, 501 UErrorCode &errorCode) const; 502 503 /** sink==nullptr: isNormalized()/spanQuickCheckYes() */ 504 const uint8_t *decomposeUTF8(uint32_t options, 505 const uint8_t *src, const uint8_t *limit, 506 ByteSink *sink, Edits *edits, UErrorCode &errorCode) const; 507 508 UBool compose(const char16_t *src, const char16_t *limit, 509 UBool onlyContiguous, 510 UBool doCompose, 511 ReorderingBuffer &buffer, 512 UErrorCode &errorCode) const; 513 const char16_t *composeQuickCheck(const char16_t *src, const char16_t *limit, 514 UBool onlyContiguous, 515 UNormalizationCheckResult *pQCResult) const; 516 void composeAndAppend(const char16_t *src, const char16_t *limit, 517 UBool doCompose, 518 UBool onlyContiguous, 519 UnicodeString &safeMiddle, 520 ReorderingBuffer &buffer, 521 UErrorCode &errorCode) const; 522 523 /** sink==nullptr: isNormalized() */ 524 UBool composeUTF8(uint32_t options, UBool onlyContiguous, 525 const uint8_t *src, const uint8_t *limit, 526 ByteSink *sink, icu::Edits *edits, UErrorCode &errorCode) const; 527 528 const char16_t *makeFCD(const char16_t *src, const char16_t *limit, 529 ReorderingBuffer *buffer, UErrorCode &errorCode) const; 530 void makeFCDAndAppend(const char16_t *src, const char16_t *limit, 531 UBool doMakeFCD, 532 UnicodeString &safeMiddle, 533 ReorderingBuffer &buffer, 534 UErrorCode &errorCode) const; 535 536 UBool hasDecompBoundaryBefore(UChar32 c) const; 537 UBool norm16HasDecompBoundaryBefore(uint16_t norm16) const; 538 UBool hasDecompBoundaryAfter(UChar32 c) const; 539 UBool norm16HasDecompBoundaryAfter(uint16_t norm16) const; isDecompInert(UChar32 c)540 UBool isDecompInert(UChar32 c) const { return isDecompYesAndZeroCC(getNorm16(c)); } 541 hasCompBoundaryBefore(UChar32 c)542 UBool hasCompBoundaryBefore(UChar32 c) const { 543 return c<minCompNoMaybeCP || norm16HasCompBoundaryBefore(getNorm16(c)); 544 } hasCompBoundaryAfter(UChar32 c,UBool onlyContiguous)545 UBool hasCompBoundaryAfter(UChar32 c, UBool onlyContiguous) const { 546 return norm16HasCompBoundaryAfter(getNorm16(c), onlyContiguous); 547 } isCompInert(UChar32 c,UBool onlyContiguous)548 UBool isCompInert(UChar32 c, UBool onlyContiguous) const { 549 uint16_t norm16=getNorm16(c); 550 return isCompYesAndZeroCC(norm16) && 551 (norm16 & HAS_COMP_BOUNDARY_AFTER) != 0 && 552 (!onlyContiguous || isInert(norm16) || *getDataForYesOrNo(norm16) <= 0x1ff); 553 // The last check fetches the mapping's first unit and checks tccc<=1. 554 } 555 hasFCDBoundaryBefore(UChar32 c)556 UBool hasFCDBoundaryBefore(UChar32 c) const { return hasDecompBoundaryBefore(c); } hasFCDBoundaryAfter(UChar32 c)557 UBool hasFCDBoundaryAfter(UChar32 c) const { return hasDecompBoundaryAfter(c); } isFCDInert(UChar32 c)558 UBool isFCDInert(UChar32 c) const { return getFCD16(c)<=1; } 559 private: 560 friend class InitCanonIterData; 561 friend class LcccContext; 562 isMaybe(uint16_t norm16)563 UBool isMaybe(uint16_t norm16) const { return minMaybeNo<=norm16 && norm16<=JAMO_VT; } isMaybeYesOrNonZeroCC(uint16_t norm16)564 UBool isMaybeYesOrNonZeroCC(uint16_t norm16) const { return norm16>=minMaybeYes; } isInert(uint16_t norm16)565 static UBool isInert(uint16_t norm16) { return norm16==INERT; } isJamoL(uint16_t norm16)566 static UBool isJamoL(uint16_t norm16) { return norm16==JAMO_L; } isJamoVT(uint16_t norm16)567 static UBool isJamoVT(uint16_t norm16) { return norm16==JAMO_VT; } hangulLVT()568 uint16_t hangulLVT() const { return minYesNoMappingsOnly|HAS_COMP_BOUNDARY_AFTER; } isHangulLV(uint16_t norm16)569 UBool isHangulLV(uint16_t norm16) const { return norm16==minYesNo; } isHangulLVT(uint16_t norm16)570 UBool isHangulLVT(uint16_t norm16) const { 571 return norm16==hangulLVT(); 572 } isCompYesAndZeroCC(uint16_t norm16)573 UBool isCompYesAndZeroCC(uint16_t norm16) const { return norm16<minNoNo; } 574 // UBool isCompYes(uint16_t norm16) const { 575 // return norm16>=MIN_YES_YES_WITH_CC || norm16<minNoNo; 576 // } 577 // UBool isCompYesOrMaybe(uint16_t norm16) const { 578 // return norm16<minNoNo || minMaybeNo<=norm16; 579 // } 580 // UBool hasZeroCCFromDecompYes(uint16_t norm16) const { 581 // return norm16<=MIN_NORMAL_MAYBE_YES || norm16==JAMO_VT; 582 // } isDecompYesAndZeroCC(uint16_t norm16)583 UBool isDecompYesAndZeroCC(uint16_t norm16) const { 584 return norm16<minYesNo || 585 norm16==JAMO_VT || 586 (minMaybeYes<=norm16 && norm16<=MIN_NORMAL_MAYBE_YES); 587 } 588 /** 589 * A little faster and simpler than isDecompYesAndZeroCC() but does not include 590 * the MaybeYes which combine-forward and have ccc=0. 591 */ isMostDecompYesAndZeroCC(uint16_t norm16)592 UBool isMostDecompYesAndZeroCC(uint16_t norm16) const { 593 return norm16<minYesNo || norm16==MIN_NORMAL_MAYBE_YES || norm16==JAMO_VT; 594 } 595 /** Since formatVersion 5: same as isAlgorithmicNoNo() */ isDecompNoAlgorithmic(uint16_t norm16)596 UBool isDecompNoAlgorithmic(uint16_t norm16) const { return limitNoNo<=norm16 && norm16<minMaybeNo; } 597 598 // For use with isCompYes(). 599 // Perhaps the compiler can combine the two tests for MIN_YES_YES_WITH_CC. 600 // static uint8_t getCCFromYes(uint16_t norm16) { 601 // return norm16>=MIN_YES_YES_WITH_CC ? getCCFromNormalYesOrMaybe(norm16) : 0; 602 // } getCCFromNoNo(uint16_t norm16)603 uint8_t getCCFromNoNo(uint16_t norm16) const { 604 const uint16_t *mapping=getDataForYesOrNo(norm16); 605 if(*mapping&MAPPING_HAS_CCC_LCCC_WORD) { 606 return static_cast<uint8_t>(*(mapping - 1)); 607 } else { 608 return 0; 609 } 610 } 611 // requires that the [cpStart..cpLimit[ character passes isCompYesAndZeroCC() getTrailCCFromCompYesAndZeroCC(uint16_t norm16)612 uint8_t getTrailCCFromCompYesAndZeroCC(uint16_t norm16) const { 613 if(norm16<=minYesNo) { 614 return 0; // yesYes and Hangul LV have ccc=tccc=0 615 } else { 616 // For Hangul LVT we harmlessly fetch a firstUnit with tccc=0 here. 617 return static_cast<uint8_t>(*getDataForYesOrNo(norm16) >> 8); // tccc from yesNo 618 } 619 } 620 uint8_t getPreviousTrailCC(const char16_t *start, const char16_t *p) const; 621 uint8_t getPreviousTrailCC(const uint8_t *start, const uint8_t *p) const; 622 623 // Requires algorithmic-NoNo. mapAlgorithmic(UChar32 c,uint16_t norm16)624 UChar32 mapAlgorithmic(UChar32 c, uint16_t norm16) const { 625 return c+(norm16>>DELTA_SHIFT)-centerNoNoDelta; 626 } getAlgorithmicDelta(uint16_t norm16)627 UChar32 getAlgorithmicDelta(uint16_t norm16) const { 628 return (norm16>>DELTA_SHIFT)-centerNoNoDelta; 629 } 630 getDataForYesOrNo(uint16_t norm16)631 const uint16_t *getDataForYesOrNo(uint16_t norm16) const { 632 return extraData+(norm16>>OFFSET_SHIFT); 633 } getDataForMaybe(uint16_t norm16)634 const uint16_t *getDataForMaybe(uint16_t norm16) const { 635 return extraData+((norm16-minMaybeNo+limitNoNo)>>OFFSET_SHIFT); 636 } getData(uint16_t norm16)637 const uint16_t *getData(uint16_t norm16) const { 638 if(norm16>=minMaybeNo) { 639 norm16=norm16-minMaybeNo+limitNoNo; 640 } 641 return extraData+(norm16>>OFFSET_SHIFT); 642 } getCompositionsListForDecompYes(uint16_t norm16)643 const uint16_t *getCompositionsListForDecompYes(uint16_t norm16) const { 644 if(norm16<JAMO_L || MIN_NORMAL_MAYBE_YES<=norm16) { 645 return nullptr; 646 } else { 647 // if yesYes: if Jamo L: harmless empty list 648 return getData(norm16); 649 } 650 } getCompositionsListForComposite(uint16_t norm16)651 const uint16_t *getCompositionsListForComposite(uint16_t norm16) const { 652 // A composite has both mapping & compositions list. 653 const uint16_t *list=getData(norm16); 654 return list+ // mapping pointer 655 1+ // +1 to skip the first unit with the mapping length 656 (*list&MAPPING_LENGTH_MASK); // + mapping length 657 } 658 /** 659 * @param c code point must have compositions 660 * @return compositions list pointer 661 */ getCompositionsList(uint16_t norm16)662 const uint16_t *getCompositionsList(uint16_t norm16) const { 663 return isDecompYes(norm16) ? 664 getCompositionsListForDecompYes(norm16) : 665 getCompositionsListForComposite(norm16); 666 } 667 668 const char16_t *copyLowPrefixFromNulTerminated(const char16_t *src, 669 UChar32 minNeedDataCP, 670 ReorderingBuffer *buffer, 671 UErrorCode &errorCode) const; 672 673 enum StopAt { STOP_AT_LIMIT, STOP_AT_DECOMP_BOUNDARY, STOP_AT_COMP_BOUNDARY }; 674 675 const char16_t *decomposeShort(const char16_t *src, const char16_t *limit, 676 UBool stopAtCompBoundary, UBool onlyContiguous, 677 ReorderingBuffer &buffer, UErrorCode &errorCode) const; 678 UBool decompose(UChar32 c, uint16_t norm16, 679 ReorderingBuffer &buffer, UErrorCode &errorCode) const; 680 681 const uint8_t *decomposeShort(const uint8_t *src, const uint8_t *limit, 682 StopAt stopAt, UBool onlyContiguous, 683 ReorderingBuffer &buffer, UErrorCode &errorCode) const; 684 685 static int32_t combine(const uint16_t *list, UChar32 trail); 686 void addComposites(const uint16_t *list, UnicodeSet &set) const; 687 void recompose(ReorderingBuffer &buffer, int32_t recomposeStartIndex, 688 UBool onlyContiguous) const; 689 hasCompBoundaryBefore(UChar32 c,uint16_t norm16)690 UBool hasCompBoundaryBefore(UChar32 c, uint16_t norm16) const { 691 return c<minCompNoMaybeCP || norm16HasCompBoundaryBefore(norm16); 692 } norm16HasCompBoundaryBefore(uint16_t norm16)693 UBool norm16HasCompBoundaryBefore(uint16_t norm16) const { 694 return norm16 < minNoNoCompNoMaybeCC || isAlgorithmicNoNo(norm16); 695 } 696 UBool hasCompBoundaryBefore(const char16_t *src, const char16_t *limit) const; 697 UBool hasCompBoundaryBefore(const uint8_t *src, const uint8_t *limit) const; 698 UBool hasCompBoundaryAfter(const char16_t *start, const char16_t *p, 699 UBool onlyContiguous) const; 700 UBool hasCompBoundaryAfter(const uint8_t *start, const uint8_t *p, 701 UBool onlyContiguous) const; norm16HasCompBoundaryAfter(uint16_t norm16,UBool onlyContiguous)702 UBool norm16HasCompBoundaryAfter(uint16_t norm16, UBool onlyContiguous) const { 703 return (norm16 & HAS_COMP_BOUNDARY_AFTER) != 0 && 704 (!onlyContiguous || isTrailCC01ForCompBoundaryAfter(norm16)); 705 } 706 /** For FCC: Given norm16 HAS_COMP_BOUNDARY_AFTER, does it have tccc<=1? */ isTrailCC01ForCompBoundaryAfter(uint16_t norm16)707 UBool isTrailCC01ForCompBoundaryAfter(uint16_t norm16) const { 708 return isInert(norm16) || (isDecompNoAlgorithmic(norm16) ? 709 (norm16 & DELTA_TCCC_MASK) <= DELTA_TCCC_1 : *getDataForYesOrNo(norm16) <= 0x1ff); 710 } 711 712 const char16_t *findPreviousCompBoundary(const char16_t *start, const char16_t *p, 713 UBool onlyContiguous) const; 714 const char16_t *findNextCompBoundary(const char16_t *p, const char16_t *limit, 715 UBool onlyContiguous) const; 716 717 const char16_t *findPreviousFCDBoundary(const char16_t *start, const char16_t *p) const; 718 const char16_t *findNextFCDBoundary(const char16_t *p, const char16_t *limit) const; 719 720 void makeCanonIterDataFromNorm16(UChar32 start, UChar32 end, const uint16_t norm16, 721 CanonIterData &newData, UErrorCode &errorCode) const; 722 723 int32_t getCanonValue(UChar32 c) const; 724 const UnicodeSet &getCanonStartSet(int32_t n) const; 725 726 // UVersionInfo dataVersion; 727 728 // BMP code point thresholds for quick check loops looking at single UTF-16 code units. 729 char16_t minDecompNoCP; 730 char16_t minCompNoMaybeCP; 731 char16_t minLcccCP; 732 733 // Norm16 value thresholds for quick check combinations and types of extra data. 734 uint16_t minYesNo; 735 uint16_t minYesNoMappingsOnly; 736 uint16_t minNoNo; 737 uint16_t minNoNoCompBoundaryBefore; 738 uint16_t minNoNoCompNoMaybeCC; 739 uint16_t minNoNoEmpty; 740 uint16_t limitNoNo; 741 uint16_t centerNoNoDelta; 742 uint16_t minMaybeNo; 743 uint16_t minMaybeNoCombinesFwd; 744 uint16_t minMaybeYes; 745 746 const UCPTrie *normTrie; 747 const uint16_t *extraData; // mappings and/or compositions 748 const uint8_t *smallFCD; // [0x100] one bit per 32 BMP code points, set if any FCD!=0 749 750 UInitOnce fCanonIterDataInitOnce {}; 751 CanonIterData *fCanonIterData; 752 }; 753 754 // bits in canonIterData 755 #define CANON_NOT_SEGMENT_STARTER 0x80000000 756 #define CANON_HAS_COMPOSITIONS 0x40000000 757 #define CANON_HAS_SET 0x200000 758 #define CANON_VALUE_MASK 0x1fffff 759 760 /** 761 * ICU-internal shortcut for quick access to standard Unicode normalization. 762 */ 763 class U_COMMON_API Normalizer2Factory { 764 public: 765 static const Normalizer2 *getFCDInstance(UErrorCode &errorCode); 766 static const Normalizer2 *getFCCInstance(UErrorCode &errorCode); 767 static const Normalizer2 *getNoopInstance(UErrorCode &errorCode); 768 769 static const Normalizer2 *getInstance(UNormalizationMode mode, UErrorCode &errorCode); 770 771 static const Normalizer2Impl *getNFCImpl(UErrorCode &errorCode); 772 static const Normalizer2Impl *getNFKCImpl(UErrorCode &errorCode); 773 static const Normalizer2Impl *getNFKC_CFImpl(UErrorCode &errorCode); 774 775 // Get the Impl instance of the Normalizer2. 776 // Must be used only when it is known that norm2 is a Normalizer2WithImpl instance. 777 static const Normalizer2Impl *getImpl(const Normalizer2 *norm2); 778 private: 779 Normalizer2Factory() = delete; // No instantiation. 780 }; 781 782 U_NAMESPACE_END 783 784 U_CAPI int32_t U_EXPORT2 785 unorm2_swap(const UDataSwapper *ds, 786 const void *inData, int32_t length, void *outData, 787 UErrorCode *pErrorCode); 788 789 /** 790 * Get the NF*_QC property for a code point, for u_getIntPropertyValue(). 791 * @internal 792 */ 793 U_CFUNC UNormalizationCheckResult 794 unorm_getQuickCheck(UChar32 c, UNormalizationMode mode); 795 796 /** 797 * Gets the 16-bit FCD value (lead & trail CCs) for a code point, for u_getIntPropertyValue(). 798 * @internal 799 */ 800 U_CFUNC uint16_t 801 unorm_getFCD16(UChar32 c); 802 803 /** 804 * Format of Normalizer2 .nrm data files. 805 * Format version 5.0. 806 * 807 * Normalizer2 .nrm data files provide data for the Unicode Normalization algorithms. 808 * ICU ships with data files for standard Unicode Normalization Forms 809 * NFC and NFD (nfc.nrm), NFKC and NFKD (nfkc.nrm), 810 * NFKC_Casefold (nfkc_cf.nrm) and NFKC_Simple_Casefold (nfkc_scf.nrm). 811 * Custom (application-specific) data can be built into additional .nrm files 812 * with the gennorm2 build tool. 813 * ICU ships with one such file, uts46.nrm, for the implementation of UTS #46. 814 * 815 * Normalizer2.getInstance() causes a .nrm file to be loaded, unless it has been 816 * cached already. Internally, Normalizer2Impl.load() reads the .nrm file. 817 * 818 * A .nrm file begins with a standard ICU data file header 819 * (DataHeader, see ucmndata.h and unicode/udata.h). 820 * The UDataInfo.dataVersion field usually contains the Unicode version 821 * for which the data was generated. 822 * 823 * After the header, the file contains the following parts. 824 * Constants are defined as enum values of the Normalizer2Impl class. 825 * 826 * Many details of the data structures are described in the design doc 827 * which is at https://unicode-org.github.io/icu/design/normalization/custom.html 828 * 829 * int32_t indexes[indexesLength]; -- indexesLength=indexes[IX_NORM_TRIE_OFFSET]/4; 830 * 831 * The first eight indexes are byte offsets in ascending order. 832 * Each byte offset marks the start of the next part in the data file, 833 * and the end of the previous one. 834 * When two consecutive byte offsets are the same, then the corresponding part is empty. 835 * Byte offsets are offsets from after the header, 836 * that is, from the beginning of the indexes[]. 837 * Each part starts at an offset with proper alignment for its data. 838 * If necessary, the previous part may include padding bytes to achieve this alignment. 839 * 840 * minDecompNoCP=indexes[IX_MIN_DECOMP_NO_CP] is the lowest code point 841 * with a decomposition mapping, that is, with NF*D_QC=No. 842 * minCompNoMaybeCP=indexes[IX_MIN_COMP_NO_MAYBE_CP] is the lowest code point 843 * with NF*C_QC=No (has a one-way mapping) or Maybe (combines backward). 844 * minLcccCP=indexes[IX_MIN_LCCC_CP] (index 18, new in formatVersion 3) 845 * is the lowest code point with lccc!=0. 846 * 847 * The next eight indexes are thresholds of 16-bit trie values for ranges of 848 * values indicating multiple normalization properties. 849 * Format version 5 adds the two minMaybeNo* threshold indexes. 850 * The thresholds are listed here in threshold order, 851 * not in the order they are stored in the indexes. 852 * minYesNo=indexes[IX_MIN_YES_NO]; 853 * minYesNoMappingsOnly=indexes[IX_MIN_YES_NO_MAPPINGS_ONLY]; 854 * minNoNo=indexes[IX_MIN_NO_NO]; 855 * minNoNoCompBoundaryBefore=indexes[IX_MIN_NO_NO_COMP_BOUNDARY_BEFORE]; 856 * minNoNoCompNoMaybeCC=indexes[IX_MIN_NO_NO_COMP_NO_MAYBE_CC]; 857 * minNoNoEmpty=indexes[IX_MIN_NO_NO_EMPTY]; 858 * limitNoNo=indexes[IX_LIMIT_NO_NO]; 859 * minMaybeNo=indexes[IX_MIN_MAYBE_NO]; 860 * minMaybeNoCombinesFwd=indexes[IX_MIN_MAYBE_NO_COMBINES_FWD]; 861 * minMaybeYes=indexes[IX_MIN_MAYBE_YES]; 862 * See the normTrie description below and the design doc for details. 863 * 864 * UCPTrie normTrie; -- see ucptrie_impl.h and ucptrie.h, same as Java CodePointTrie 865 * 866 * The trie holds the main normalization data. Each code point is mapped to a 16-bit value. 867 * Rather than using independent bits in the value (which would require more than 16 bits), 868 * information is extracted primarily via range checks. 869 * Except, format version 3+ uses bit 0 for hasCompBoundaryAfter(). 870 * For example, a 16-bit value norm16 in the range minYesNo<=norm16<minNoNo 871 * means that the character has NF*C_QC=Yes and NF*D_QC=No properties, 872 * which means it has a two-way (round-trip) decomposition mapping. 873 * Values in the ranges 2<=norm16<limitNoNo and minMaybeNo<=norm16<minMaybeYes 874 * are also directly indexes into the extraData 875 * pointing to mappings, compositions lists, or both. 876 * Value norm16==INERT (0 in versions 1 & 2, 1 in version 3+) 877 * means that the character is normalization-inert, that is, 878 * it does not have a mapping, does not participate in composition, has a zero 879 * canonical combining class, and forms a boundary where text before it and after it 880 * can be normalized independently. 881 * For details about how multiple properties are encoded in 16-bit values 882 * see the design doc. 883 * Note that the encoding cannot express all combinations of the properties involved; 884 * it only supports those combinations that are allowed by 885 * the Unicode Normalization algorithms. Details are in the design doc as well. 886 * The gennorm2 tool only builds .nrm files for data that conforms to the limitations. 887 * 888 * The trie has a value for each lead surrogate code unit representing the "worst case" 889 * properties of the 1024 supplementary characters whose UTF-16 form starts with 890 * the lead surrogate. If all of the 1024 supplementary characters are normalization-inert, 891 * then their lead surrogate code unit has the trie value INERT. 892 * When the lead surrogate unit's value exceeds the quick check minimum during processing, 893 * the properties for the full supplementary code point need to be looked up. 894 * 895 * uint16_t extraData[]; 896 * 897 * The extraData array contains many per-character data sections. 898 * Each section contains mappings and/or composition lists. 899 * The norm16 value of each character that has such data is directly an index to 900 * a section of the extraData array. 901 * 902 * In version 3+, the norm16 values must be shifted right by OFFSET_SHIFT 903 * for accessing extraData. 904 * 905 * The data structures for compositions lists and mappings are described in the design doc. 906 * 907 * In version 4 and below, the composition lists for MaybeYes characters were stored before 908 * the data for other characters. 909 * This sub-array had a length of MIN_NORMAL_MAYBE_YES-minMaybeYes. 910 * In version 3 & 4, the difference must be shifted right by OFFSET_SHIFT. 911 * 912 * In version 5, the data for MaybeNo and MaybeYes characters is stored after 913 * the data for other characters. 914 * 915 * If there are no MaybeNo and no MaybeYes characters, 916 * then minMaybeYes==minMaybeNo==MIN_NORMAL_MAYBE_YES. 917 * If there are such characters, then minMaybeNo is subtracted from their norm16 values 918 * to get the index into the extraData. 919 * In version 4 and below, the data index for Yes* and No* characters needs to be 920 * offset by the length of the MaybeYes data. 921 * In version 5, the data index for Maybe* characters needs to be offset by limitNoNo. 922 * 923 * Version 5 is the first to support MaybeNo characters, and 924 * adds the minMaybeNo and minMaybeNoCombinesFwd thresholds and 925 * the corresponding sections of the extraData. 926 * 927 * uint8_t smallFCD[0x100]; -- new in format version 2 928 * 929 * This is a bit set to help speed up FCD value lookups in the absence of a full 930 * UTrie2 or other large data structure with the full FCD value mapping. 931 * 932 * Each smallFCD bit is set if any of the corresponding 32 BMP code points 933 * has a non-zero FCD value (lccc!=0 or tccc!=0). 934 * Bit 0 of smallFCD[0] is for U+0000..U+001F. Bit 7 of smallFCD[0xff] is for U+FFE0..U+FFFF. 935 * A bit for 32 lead surrogates is set if any of the 32k corresponding 936 * _supplementary_ code points has a non-zero FCD value. 937 * 938 * This bit set is most useful for the large blocks of CJK characters with FCD=0. 939 * 940 * Changes from format version 1 to format version 2 --------------------------- 941 * 942 * - Addition of data for raw (not recursively decomposed) mappings. 943 * + The MAPPING_NO_COMP_BOUNDARY_AFTER bit in the extraData is now also set when 944 * the mapping is to an empty string or when the character combines-forward. 945 * This subsumes the one actual use of the MAPPING_PLUS_COMPOSITION_LIST bit which 946 * is then repurposed for the MAPPING_HAS_RAW_MAPPING bit. 947 * + For details see the design doc. 948 * - Addition of indexes[IX_MIN_YES_NO_MAPPINGS_ONLY] and separation of the yesNo extraData into 949 * distinct ranges (combines-forward vs. not) 950 * so that a range check can be used to find out if there is a compositions list. 951 * This is fully equivalent with formatVersion 1's MAPPING_PLUS_COMPOSITION_LIST flag. 952 * It is needed for the new (in ICU 49) composePair(), not for other normalization. 953 * - Addition of the smallFCD[] bit set. 954 * 955 * Changes from format version 2 to format version 3 (ICU 60) ------------------ 956 * 957 * - norm16 bit 0 indicates hasCompBoundaryAfter(), 958 * except that for contiguous composition (FCC) the tccc must be checked as well. 959 * Data indexes and ccc values are shifted left by one (OFFSET_SHIFT). 960 * Thresholds like minNoNo are tested before shifting. 961 * 962 * - Algorithmic mapping deltas are shifted left by two more bits (total DELTA_SHIFT), 963 * to make room for two bits (three values) indicating whether the tccc is 0, 1, or greater. 964 * See DELTA_TCCC_MASK etc. 965 * This helps with fetching tccc/FCD values and FCC hasCompBoundaryAfter(). 966 * minMaybeNo is 8-aligned so that the DELTA_TCCC_MASK bits can be tested directly. 967 * 968 * - Algorithmic mappings are only used for mapping to "comp yes and ccc=0" characters, 969 * and ASCII characters are mapped algorithmically only to other ASCII characters. 970 * This helps with hasCompBoundaryBefore() and compose() fast paths. 971 * It is never necessary any more to loop for algorithmic mappings. 972 * 973 * - Addition of indexes[IX_MIN_NO_NO_COMP_BOUNDARY_BEFORE], 974 * indexes[IX_MIN_NO_NO_COMP_NO_MAYBE_CC], and indexes[IX_MIN_NO_NO_EMPTY], 975 * and separation of the noNo extraData into distinct ranges. 976 * With this, the noNo norm16 value indicates whether the mapping is 977 * compose-normalized, not normalized but hasCompBoundaryBefore(), 978 * not even that, or maps to an empty string. 979 * hasCompBoundaryBefore() can be determined solely from the norm16 value. 980 * 981 * - The norm16 value for Hangul LVT is now different from that for Hangul LV, 982 * so that hasCompBoundaryAfter() need not check for the syllable type. 983 * For Hangul LV, minYesNo continues to be used (no comp-boundary-after). 984 * For Hangul LVT, minYesNoMappingsOnly|HAS_COMP_BOUNDARY_AFTER is used. 985 * The extraData units at these indexes are set to firstUnit=2 and firstUnit=3, respectively, 986 * to simplify some code. 987 * 988 * - The extraData firstUnit bit 5 is no longer necessary 989 * (norm16 bit 0 used instead of firstUnit MAPPING_NO_COMP_BOUNDARY_AFTER), 990 * is reserved again, and always set to 0. 991 * 992 * - Addition of indexes[IX_MIN_LCCC_CP], the first code point where lccc!=0. 993 * This used to be hardcoded to U+0300, but in data like NFKC_Casefold it is lower: 994 * U+00AD Soft Hyphen maps to an empty string, 995 * which is artificially assigned "worst case" values lccc=1 and tccc=255. 996 * 997 * - A mapping to an empty string has explicit lccc=1 and tccc=255 values. 998 * 999 * Changes from format version 3 to format version 4 (ICU 63) ------------------ 1000 * 1001 * Switched from UTrie2 to UCPTrie/CodePointTrie. 1002 * 1003 * The new trie no longer stores different values for surrogate code *units* vs. 1004 * surrogate code *points*. 1005 * Lead surrogates still have values for optimized UTF-16 string processing. 1006 * When looking up code point properties, the code now checks for lead surrogates and 1007 * treats them as inert. 1008 * 1009 * gennorm2 now has to reject mappings for surrogate code points. 1010 * UTS #46 maps unpaired surrogates to U+FFFD in code rather than via its 1011 * custom normalization data file. 1012 * 1013 * Changes from format version 4 to format version 5 (ICU 76) ------------------ 1014 * 1015 * Unicode 16 adds the first MaybeYes characters which combine both backward and forward, 1016 * taking this formerly theoretical data structure into reality. 1017 * 1018 * Unicode 16 also adds the first characters that have two-way mappings whose first characters 1019 * combine backward. In order for normalization and the quick check to work properly, 1020 * these composite characters also must be marked as NFC_QC=Maybe, 1021 * corresponding to "combines back", although the composites themselves do not combine backward. 1022 * Format version 5 adds two new ranges between "algorithmic NoNo" and MaybeYes, 1023 * with thresholds minMaybeNo and minMaybeNoCombinesFwd, 1024 * and indexes[IX_MIN_MAYBE_NO] and indexes[IX_MIN_MAYBE_NO_COMBINES_FWD], 1025 * and corresponding mappings and composition lists in the extraData. 1026 * 1027 * Format version 5 moves the data for Maybe* characters from the start of the extraData array 1028 * to its end. 1029 */ 1030 1031 #endif /* !UCONFIG_NO_NORMALIZATION */ 1032 #endif /* __NORMALIZER2IMPL_H__ */ 1033