normalizer2impl.h 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  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 (uint32_t)(c-JAMO_L_BASE)<JAMO_L_COUNT;
  71. }
  72. static inline UBool isJamoV(UChar32 c) {
  73. return (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, UChar buffer[3]) {
  88. c-=HANGUL_BASE;
  89. UChar32 c2=c%JAMO_T_COUNT;
  90. c/=JAMO_T_COUNT;
  91. buffer[0]=(UChar)(JAMO_L_BASE+c/JAMO_V_COUNT);
  92. buffer[1]=(UChar)(JAMO_V_BASE+c%JAMO_V_COUNT);
  93. if(c2==0) {
  94. return 2;
  95. } else {
  96. buffer[2]=(UChar)(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, UChar 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]=(UChar)(JAMO_L_BASE+c/JAMO_V_COUNT);
  111. buffer[1]=(UChar)(JAMO_V_BASE+c%JAMO_V_COUNT);
  112. } else {
  113. buffer[0]=(UChar)(orig-c2); // LV syllable
  114. buffer[1]=(UChar)(JAMO_T_BASE+c2);
  115. }
  116. }
  117. private:
  118. Hangul(); // 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(NULL), reorderStart(NULL), limit(NULL),
  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!=NULL) {
  132. str.releaseBuffer((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 (int32_t)(limit-start); }
  138. UChar *getStart() { return start; }
  139. UChar *getLimit() { return limit; }
  140. uint8_t getLastCC() const { return lastCC; }
  141. UBool equals(const UChar *start, const UChar *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((UChar)c, cc, errorCode) :
  146. appendSupplementary(c, cc, errorCode);
  147. }
  148. UBool append(const UChar *s, int32_t length, UBool isNFD,
  149. uint8_t leadCC, uint8_t trailCC,
  150. UErrorCode &errorCode);
  151. UBool appendBMP(UChar 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 UChar *s, const UChar *sLimit, UErrorCode &errorCode);
  169. void remove();
  170. void removeSuffix(int32_t suffixLength);
  171. void setReorderingLimit(UChar *newLimit) {
  172. remainingCapacity+=(int32_t)(limit-newLimit);
  173. reorderStart=limit=newLimit;
  174. lastCC=0;
  175. }
  176. void copyReorderableSuffixTo(UnicodeString &s) const {
  177. s.setTo(ConstChar16Ptr(reorderStart), (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(UChar *p, UChar32 c) {
  195. if(c<=0xffff) {
  196. *p=(UChar)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. UChar *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. UChar *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. * http://site.icu-project.org/design/normalization/custom
  219. */
  220. class U_COMMON_API Normalizer2Impl : public UObject {
  221. public:
  222. Normalizer2Impl() : normTrie(NULL), fCanonIterData(NULL) { }
  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(minMaybeYes<=norm16) {
  243. return UNORM_MAYBE;
  244. } else {
  245. return UNORM_NO;
  246. }
  247. }
  248. UBool isAlgorithmicNoNo(uint16_t norm16) const { return limitNoNo<=norm16 && norm16<minMaybeYes; }
  249. UBool isCompNo(uint16_t norm16) const { return minNoNo<=norm16 && norm16<minMaybeYes; }
  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 (uint8_t)(norm16 >> OFFSET_SHIFT);
  262. }
  263. static uint8_t getCCFromYesOrMaybe(uint16_t norm16) {
  264. return norm16>=MIN_NORMAL_MAYBE_YES ? getCCFromNormalYesOrMaybe(norm16) : 0;
  265. }
  266. uint8_t getCCFromYesOrMaybeCP(UChar32 c) const {
  267. if (c < minCompNoMaybeCP) { return 0; }
  268. return getCCFromYesOrMaybe(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 UChar *&s, const UChar *limit) const {
  292. UChar32 c=*s++;
  293. if(c<minDecompNoCP || !singleLeadMightHaveNonZeroFCD16(c)) {
  294. return 0;
  295. }
  296. UChar 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 UChar *start, const UChar *&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. UChar 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 (UBool)((bits>>((lead>>5)&7))&1);
  333. }
  334. /** Returns the FCD value from the regular normalization data. */
  335. uint16_t getFCD16FromNormData(UChar32 c) const;
  336. /**
  337. * Gets the decomposition for one code point.
  338. * @param c code point
  339. * @param buffer out-only buffer for algorithmic decompositions
  340. * @param length out-only, takes the length of the decomposition, if any
  341. * @return pointer to the decomposition, or NULL if none
  342. */
  343. const UChar *getDecomposition(UChar32 c, UChar buffer[4], int32_t &length) const;
  344. /**
  345. * Gets the raw decomposition for one code point.
  346. * @param c code point
  347. * @param buffer out-only buffer for algorithmic decompositions
  348. * @param length out-only, takes the length of the decomposition, if any
  349. * @return pointer to the decomposition, or NULL if none
  350. */
  351. const UChar *getRawDecomposition(UChar32 c, UChar buffer[30], int32_t &length) const;
  352. UChar32 composePair(UChar32 a, UChar32 b) const;
  353. UBool isCanonSegmentStarter(UChar32 c) const;
  354. UBool getCanonStartSet(UChar32 c, UnicodeSet &set) const;
  355. enum {
  356. // Fixed norm16 values.
  357. MIN_YES_YES_WITH_CC=0xfe02,
  358. JAMO_VT=0xfe00,
  359. MIN_NORMAL_MAYBE_YES=0xfc00,
  360. JAMO_L=2, // offset=1 hasCompBoundaryAfter=FALSE
  361. INERT=1, // offset=0 hasCompBoundaryAfter=TRUE
  362. // norm16 bit 0 is comp-boundary-after.
  363. HAS_COMP_BOUNDARY_AFTER=1,
  364. OFFSET_SHIFT=1,
  365. // For algorithmic one-way mappings, norm16 bits 2..1 indicate the
  366. // tccc (0, 1, >1) for quick FCC boundary-after tests.
  367. DELTA_TCCC_0=0,
  368. DELTA_TCCC_1=2,
  369. DELTA_TCCC_GT_1=4,
  370. DELTA_TCCC_MASK=6,
  371. DELTA_SHIFT=3,
  372. MAX_DELTA=0x40
  373. };
  374. enum {
  375. // Byte offsets from the start of the data, after the generic header.
  376. IX_NORM_TRIE_OFFSET,
  377. IX_EXTRA_DATA_OFFSET,
  378. IX_SMALL_FCD_OFFSET,
  379. IX_RESERVED3_OFFSET,
  380. IX_RESERVED4_OFFSET,
  381. IX_RESERVED5_OFFSET,
  382. IX_RESERVED6_OFFSET,
  383. IX_TOTAL_SIZE,
  384. // Code point thresholds for quick check codes.
  385. IX_MIN_DECOMP_NO_CP,
  386. IX_MIN_COMP_NO_MAYBE_CP,
  387. // Norm16 value thresholds for quick check combinations and types of extra data.
  388. /** Mappings & compositions in [minYesNo..minYesNoMappingsOnly[. */
  389. IX_MIN_YES_NO,
  390. /** Mappings are comp-normalized. */
  391. IX_MIN_NO_NO,
  392. IX_LIMIT_NO_NO,
  393. IX_MIN_MAYBE_YES,
  394. /** Mappings only in [minYesNoMappingsOnly..minNoNo[. */
  395. IX_MIN_YES_NO_MAPPINGS_ONLY,
  396. /** Mappings are not comp-normalized but have a comp boundary before. */
  397. IX_MIN_NO_NO_COMP_BOUNDARY_BEFORE,
  398. /** Mappings do not have a comp boundary before. */
  399. IX_MIN_NO_NO_COMP_NO_MAYBE_CC,
  400. /** Mappings to the empty string. */
  401. IX_MIN_NO_NO_EMPTY,
  402. IX_MIN_LCCC_CP,
  403. IX_RESERVED19,
  404. IX_COUNT
  405. };
  406. enum {
  407. MAPPING_HAS_CCC_LCCC_WORD=0x80,
  408. MAPPING_HAS_RAW_MAPPING=0x40,
  409. // unused bit 0x20,
  410. MAPPING_LENGTH_MASK=0x1f
  411. };
  412. enum {
  413. COMP_1_LAST_TUPLE=0x8000,
  414. COMP_1_TRIPLE=1,
  415. COMP_1_TRAIL_LIMIT=0x3400,
  416. COMP_1_TRAIL_MASK=0x7ffe,
  417. COMP_1_TRAIL_SHIFT=9, // 10-1 for the "triple" bit
  418. COMP_2_TRAIL_SHIFT=6,
  419. COMP_2_TRAIL_MASK=0xffc0
  420. };
  421. // higher-level functionality ------------------------------------------ ***
  422. // NFD without an NFD Normalizer2 instance.
  423. UnicodeString &decompose(const UnicodeString &src, UnicodeString &dest,
  424. UErrorCode &errorCode) const;
  425. /**
  426. * Decomposes [src, limit[ and writes the result to dest.
  427. * limit can be NULL if src is NUL-terminated.
  428. * destLengthEstimate is the initial dest buffer capacity and can be -1.
  429. */
  430. void decompose(const UChar *src, const UChar *limit,
  431. UnicodeString &dest, int32_t destLengthEstimate,
  432. UErrorCode &errorCode) const;
  433. const UChar *decompose(const UChar *src, const UChar *limit,
  434. ReorderingBuffer *buffer, UErrorCode &errorCode) const;
  435. void decomposeAndAppend(const UChar *src, const UChar *limit,
  436. UBool doDecompose,
  437. UnicodeString &safeMiddle,
  438. ReorderingBuffer &buffer,
  439. UErrorCode &errorCode) const;
  440. UBool compose(const UChar *src, const UChar *limit,
  441. UBool onlyContiguous,
  442. UBool doCompose,
  443. ReorderingBuffer &buffer,
  444. UErrorCode &errorCode) const;
  445. const UChar *composeQuickCheck(const UChar *src, const UChar *limit,
  446. UBool onlyContiguous,
  447. UNormalizationCheckResult *pQCResult) const;
  448. void composeAndAppend(const UChar *src, const UChar *limit,
  449. UBool doCompose,
  450. UBool onlyContiguous,
  451. UnicodeString &safeMiddle,
  452. ReorderingBuffer &buffer,
  453. UErrorCode &errorCode) const;
  454. /** sink==nullptr: isNormalized() */
  455. UBool composeUTF8(uint32_t options, UBool onlyContiguous,
  456. const uint8_t *src, const uint8_t *limit,
  457. ByteSink *sink, icu::Edits *edits, UErrorCode &errorCode) const;
  458. const UChar *makeFCD(const UChar *src, const UChar *limit,
  459. ReorderingBuffer *buffer, UErrorCode &errorCode) const;
  460. void makeFCDAndAppend(const UChar *src, const UChar *limit,
  461. UBool doMakeFCD,
  462. UnicodeString &safeMiddle,
  463. ReorderingBuffer &buffer,
  464. UErrorCode &errorCode) const;
  465. UBool hasDecompBoundaryBefore(UChar32 c) const;
  466. UBool norm16HasDecompBoundaryBefore(uint16_t norm16) const;
  467. UBool hasDecompBoundaryAfter(UChar32 c) const;
  468. UBool norm16HasDecompBoundaryAfter(uint16_t norm16) const;
  469. UBool isDecompInert(UChar32 c) const { return isDecompYesAndZeroCC(getNorm16(c)); }
  470. UBool hasCompBoundaryBefore(UChar32 c) const {
  471. return c<minCompNoMaybeCP || norm16HasCompBoundaryBefore(getNorm16(c));
  472. }
  473. UBool hasCompBoundaryAfter(UChar32 c, UBool onlyContiguous) const {
  474. return norm16HasCompBoundaryAfter(getNorm16(c), onlyContiguous);
  475. }
  476. UBool isCompInert(UChar32 c, UBool onlyContiguous) const {
  477. uint16_t norm16=getNorm16(c);
  478. return isCompYesAndZeroCC(norm16) &&
  479. (norm16 & HAS_COMP_BOUNDARY_AFTER) != 0 &&
  480. (!onlyContiguous || isInert(norm16) || *getMapping(norm16) <= 0x1ff);
  481. }
  482. UBool hasFCDBoundaryBefore(UChar32 c) const { return hasDecompBoundaryBefore(c); }
  483. UBool hasFCDBoundaryAfter(UChar32 c) const { return hasDecompBoundaryAfter(c); }
  484. UBool isFCDInert(UChar32 c) const { return getFCD16(c)<=1; }
  485. private:
  486. friend class InitCanonIterData;
  487. friend class LcccContext;
  488. UBool isMaybe(uint16_t norm16) const { return minMaybeYes<=norm16 && norm16<=JAMO_VT; }
  489. UBool isMaybeOrNonZeroCC(uint16_t norm16) const { return norm16>=minMaybeYes; }
  490. static UBool isInert(uint16_t norm16) { return norm16==INERT; }
  491. static UBool isJamoL(uint16_t norm16) { return norm16==JAMO_L; }
  492. static UBool isJamoVT(uint16_t norm16) { return norm16==JAMO_VT; }
  493. uint16_t hangulLVT() const { return minYesNoMappingsOnly|HAS_COMP_BOUNDARY_AFTER; }
  494. UBool isHangulLV(uint16_t norm16) const { return norm16==minYesNo; }
  495. UBool isHangulLVT(uint16_t norm16) const {
  496. return norm16==hangulLVT();
  497. }
  498. UBool isCompYesAndZeroCC(uint16_t norm16) const { return norm16<minNoNo; }
  499. // UBool isCompYes(uint16_t norm16) const {
  500. // return norm16>=MIN_YES_YES_WITH_CC || norm16<minNoNo;
  501. // }
  502. // UBool isCompYesOrMaybe(uint16_t norm16) const {
  503. // return norm16<minNoNo || minMaybeYes<=norm16;
  504. // }
  505. // UBool hasZeroCCFromDecompYes(uint16_t norm16) const {
  506. // return norm16<=MIN_NORMAL_MAYBE_YES || norm16==JAMO_VT;
  507. // }
  508. UBool isDecompYesAndZeroCC(uint16_t norm16) const {
  509. return norm16<minYesNo ||
  510. norm16==JAMO_VT ||
  511. (minMaybeYes<=norm16 && norm16<=MIN_NORMAL_MAYBE_YES);
  512. }
  513. /**
  514. * A little faster and simpler than isDecompYesAndZeroCC() but does not include
  515. * the MaybeYes which combine-forward and have ccc=0.
  516. * (Standard Unicode 10 normalization does not have such characters.)
  517. */
  518. UBool isMostDecompYesAndZeroCC(uint16_t norm16) const {
  519. return norm16<minYesNo || norm16==MIN_NORMAL_MAYBE_YES || norm16==JAMO_VT;
  520. }
  521. UBool isDecompNoAlgorithmic(uint16_t norm16) const { return norm16>=limitNoNo; }
  522. // For use with isCompYes().
  523. // Perhaps the compiler can combine the two tests for MIN_YES_YES_WITH_CC.
  524. // static uint8_t getCCFromYes(uint16_t norm16) {
  525. // return norm16>=MIN_YES_YES_WITH_CC ? getCCFromNormalYesOrMaybe(norm16) : 0;
  526. // }
  527. uint8_t getCCFromNoNo(uint16_t norm16) const {
  528. const uint16_t *mapping=getMapping(norm16);
  529. if(*mapping&MAPPING_HAS_CCC_LCCC_WORD) {
  530. return (uint8_t)*(mapping-1);
  531. } else {
  532. return 0;
  533. }
  534. }
  535. // requires that the [cpStart..cpLimit[ character passes isCompYesAndZeroCC()
  536. uint8_t getTrailCCFromCompYesAndZeroCC(uint16_t norm16) const {
  537. if(norm16<=minYesNo) {
  538. return 0; // yesYes and Hangul LV have ccc=tccc=0
  539. } else {
  540. // For Hangul LVT we harmlessly fetch a firstUnit with tccc=0 here.
  541. return (uint8_t)(*getMapping(norm16)>>8); // tccc from yesNo
  542. }
  543. }
  544. uint8_t getPreviousTrailCC(const UChar *start, const UChar *p) const;
  545. uint8_t getPreviousTrailCC(const uint8_t *start, const uint8_t *p) const;
  546. // Requires algorithmic-NoNo.
  547. UChar32 mapAlgorithmic(UChar32 c, uint16_t norm16) const {
  548. return c+(norm16>>DELTA_SHIFT)-centerNoNoDelta;
  549. }
  550. UChar32 getAlgorithmicDelta(uint16_t norm16) const {
  551. return (norm16>>DELTA_SHIFT)-centerNoNoDelta;
  552. }
  553. // Requires minYesNo<norm16<limitNoNo.
  554. const uint16_t *getMapping(uint16_t norm16) const { return extraData+(norm16>>OFFSET_SHIFT); }
  555. const uint16_t *getCompositionsListForDecompYes(uint16_t norm16) const {
  556. if(norm16<JAMO_L || MIN_NORMAL_MAYBE_YES<=norm16) {
  557. return NULL;
  558. } else if(norm16<minMaybeYes) {
  559. return getMapping(norm16); // for yesYes; if Jamo L: harmless empty list
  560. } else {
  561. return maybeYesCompositions+norm16-minMaybeYes;
  562. }
  563. }
  564. const uint16_t *getCompositionsListForComposite(uint16_t norm16) const {
  565. // A composite has both mapping & compositions list.
  566. const uint16_t *list=getMapping(norm16);
  567. return list+ // mapping pointer
  568. 1+ // +1 to skip the first unit with the mapping length
  569. (*list&MAPPING_LENGTH_MASK); // + mapping length
  570. }
  571. const uint16_t *getCompositionsListForMaybe(uint16_t norm16) const {
  572. // minMaybeYes<=norm16<MIN_NORMAL_MAYBE_YES
  573. return maybeYesCompositions+((norm16-minMaybeYes)>>OFFSET_SHIFT);
  574. }
  575. /**
  576. * @param c code point must have compositions
  577. * @return compositions list pointer
  578. */
  579. const uint16_t *getCompositionsList(uint16_t norm16) const {
  580. return isDecompYes(norm16) ?
  581. getCompositionsListForDecompYes(norm16) :
  582. getCompositionsListForComposite(norm16);
  583. }
  584. const UChar *copyLowPrefixFromNulTerminated(const UChar *src,
  585. UChar32 minNeedDataCP,
  586. ReorderingBuffer *buffer,
  587. UErrorCode &errorCode) const;
  588. const UChar *decomposeShort(const UChar *src, const UChar *limit,
  589. UBool stopAtCompBoundary, UBool onlyContiguous,
  590. ReorderingBuffer &buffer, UErrorCode &errorCode) const;
  591. UBool decompose(UChar32 c, uint16_t norm16,
  592. ReorderingBuffer &buffer, UErrorCode &errorCode) const;
  593. const uint8_t *decomposeShort(const uint8_t *src, const uint8_t *limit,
  594. UBool stopAtCompBoundary, UBool onlyContiguous,
  595. ReorderingBuffer &buffer, UErrorCode &errorCode) const;
  596. static int32_t combine(const uint16_t *list, UChar32 trail);
  597. void addComposites(const uint16_t *list, UnicodeSet &set) const;
  598. void recompose(ReorderingBuffer &buffer, int32_t recomposeStartIndex,
  599. UBool onlyContiguous) const;
  600. UBool hasCompBoundaryBefore(UChar32 c, uint16_t norm16) const {
  601. return c<minCompNoMaybeCP || norm16HasCompBoundaryBefore(norm16);
  602. }
  603. UBool norm16HasCompBoundaryBefore(uint16_t norm16) const {
  604. return norm16 < minNoNoCompNoMaybeCC || isAlgorithmicNoNo(norm16);
  605. }
  606. UBool hasCompBoundaryBefore(const UChar *src, const UChar *limit) const;
  607. UBool hasCompBoundaryBefore(const uint8_t *src, const uint8_t *limit) const;
  608. UBool hasCompBoundaryAfter(const UChar *start, const UChar *p,
  609. UBool onlyContiguous) const;
  610. UBool hasCompBoundaryAfter(const uint8_t *start, const uint8_t *p,
  611. UBool onlyContiguous) const;
  612. UBool norm16HasCompBoundaryAfter(uint16_t norm16, UBool onlyContiguous) const {
  613. return (norm16 & HAS_COMP_BOUNDARY_AFTER) != 0 &&
  614. (!onlyContiguous || isTrailCC01ForCompBoundaryAfter(norm16));
  615. }
  616. /** For FCC: Given norm16 HAS_COMP_BOUNDARY_AFTER, does it have tccc<=1? */
  617. UBool isTrailCC01ForCompBoundaryAfter(uint16_t norm16) const {
  618. return isInert(norm16) || (isDecompNoAlgorithmic(norm16) ?
  619. (norm16 & DELTA_TCCC_MASK) <= DELTA_TCCC_1 : *getMapping(norm16) <= 0x1ff);
  620. }
  621. const UChar *findPreviousCompBoundary(const UChar *start, const UChar *p, UBool onlyContiguous) const;
  622. const UChar *findNextCompBoundary(const UChar *p, const UChar *limit, UBool onlyContiguous) const;
  623. const UChar *findPreviousFCDBoundary(const UChar *start, const UChar *p) const;
  624. const UChar *findNextFCDBoundary(const UChar *p, const UChar *limit) const;
  625. void makeCanonIterDataFromNorm16(UChar32 start, UChar32 end, const uint16_t norm16,
  626. CanonIterData &newData, UErrorCode &errorCode) const;
  627. int32_t getCanonValue(UChar32 c) const;
  628. const UnicodeSet &getCanonStartSet(int32_t n) const;
  629. // UVersionInfo dataVersion;
  630. // BMP code point thresholds for quick check loops looking at single UTF-16 code units.
  631. UChar minDecompNoCP;
  632. UChar minCompNoMaybeCP;
  633. UChar minLcccCP;
  634. // Norm16 value thresholds for quick check combinations and types of extra data.
  635. uint16_t minYesNo;
  636. uint16_t minYesNoMappingsOnly;
  637. uint16_t minNoNo;
  638. uint16_t minNoNoCompBoundaryBefore;
  639. uint16_t minNoNoCompNoMaybeCC;
  640. uint16_t minNoNoEmpty;
  641. uint16_t limitNoNo;
  642. uint16_t centerNoNoDelta;
  643. uint16_t minMaybeYes;
  644. const UCPTrie *normTrie;
  645. const uint16_t *maybeYesCompositions;
  646. const uint16_t *extraData; // mappings and/or compositions for yesYes, yesNo & noNo characters
  647. const uint8_t *smallFCD; // [0x100] one bit per 32 BMP code points, set if any FCD!=0
  648. UInitOnce fCanonIterDataInitOnce = U_INITONCE_INITIALIZER;
  649. CanonIterData *fCanonIterData;
  650. };
  651. // bits in canonIterData
  652. #define CANON_NOT_SEGMENT_STARTER 0x80000000
  653. #define CANON_HAS_COMPOSITIONS 0x40000000
  654. #define CANON_HAS_SET 0x200000
  655. #define CANON_VALUE_MASK 0x1fffff
  656. /**
  657. * ICU-internal shortcut for quick access to standard Unicode normalization.
  658. */
  659. class U_COMMON_API Normalizer2Factory {
  660. public:
  661. static const Normalizer2 *getFCDInstance(UErrorCode &errorCode);
  662. static const Normalizer2 *getFCCInstance(UErrorCode &errorCode);
  663. static const Normalizer2 *getNoopInstance(UErrorCode &errorCode);
  664. static const Normalizer2 *getInstance(UNormalizationMode mode, UErrorCode &errorCode);
  665. static const Normalizer2Impl *getNFCImpl(UErrorCode &errorCode);
  666. static const Normalizer2Impl *getNFKCImpl(UErrorCode &errorCode);
  667. static const Normalizer2Impl *getNFKC_CFImpl(UErrorCode &errorCode);
  668. // Get the Impl instance of the Normalizer2.
  669. // Must be used only when it is known that norm2 is a Normalizer2WithImpl instance.
  670. static const Normalizer2Impl *getImpl(const Normalizer2 *norm2);
  671. private:
  672. Normalizer2Factory(); // No instantiation.
  673. };
  674. U_NAMESPACE_END
  675. U_CAPI int32_t U_EXPORT2
  676. unorm2_swap(const UDataSwapper *ds,
  677. const void *inData, int32_t length, void *outData,
  678. UErrorCode *pErrorCode);
  679. /**
  680. * Get the NF*_QC property for a code point, for u_getIntPropertyValue().
  681. * @internal
  682. */
  683. U_CFUNC UNormalizationCheckResult
  684. unorm_getQuickCheck(UChar32 c, UNormalizationMode mode);
  685. /**
  686. * Gets the 16-bit FCD value (lead & trail CCs) for a code point, for u_getIntPropertyValue().
  687. * @internal
  688. */
  689. U_CFUNC uint16_t
  690. unorm_getFCD16(UChar32 c);
  691. /**
  692. * Format of Normalizer2 .nrm data files.
  693. * Format version 4.0.
  694. *
  695. * Normalizer2 .nrm data files provide data for the Unicode Normalization algorithms.
  696. * ICU ships with data files for standard Unicode Normalization Forms
  697. * NFC and NFD (nfc.nrm), NFKC and NFKD (nfkc.nrm) and NFKC_Casefold (nfkc_cf.nrm).
  698. * Custom (application-specific) data can be built into additional .nrm files
  699. * with the gennorm2 build tool.
  700. * ICU ships with one such file, uts46.nrm, for the implementation of UTS #46.
  701. *
  702. * Normalizer2.getInstance() causes a .nrm file to be loaded, unless it has been
  703. * cached already. Internally, Normalizer2Impl.load() reads the .nrm file.
  704. *
  705. * A .nrm file begins with a standard ICU data file header
  706. * (DataHeader, see ucmndata.h and unicode/udata.h).
  707. * The UDataInfo.dataVersion field usually contains the Unicode version
  708. * for which the data was generated.
  709. *
  710. * After the header, the file contains the following parts.
  711. * Constants are defined as enum values of the Normalizer2Impl class.
  712. *
  713. * Many details of the data structures are described in the design doc
  714. * which is at http://site.icu-project.org/design/normalization/custom
  715. *
  716. * int32_t indexes[indexesLength]; -- indexesLength=indexes[IX_NORM_TRIE_OFFSET]/4;
  717. *
  718. * The first eight indexes are byte offsets in ascending order.
  719. * Each byte offset marks the start of the next part in the data file,
  720. * and the end of the previous one.
  721. * When two consecutive byte offsets are the same, then the corresponding part is empty.
  722. * Byte offsets are offsets from after the header,
  723. * that is, from the beginning of the indexes[].
  724. * Each part starts at an offset with proper alignment for its data.
  725. * If necessary, the previous part may include padding bytes to achieve this alignment.
  726. *
  727. * minDecompNoCP=indexes[IX_MIN_DECOMP_NO_CP] is the lowest code point
  728. * with a decomposition mapping, that is, with NF*D_QC=No.
  729. * minCompNoMaybeCP=indexes[IX_MIN_COMP_NO_MAYBE_CP] is the lowest code point
  730. * with NF*C_QC=No (has a one-way mapping) or Maybe (combines backward).
  731. * minLcccCP=indexes[IX_MIN_LCCC_CP] (index 18, new in formatVersion 3)
  732. * is the lowest code point with lccc!=0.
  733. *
  734. * The next eight indexes are thresholds of 16-bit trie values for ranges of
  735. * values indicating multiple normalization properties.
  736. * They are listed here in threshold order, not in the order they are stored in the indexes.
  737. * minYesNo=indexes[IX_MIN_YES_NO];
  738. * minYesNoMappingsOnly=indexes[IX_MIN_YES_NO_MAPPINGS_ONLY];
  739. * minNoNo=indexes[IX_MIN_NO_NO];
  740. * minNoNoCompBoundaryBefore=indexes[IX_MIN_NO_NO_COMP_BOUNDARY_BEFORE];
  741. * minNoNoCompNoMaybeCC=indexes[IX_MIN_NO_NO_COMP_NO_MAYBE_CC];
  742. * minNoNoEmpty=indexes[IX_MIN_NO_NO_EMPTY];
  743. * limitNoNo=indexes[IX_LIMIT_NO_NO];
  744. * minMaybeYes=indexes[IX_MIN_MAYBE_YES];
  745. * See the normTrie description below and the design doc for details.
  746. *
  747. * UCPTrie normTrie; -- see ucptrie_impl.h and ucptrie.h, same as Java CodePointTrie
  748. *
  749. * The trie holds the main normalization data. Each code point is mapped to a 16-bit value.
  750. * Rather than using independent bits in the value (which would require more than 16 bits),
  751. * information is extracted primarily via range checks.
  752. * Except, format version 3 uses bit 0 for hasCompBoundaryAfter().
  753. * For example, a 16-bit value norm16 in the range minYesNo<=norm16<minNoNo
  754. * means that the character has NF*C_QC=Yes and NF*D_QC=No properties,
  755. * which means it has a two-way (round-trip) decomposition mapping.
  756. * Values in the range 2<=norm16<limitNoNo are also directly indexes into the extraData
  757. * pointing to mappings, compositions lists, or both.
  758. * Value norm16==INERT (0 in versions 1 & 2, 1 in version 3)
  759. * means that the character is normalization-inert, that is,
  760. * it does not have a mapping, does not participate in composition, has a zero
  761. * canonical combining class, and forms a boundary where text before it and after it
  762. * can be normalized independently.
  763. * For details about how multiple properties are encoded in 16-bit values
  764. * see the design doc.
  765. * Note that the encoding cannot express all combinations of the properties involved;
  766. * it only supports those combinations that are allowed by
  767. * the Unicode Normalization algorithms. Details are in the design doc as well.
  768. * The gennorm2 tool only builds .nrm files for data that conforms to the limitations.
  769. *
  770. * The trie has a value for each lead surrogate code unit representing the "worst case"
  771. * properties of the 1024 supplementary characters whose UTF-16 form starts with
  772. * the lead surrogate. If all of the 1024 supplementary characters are normalization-inert,
  773. * then their lead surrogate code unit has the trie value INERT.
  774. * When the lead surrogate unit's value exceeds the quick check minimum during processing,
  775. * the properties for the full supplementary code point need to be looked up.
  776. *
  777. * uint16_t maybeYesCompositions[MIN_NORMAL_MAYBE_YES-minMaybeYes];
  778. * uint16_t extraData[];
  779. *
  780. * There is only one byte offset for the end of these two arrays.
  781. * The split between them is given by the constant and variable mentioned above.
  782. * In version 3, the difference must be shifted right by OFFSET_SHIFT.
  783. *
  784. * The maybeYesCompositions array contains compositions lists for characters that
  785. * combine both forward (as starters in composition pairs)
  786. * and backward (as trailing characters in composition pairs).
  787. * Such characters do not occur in Unicode 5.2 but are allowed by
  788. * the Unicode Normalization algorithms.
  789. * If there are no such characters, then minMaybeYes==MIN_NORMAL_MAYBE_YES
  790. * and the maybeYesCompositions array is empty.
  791. * If there are such characters, then minMaybeYes is subtracted from their norm16 values
  792. * to get the index into this array.
  793. *
  794. * The extraData array contains compositions lists for "YesYes" characters,
  795. * followed by mappings and optional compositions lists for "YesNo" characters,
  796. * followed by only mappings for "NoNo" characters.
  797. * (Referring to pairs of NFC/NFD quick check values.)
  798. * The norm16 values of those characters are directly indexes into the extraData array.
  799. * In version 3, the norm16 values must be shifted right by OFFSET_SHIFT
  800. * for accessing extraData.
  801. *
  802. * The data structures for compositions lists and mappings are described in the design doc.
  803. *
  804. * uint8_t smallFCD[0x100]; -- new in format version 2
  805. *
  806. * This is a bit set to help speed up FCD value lookups in the absence of a full
  807. * UTrie2 or other large data structure with the full FCD value mapping.
  808. *
  809. * Each smallFCD bit is set if any of the corresponding 32 BMP code points
  810. * has a non-zero FCD value (lccc!=0 or tccc!=0).
  811. * Bit 0 of smallFCD[0] is for U+0000..U+001F. Bit 7 of smallFCD[0xff] is for U+FFE0..U+FFFF.
  812. * A bit for 32 lead surrogates is set if any of the 32k corresponding
  813. * _supplementary_ code points has a non-zero FCD value.
  814. *
  815. * This bit set is most useful for the large blocks of CJK characters with FCD=0.
  816. *
  817. * Changes from format version 1 to format version 2 ---------------------------
  818. *
  819. * - Addition of data for raw (not recursively decomposed) mappings.
  820. * + The MAPPING_NO_COMP_BOUNDARY_AFTER bit in the extraData is now also set when
  821. * the mapping is to an empty string or when the character combines-forward.
  822. * This subsumes the one actual use of the MAPPING_PLUS_COMPOSITION_LIST bit which
  823. * is then repurposed for the MAPPING_HAS_RAW_MAPPING bit.
  824. * + For details see the design doc.
  825. * - Addition of indexes[IX_MIN_YES_NO_MAPPINGS_ONLY] and separation of the yesNo extraData into
  826. * distinct ranges (combines-forward vs. not)
  827. * so that a range check can be used to find out if there is a compositions list.
  828. * This is fully equivalent with formatVersion 1's MAPPING_PLUS_COMPOSITION_LIST flag.
  829. * It is needed for the new (in ICU 49) composePair(), not for other normalization.
  830. * - Addition of the smallFCD[] bit set.
  831. *
  832. * Changes from format version 2 to format version 3 (ICU 60) ------------------
  833. *
  834. * - norm16 bit 0 indicates hasCompBoundaryAfter(),
  835. * except that for contiguous composition (FCC) the tccc must be checked as well.
  836. * Data indexes and ccc values are shifted left by one (OFFSET_SHIFT).
  837. * Thresholds like minNoNo are tested before shifting.
  838. *
  839. * - Algorithmic mapping deltas are shifted left by two more bits (total DELTA_SHIFT),
  840. * to make room for two bits (three values) indicating whether the tccc is 0, 1, or greater.
  841. * See DELTA_TCCC_MASK etc.
  842. * This helps with fetching tccc/FCD values and FCC hasCompBoundaryAfter().
  843. * minMaybeYes is 8-aligned so that the DELTA_TCCC_MASK bits can be tested directly.
  844. *
  845. * - Algorithmic mappings are only used for mapping to "comp yes and ccc=0" characters,
  846. * and ASCII characters are mapped algorithmically only to other ASCII characters.
  847. * This helps with hasCompBoundaryBefore() and compose() fast paths.
  848. * It is never necessary any more to loop for algorithmic mappings.
  849. *
  850. * - Addition of indexes[IX_MIN_NO_NO_COMP_BOUNDARY_BEFORE],
  851. * indexes[IX_MIN_NO_NO_COMP_NO_MAYBE_CC], and indexes[IX_MIN_NO_NO_EMPTY],
  852. * and separation of the noNo extraData into distinct ranges.
  853. * With this, the noNo norm16 value indicates whether the mapping is
  854. * compose-normalized, not normalized but hasCompBoundaryBefore(),
  855. * not even that, or maps to an empty string.
  856. * hasCompBoundaryBefore() can be determined solely from the norm16 value.
  857. *
  858. * - The norm16 value for Hangul LVT is now different from that for Hangul LV,
  859. * so that hasCompBoundaryAfter() need not check for the syllable type.
  860. * For Hangul LV, minYesNo continues to be used (no comp-boundary-after).
  861. * For Hangul LVT, minYesNoMappingsOnly|HAS_COMP_BOUNDARY_AFTER is used.
  862. * The extraData units at these indexes are set to firstUnit=2 and firstUnit=3, respectively,
  863. * to simplify some code.
  864. *
  865. * - The extraData firstUnit bit 5 is no longer necessary
  866. * (norm16 bit 0 used instead of firstUnit MAPPING_NO_COMP_BOUNDARY_AFTER),
  867. * is reserved again, and always set to 0.
  868. *
  869. * - Addition of indexes[IX_MIN_LCCC_CP], the first code point where lccc!=0.
  870. * This used to be hardcoded to U+0300, but in data like NFKC_Casefold it is lower:
  871. * U+00AD Soft Hyphen maps to an empty string,
  872. * which is artificially assigned "worst case" values lccc=1 and tccc=255.
  873. *
  874. * - A mapping to an empty string has explicit lccc=1 and tccc=255 values.
  875. *
  876. * Changes from format version 3 to format version 4 (ICU 63) ------------------
  877. *
  878. * Switched from UTrie2 to UCPTrie/CodePointTrie.
  879. *
  880. * The new trie no longer stores different values for surrogate code *units* vs.
  881. * surrogate code *points*.
  882. * Lead surrogates still have values for optimized UTF-16 string processing.
  883. * When looking up code point properties, the code now checks for lead surrogates and
  884. * treats them as inert.
  885. *
  886. * gennorm2 now has to reject mappings for surrogate code points.
  887. * UTS #46 maps unpaired surrogates to U+FFFD in code rather than via its
  888. * custom normalization data file.
  889. */
  890. #endif /* !UCONFIG_NO_NORMALIZATION */
  891. #endif /* __NORMALIZER2IMPL_H__ */