normalizer2impl.h 43 KB

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