1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
6 * Copyright (C) 2009-2014, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 *******************************************************************************
10 * file name: normalizer2impl.h
12 * tab size: 8 (not used)
15 * created on: 2009nov22
16 * created by: Markus W. Scherer
19 #ifndef __NORMALIZER2IMPL_H__
20 #define __NORMALIZER2IMPL_H__
22 #include "unicode/utypes.h"
24 #if !UCONFIG_NO_NORMALIZATION
26 #include "unicode/normalizer2.h"
27 #include "unicode/unistr.h"
28 #include "unicode/unorm.h"
29 #include "unicode/utf16.h"
38 class U_COMMON_API Hangul
{
40 /* Korean Hangul and Jamo constants */
42 JAMO_L_BASE
=0x1100, /* "lead" jamo */
44 JAMO_V_BASE
=0x1161, /* "vowel" jamo */
46 JAMO_T_BASE
=0x11a7, /* "trail" jamo */
56 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
62 static inline UBool
isHangul(UChar32 c
) {
63 return HANGUL_BASE
<=c
&& c
<HANGUL_LIMIT
;
66 isHangulWithoutJamoT(UChar c
) {
68 return c
<HANGUL_COUNT
&& c%JAMO_T_COUNT
==0;
70 static inline UBool
isJamoL(UChar32 c
) {
71 return (uint32_t)(c
-JAMO_L_BASE
)<JAMO_L_COUNT
;
73 static inline UBool
isJamoV(UChar32 c
) {
74 return (uint32_t)(c
-JAMO_V_BASE
)<JAMO_V_COUNT
;
78 * Decomposes c, which must be a Hangul syllable, into buffer
79 * and returns the length of the decomposition (2 or 3).
81 static inline int32_t decompose(UChar32 c
, UChar buffer
[3]) {
83 UChar32 c2
=c%JAMO_T_COUNT
;
85 buffer
[0]=(UChar
)(JAMO_L_BASE
+c
/JAMO_V_COUNT
);
86 buffer
[1]=(UChar
)(JAMO_V_BASE
+c%JAMO_V_COUNT
);
90 buffer
[2]=(UChar
)(JAMO_T_BASE
+c2
);
96 * Decomposes c, which must be a Hangul syllable, into buffer.
97 * This is the raw, not recursive, decomposition. Its length is always 2.
99 static inline void getRawDecomposition(UChar32 c
, UChar buffer
[2]) {
102 UChar32 c2
=c%JAMO_T_COUNT
;
105 buffer
[0]=(UChar
)(JAMO_L_BASE
+c
/JAMO_V_COUNT
);
106 buffer
[1]=(UChar
)(JAMO_V_BASE
+c%JAMO_V_COUNT
);
108 buffer
[0]=orig
-c2
; // LV syllable
109 buffer
[1]=(UChar
)(JAMO_T_BASE
+c2
);
113 Hangul(); // no instantiation
116 class Normalizer2Impl
;
118 class U_COMMON_API ReorderingBuffer
: public UMemory
{
120 ReorderingBuffer(const Normalizer2Impl
&ni
, UnicodeString
&dest
) :
122 start(NULL
), reorderStart(NULL
), limit(NULL
),
123 remainingCapacity(0), lastCC(0) {}
124 ~ReorderingBuffer() {
126 str
.releaseBuffer((int32_t)(limit
-start
));
129 UBool
init(int32_t destCapacity
, UErrorCode
&errorCode
);
131 UBool
isEmpty() const { return start
==limit
; }
132 int32_t length() const { return (int32_t)(limit
-start
); }
133 UChar
*getStart() { return start
; }
134 UChar
*getLimit() { return limit
; }
135 uint8_t getLastCC() const { return lastCC
; }
137 UBool
equals(const UChar
*start
, const UChar
*limit
) const;
139 // For Hangul composition, replacing the Leading consonant Jamo with the syllable.
140 void setLastChar(UChar c
) {
144 UBool
append(UChar32 c
, uint8_t cc
, UErrorCode
&errorCode
) {
146 appendBMP((UChar
)c
, cc
, errorCode
) :
147 appendSupplementary(c
, cc
, errorCode
);
149 // s must be in NFD, otherwise change the implementation.
150 UBool
append(const UChar
*s
, int32_t length
,
151 uint8_t leadCC
, uint8_t trailCC
,
152 UErrorCode
&errorCode
);
153 UBool
appendBMP(UChar c
, uint8_t cc
, UErrorCode
&errorCode
) {
154 if(remainingCapacity
==0 && !resize(1, errorCode
)) {
157 if(lastCC
<=cc
|| cc
==0) {
169 UBool
appendZeroCC(UChar32 c
, UErrorCode
&errorCode
);
170 UBool
appendZeroCC(const UChar
*s
, const UChar
*sLimit
, UErrorCode
&errorCode
);
172 void removeSuffix(int32_t suffixLength
);
173 void setReorderingLimit(UChar
*newLimit
) {
174 remainingCapacity
+=(int32_t)(limit
-newLimit
);
175 reorderStart
=limit
=newLimit
;
178 void copyReorderableSuffixTo(UnicodeString
&s
) const {
179 s
.setTo(ConstChar16Ptr(reorderStart
), (int32_t)(limit
-reorderStart
));
183 * TODO: Revisit whether it makes sense to track reorderStart.
184 * It is set to after the last known character with cc<=1,
185 * which stops previousCC() before it reads that character and looks up its cc.
186 * previousCC() is normally only called from insert().
187 * In other words, reorderStart speeds up the insertion of a combining mark
188 * into a multi-combining mark sequence where it does not belong at the end.
189 * This might not be worth the trouble.
190 * On the other hand, it's not a huge amount of trouble.
192 * We probably need it for UNORM_SIMPLE_APPEND.
195 UBool
appendSupplementary(UChar32 c
, uint8_t cc
, UErrorCode
&errorCode
);
196 void insert(UChar32 c
, uint8_t cc
);
197 static void writeCodePoint(UChar
*p
, UChar32 c
) {
205 UBool
resize(int32_t appendLength
, UErrorCode
&errorCode
);
207 const Normalizer2Impl
&impl
;
209 UChar
*start
, *reorderStart
, *limit
;
210 int32_t remainingCapacity
;
213 // private backward iterator
214 void setIterator() { codePointStart
=limit
; }
215 void skipPrevious(); // Requires start<codePointStart.
216 uint8_t previousCC(); // Returns 0 if there is no previous character.
218 UChar
*codePointStart
, *codePointLimit
;
221 class U_COMMON_API Normalizer2Impl
: public UObject
{
223 Normalizer2Impl() : normTrie(NULL
), fCanonIterData(NULL
) {
224 fCanonIterDataInitOnce
.reset();
226 virtual ~Normalizer2Impl();
228 void init(const int32_t *inIndexes
, const UTrie2
*inTrie
,
229 const uint16_t *inExtraData
, const uint8_t *inSmallFCD
);
231 void addLcccChars(UnicodeSet
&set
) const;
232 void addPropertyStarts(const USetAdder
*sa
, UErrorCode
&errorCode
) const;
233 void addCanonIterPropertyStarts(const USetAdder
*sa
, UErrorCode
&errorCode
) const;
235 // low-level properties ------------------------------------------------ ***
237 const UTrie2
*getNormTrie() const { return normTrie
; }
239 UBool
ensureCanonIterData(UErrorCode
&errorCode
) const;
241 uint16_t getNorm16(UChar32 c
) const { return UTRIE2_GET16(normTrie
, c
); }
243 UNormalizationCheckResult
getCompQuickCheck(uint16_t norm16
) const {
244 if(norm16
<minNoNo
|| MIN_YES_YES_WITH_CC
<=norm16
) {
246 } else if(minMaybeYes
<=norm16
) {
252 UBool
isAlgorithmicNoNo(uint16_t norm16
) const { return limitNoNo
<=norm16
&& norm16
<minMaybeYes
; }
253 UBool
isCompNo(uint16_t norm16
) const { return minNoNo
<=norm16
&& norm16
<minMaybeYes
; }
254 UBool
isDecompYes(uint16_t norm16
) const { return norm16
<minYesNo
|| minMaybeYes
<=norm16
; }
256 uint8_t getCC(uint16_t norm16
) const {
257 if(norm16
>=MIN_NORMAL_MAYBE_YES
) {
258 return (uint8_t)norm16
;
260 if(norm16
<minNoNo
|| limitNoNo
<=norm16
) {
263 return getCCFromNoNo(norm16
);
265 static uint8_t getCCFromYesOrMaybe(uint16_t norm16
) {
266 return norm16
>=MIN_NORMAL_MAYBE_YES
? (uint8_t)norm16
: 0;
270 * Returns the FCD data for code point c.
271 * @param c A Unicode code point.
272 * @return The lccc(c) in bits 15..8 and tccc(c) in bits 7..0.
274 uint16_t getFCD16(UChar32 c
) const {
279 } else if(c
<=0xffff) {
280 if(!singleLeadMightHaveNonZeroFCD16(c
)) { return 0; }
282 return getFCD16FromNormData(c
);
285 * Returns the FCD data for the next code point (post-increment).
286 * Might skip only a lead surrogate rather than the whole surrogate pair if none of
287 * the supplementary code points associated with the lead surrogate have non-zero FCD data.
288 * @param s A valid pointer into a string. Requires s!=limit.
289 * @param limit The end of the string, or NULL.
290 * @return The lccc(c) in bits 15..8 and tccc(c) in bits 7..0.
292 uint16_t nextFCD16(const UChar
*&s
, const UChar
*limit
) const {
296 } else if(!singleLeadMightHaveNonZeroFCD16(c
)) {
300 if(U16_IS_LEAD(c
) && s
!=limit
&& U16_IS_TRAIL(c2
=*s
)) {
301 c
=U16_GET_SUPPLEMENTARY(c
, c2
);
304 return getFCD16FromNormData(c
);
307 * Returns the FCD data for the previous code point (pre-decrement).
308 * @param start The start of the string.
309 * @param s A valid pointer into a string. Requires start<s.
310 * @return The lccc(c) in bits 15..8 and tccc(c) in bits 7..0.
312 uint16_t previousFCD16(const UChar
*start
, const UChar
*&s
) const {
317 if(!U16_IS_TRAIL(c
)) {
318 if(!singleLeadMightHaveNonZeroFCD16(c
)) {
323 if(start
<s
&& U16_IS_LEAD(c2
=*(s
-1))) {
324 c
=U16_GET_SUPPLEMENTARY(c2
, c
);
328 return getFCD16FromNormData(c
);
331 /** Returns the FCD data for U+0000<=c<U+0180. */
332 uint16_t getFCD16FromBelow180(UChar32 c
) const { return tccc180
[c
]; }
333 /** Returns TRUE if the single-or-lead code unit c might have non-zero FCD data. */
334 UBool
singleLeadMightHaveNonZeroFCD16(UChar32 lead
) const {
336 uint8_t bits
=smallFCD
[lead
>>8];
337 if(bits
==0) { return false; }
338 return (UBool
)((bits
>>((lead
>>5)&7))&1);
340 /** Returns the FCD value from the regular normalization data. */
341 uint16_t getFCD16FromNormData(UChar32 c
) const;
343 void makeCanonIterDataFromNorm16(UChar32 start
, UChar32 end
, uint16_t norm16
,
344 CanonIterData
&newData
, UErrorCode
&errorCode
) const;
347 * Gets the decomposition for one code point.
348 * @param c code point
349 * @param buffer out-only buffer for algorithmic decompositions
350 * @param length out-only, takes the length of the decomposition, if any
351 * @return pointer to the decomposition, or NULL if none
353 const UChar
*getDecomposition(UChar32 c
, UChar buffer
[4], int32_t &length
) const;
356 * Gets the raw decomposition for one code point.
357 * @param c code point
358 * @param buffer out-only buffer for algorithmic decompositions
359 * @param length out-only, takes the length of the decomposition, if any
360 * @return pointer to the decomposition, or NULL if none
362 const UChar
*getRawDecomposition(UChar32 c
, UChar buffer
[30], int32_t &length
) const;
364 UChar32
composePair(UChar32 a
, UChar32 b
) const;
366 UBool
isCanonSegmentStarter(UChar32 c
) const;
367 UBool
getCanonStartSet(UChar32 c
, UnicodeSet
&set
) const;
370 MIN_CCC_LCCC_CP
=0x300
374 MIN_YES_YES_WITH_CC
=0xff01,
376 MIN_NORMAL_MAYBE_YES
=0xfe00,
382 // Byte offsets from the start of the data, after the generic header.
384 IX_EXTRA_DATA_OFFSET
,
392 // Code point thresholds for quick check codes.
394 IX_MIN_COMP_NO_MAYBE_CP
,
396 // Norm16 value thresholds for quick check combinations and types of extra data.
397 IX_MIN_YES_NO
, // Mappings & compositions in [minYesNo..minYesNoMappingsOnly[.
402 IX_MIN_YES_NO_MAPPINGS_ONLY
, // Mappings only in [minYesNoMappingsOnly..minNoNo[.
409 MAPPING_HAS_CCC_LCCC_WORD
=0x80,
410 MAPPING_HAS_RAW_MAPPING
=0x40,
411 MAPPING_NO_COMP_BOUNDARY_AFTER
=0x20,
412 MAPPING_LENGTH_MASK
=0x1f
416 COMP_1_LAST_TUPLE
=0x8000,
418 COMP_1_TRAIL_LIMIT
=0x3400,
419 COMP_1_TRAIL_MASK
=0x7ffe,
420 COMP_1_TRAIL_SHIFT
=9, // 10-1 for the "triple" bit
421 COMP_2_TRAIL_SHIFT
=6,
422 COMP_2_TRAIL_MASK
=0xffc0
425 // higher-level functionality ------------------------------------------ ***
427 // NFD without an NFD Normalizer2 instance.
428 UnicodeString
&decompose(const UnicodeString
&src
, UnicodeString
&dest
,
429 UErrorCode
&errorCode
) const;
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.
435 void decompose(const UChar
*src
, const UChar
*limit
,
436 UnicodeString
&dest
, int32_t destLengthEstimate
,
437 UErrorCode
&errorCode
) const;
439 const UChar
*decompose(const UChar
*src
, const UChar
*limit
,
440 ReorderingBuffer
*buffer
, UErrorCode
&errorCode
) const;
441 void decomposeAndAppend(const UChar
*src
, const UChar
*limit
,
443 UnicodeString
&safeMiddle
,
444 ReorderingBuffer
&buffer
,
445 UErrorCode
&errorCode
) const;
446 UBool
compose(const UChar
*src
, const UChar
*limit
,
447 UBool onlyContiguous
,
449 ReorderingBuffer
&buffer
,
450 UErrorCode
&errorCode
) const;
451 const UChar
*composeQuickCheck(const UChar
*src
, const UChar
*limit
,
452 UBool onlyContiguous
,
453 UNormalizationCheckResult
*pQCResult
) const;
454 void composeAndAppend(const UChar
*src
, const UChar
*limit
,
456 UBool onlyContiguous
,
457 UnicodeString
&safeMiddle
,
458 ReorderingBuffer
&buffer
,
459 UErrorCode
&errorCode
) const;
460 const UChar
*makeFCD(const UChar
*src
, const UChar
*limit
,
461 ReorderingBuffer
*buffer
, UErrorCode
&errorCode
) const;
462 void makeFCDAndAppend(const UChar
*src
, const UChar
*limit
,
464 UnicodeString
&safeMiddle
,
465 ReorderingBuffer
&buffer
,
466 UErrorCode
&errorCode
) const;
468 UBool
hasDecompBoundary(UChar32 c
, UBool before
) const;
469 UBool
isDecompInert(UChar32 c
) const { return isDecompYesAndZeroCC(getNorm16(c
)); }
471 UBool
hasCompBoundaryBefore(UChar32 c
) const {
472 return c
<minCompNoMaybeCP
|| hasCompBoundaryBefore(c
, getNorm16(c
));
474 UBool
hasCompBoundaryAfter(UChar32 c
, UBool onlyContiguous
, UBool testInert
) const;
476 UBool
hasFCDBoundaryBefore(UChar32 c
) const { return c
<MIN_CCC_LCCC_CP
|| getFCD16(c
)<=0xff; }
477 UBool
hasFCDBoundaryAfter(UChar32 c
) const {
478 uint16_t fcd16
=getFCD16(c
);
479 return fcd16
<=1 || (fcd16
&0xff)==0;
481 UBool
isFCDInert(UChar32 c
) const { return getFCD16(c
)<=1; }
483 UBool
isMaybe(uint16_t norm16
) const { return minMaybeYes
<=norm16
&& norm16
<=JAMO_VT
; }
484 UBool
isMaybeOrNonZeroCC(uint16_t norm16
) const { return norm16
>=minMaybeYes
; }
485 static UBool
isInert(uint16_t norm16
) { return norm16
==0; }
486 static UBool
isJamoL(uint16_t norm16
) { return norm16
==1; }
487 static UBool
isJamoVT(uint16_t norm16
) { return norm16
==JAMO_VT
; }
488 UBool
isHangul(uint16_t norm16
) const { return norm16
==minYesNo
; }
489 UBool
isCompYesAndZeroCC(uint16_t norm16
) const { return norm16
<minNoNo
; }
490 // UBool isCompYes(uint16_t norm16) const {
491 // return norm16>=MIN_YES_YES_WITH_CC || norm16<minNoNo;
493 // UBool isCompYesOrMaybe(uint16_t norm16) const {
494 // return norm16<minNoNo || minMaybeYes<=norm16;
496 // UBool hasZeroCCFromDecompYes(uint16_t norm16) const {
497 // return norm16<=MIN_NORMAL_MAYBE_YES || norm16==JAMO_VT;
499 UBool
isDecompYesAndZeroCC(uint16_t norm16
) const {
500 return norm16
<minYesNo
||
502 (minMaybeYes
<=norm16
&& norm16
<=MIN_NORMAL_MAYBE_YES
);
505 * A little faster and simpler than isDecompYesAndZeroCC() but does not include
506 * the MaybeYes which combine-forward and have ccc=0.
507 * (Standard Unicode 5.2 normalization does not have such characters.)
509 UBool
isMostDecompYesAndZeroCC(uint16_t norm16
) const {
510 return norm16
<minYesNo
|| norm16
==MIN_NORMAL_MAYBE_YES
|| norm16
==JAMO_VT
;
512 UBool
isDecompNoAlgorithmic(uint16_t norm16
) const { return norm16
>=limitNoNo
; }
514 // For use with isCompYes().
515 // Perhaps the compiler can combine the two tests for MIN_YES_YES_WITH_CC.
516 // static uint8_t getCCFromYes(uint16_t norm16) {
517 // return norm16>=MIN_YES_YES_WITH_CC ? (uint8_t)norm16 : 0;
519 uint8_t getCCFromNoNo(uint16_t norm16
) const {
520 const uint16_t *mapping
=getMapping(norm16
);
521 if(*mapping
&MAPPING_HAS_CCC_LCCC_WORD
) {
522 return (uint8_t)*(mapping
-1);
527 // requires that the [cpStart..cpLimit[ character passes isCompYesAndZeroCC()
528 uint8_t getTrailCCFromCompYesAndZeroCC(const UChar
*cpStart
, const UChar
*cpLimit
) const;
530 // Requires algorithmic-NoNo.
531 UChar32
mapAlgorithmic(UChar32 c
, uint16_t norm16
) const {
532 return c
+norm16
-(minMaybeYes
-MAX_DELTA
-1);
535 // Requires minYesNo<norm16<limitNoNo.
536 const uint16_t *getMapping(uint16_t norm16
) const { return extraData
+norm16
; }
537 const uint16_t *getCompositionsListForDecompYes(uint16_t norm16
) const {
538 if(norm16
==0 || MIN_NORMAL_MAYBE_YES
<=norm16
) {
540 } else if(norm16
<minMaybeYes
) {
541 return extraData
+norm16
; // for yesYes; if Jamo L: harmless empty list
543 return maybeYesCompositions
+norm16
-minMaybeYes
;
546 const uint16_t *getCompositionsListForComposite(uint16_t norm16
) const {
547 const uint16_t *list
=extraData
+norm16
; // composite has both mapping & compositions list
548 return list
+ // mapping pointer
549 1+ // +1 to skip the first unit with the mapping lenth
550 (*list
&MAPPING_LENGTH_MASK
); // + mapping length
553 * @param c code point must have compositions
554 * @return compositions list pointer
556 const uint16_t *getCompositionsList(uint16_t norm16
) const {
557 return isDecompYes(norm16
) ?
558 getCompositionsListForDecompYes(norm16
) :
559 getCompositionsListForComposite(norm16
);
562 const UChar
*copyLowPrefixFromNulTerminated(const UChar
*src
,
563 UChar32 minNeedDataCP
,
564 ReorderingBuffer
*buffer
,
565 UErrorCode
&errorCode
) const;
566 UBool
decomposeShort(const UChar
*src
, const UChar
*limit
,
567 ReorderingBuffer
&buffer
, UErrorCode
&errorCode
) const;
568 UBool
decompose(UChar32 c
, uint16_t norm16
,
569 ReorderingBuffer
&buffer
, UErrorCode
&errorCode
) const;
571 static int32_t combine(const uint16_t *list
, UChar32 trail
);
572 void addComposites(const uint16_t *list
, UnicodeSet
&set
) const;
573 void recompose(ReorderingBuffer
&buffer
, int32_t recomposeStartIndex
,
574 UBool onlyContiguous
) const;
576 UBool
hasCompBoundaryBefore(UChar32 c
, uint16_t norm16
) const;
577 const UChar
*findPreviousCompBoundary(const UChar
*start
, const UChar
*p
) const;
578 const UChar
*findNextCompBoundary(const UChar
*p
, const UChar
*limit
) const;
580 const UChar
*findPreviousFCDBoundary(const UChar
*start
, const UChar
*p
) const;
581 const UChar
*findNextFCDBoundary(const UChar
*p
, const UChar
*limit
) const;
583 int32_t getCanonValue(UChar32 c
) const;
584 const UnicodeSet
&getCanonStartSet(int32_t n
) const;
586 // UVersionInfo dataVersion;
588 // Code point thresholds for quick check codes.
589 UChar32 minDecompNoCP
;
590 UChar32 minCompNoMaybeCP
;
592 // Norm16 value thresholds for quick check combinations and types of extra data.
594 uint16_t minYesNoMappingsOnly
;
597 uint16_t minMaybeYes
;
599 const UTrie2
*normTrie
;
600 const uint16_t *maybeYesCompositions
;
601 const uint16_t *extraData
; // mappings and/or compositions for yesYes, yesNo & noNo characters
602 const uint8_t *smallFCD
; // [0x100] one bit per 32 BMP code points, set if any FCD!=0
603 uint8_t tccc180
[0x180]; // tccc values for U+0000..U+017F
605 public: // CanonIterData is public to allow access from C callback functions.
606 UInitOnce fCanonIterDataInitOnce
;
607 CanonIterData
*fCanonIterData
;
610 // bits in canonIterData
611 #define CANON_NOT_SEGMENT_STARTER 0x80000000
612 #define CANON_HAS_COMPOSITIONS 0x40000000
613 #define CANON_HAS_SET 0x200000
614 #define CANON_VALUE_MASK 0x1fffff
617 * ICU-internal shortcut for quick access to standard Unicode normalization.
619 class U_COMMON_API Normalizer2Factory
{
621 static const Normalizer2
*getFCDInstance(UErrorCode
&errorCode
);
622 static const Normalizer2
*getFCCInstance(UErrorCode
&errorCode
);
623 static const Normalizer2
*getNoopInstance(UErrorCode
&errorCode
);
625 static const Normalizer2
*getInstance(UNormalizationMode mode
, UErrorCode
&errorCode
);
627 static const Normalizer2Impl
*getNFCImpl(UErrorCode
&errorCode
);
628 static const Normalizer2Impl
*getNFKCImpl(UErrorCode
&errorCode
);
629 static const Normalizer2Impl
*getNFKC_CFImpl(UErrorCode
&errorCode
);
631 // Get the Impl instance of the Normalizer2.
632 // Must be used only when it is known that norm2 is a Normalizer2WithImpl instance.
633 static const Normalizer2Impl
*getImpl(const Normalizer2
*norm2
);
635 Normalizer2Factory(); // No instantiation.
640 U_CAPI
int32_t U_EXPORT2
641 unorm2_swap(const UDataSwapper
*ds
,
642 const void *inData
, int32_t length
, void *outData
,
643 UErrorCode
*pErrorCode
);
646 * Get the NF*_QC property for a code point, for u_getIntPropertyValue().
649 U_CFUNC UNormalizationCheckResult
650 unorm_getQuickCheck(UChar32 c
, UNormalizationMode mode
);
653 * Gets the 16-bit FCD value (lead & trail CCs) for a code point, for u_getIntPropertyValue().
657 unorm_getFCD16(UChar32 c
);
660 * Format of Normalizer2 .nrm data files.
661 * Format version 2.0.
663 * Normalizer2 .nrm data files provide data for the Unicode Normalization algorithms.
664 * ICU ships with data files for standard Unicode Normalization Forms
665 * NFC and NFD (nfc.nrm), NFKC and NFKD (nfkc.nrm) and NFKC_Casefold (nfkc_cf.nrm).
666 * Custom (application-specific) data can be built into additional .nrm files
667 * with the gennorm2 build tool.
669 * Normalizer2.getInstance() causes a .nrm file to be loaded, unless it has been
670 * cached already. Internally, Normalizer2Impl.load() reads the .nrm file.
672 * A .nrm file begins with a standard ICU data file header
673 * (DataHeader, see ucmndata.h and unicode/udata.h).
674 * The UDataInfo.dataVersion field usually contains the Unicode version
675 * for which the data was generated.
677 * After the header, the file contains the following parts.
678 * Constants are defined as enum values of the Normalizer2Impl class.
680 * Many details of the data structures are described in the design doc
681 * which is at http://site.icu-project.org/design/normalization/custom
683 * int32_t indexes[indexesLength]; -- indexesLength=indexes[IX_NORM_TRIE_OFFSET]/4;
685 * The first eight indexes are byte offsets in ascending order.
686 * Each byte offset marks the start of the next part in the data file,
687 * and the end of the previous one.
688 * When two consecutive byte offsets are the same, then the corresponding part is empty.
689 * Byte offsets are offsets from after the header,
690 * that is, from the beginning of the indexes[].
691 * Each part starts at an offset with proper alignment for its data.
692 * If necessary, the previous part may include padding bytes to achieve this alignment.
694 * minDecompNoCP=indexes[IX_MIN_DECOMP_NO_CP] is the lowest code point
695 * with a decomposition mapping, that is, with NF*D_QC=No.
696 * minCompNoMaybeCP=indexes[IX_MIN_COMP_NO_MAYBE_CP] is the lowest code point
697 * with NF*C_QC=No (has a one-way mapping) or Maybe (combines backward).
699 * The next five indexes are thresholds of 16-bit trie values for ranges of
700 * values indicating multiple normalization properties.
701 * minYesNo=indexes[IX_MIN_YES_NO];
702 * minNoNo=indexes[IX_MIN_NO_NO];
703 * limitNoNo=indexes[IX_LIMIT_NO_NO];
704 * minMaybeYes=indexes[IX_MIN_MAYBE_YES];
705 * minYesNoMappingsOnly=indexes[IX_MIN_YES_NO_MAPPINGS_ONLY];
706 * See the normTrie description below and the design doc for details.
708 * UTrie2 normTrie; -- see utrie2_impl.h and utrie2.h
710 * The trie holds the main normalization data. Each code point is mapped to a 16-bit value.
711 * Rather than using independent bits in the value (which would require more than 16 bits),
712 * information is extracted primarily via range checks.
713 * For example, a 16-bit value norm16 in the range minYesNo<=norm16<minNoNo
714 * means that the character has NF*C_QC=Yes and NF*D_QC=No properties,
715 * which means it has a two-way (round-trip) decomposition mapping.
716 * Values in the range 2<=norm16<limitNoNo are also directly indexes into the extraData
717 * pointing to mappings, compositions lists, or both.
718 * Value norm16==0 means that the character is normalization-inert, that is,
719 * it does not have a mapping, does not participate in composition, has a zero
720 * canonical combining class, and forms a boundary where text before it and after it
721 * can be normalized independently.
722 * For details about how multiple properties are encoded in 16-bit values
723 * see the design doc.
724 * Note that the encoding cannot express all combinations of the properties involved;
725 * it only supports those combinations that are allowed by
726 * the Unicode Normalization algorithms. Details are in the design doc as well.
727 * The gennorm2 tool only builds .nrm files for data that conforms to the limitations.
729 * The trie has a value for each lead surrogate code unit representing the "worst case"
730 * properties of the 1024 supplementary characters whose UTF-16 form starts with
731 * the lead surrogate. If all of the 1024 supplementary characters are normalization-inert,
732 * then their lead surrogate code unit has the trie value 0.
733 * When the lead surrogate unit's value exceeds the quick check minimum during processing,
734 * the properties for the full supplementary code point need to be looked up.
736 * uint16_t maybeYesCompositions[MIN_NORMAL_MAYBE_YES-minMaybeYes];
737 * uint16_t extraData[];
739 * There is only one byte offset for the end of these two arrays.
740 * The split between them is given by the constant and variable mentioned above.
742 * The maybeYesCompositions array contains compositions lists for characters that
743 * combine both forward (as starters in composition pairs)
744 * and backward (as trailing characters in composition pairs).
745 * Such characters do not occur in Unicode 5.2 but are allowed by
746 * the Unicode Normalization algorithms.
747 * If there are no such characters, then minMaybeYes==MIN_NORMAL_MAYBE_YES
748 * and the maybeYesCompositions array is empty.
749 * If there are such characters, then minMaybeYes is subtracted from their norm16 values
750 * to get the index into this array.
752 * The extraData array contains compositions lists for "YesYes" characters,
753 * followed by mappings and optional compositions lists for "YesNo" characters,
754 * followed by only mappings for "NoNo" characters.
755 * (Referring to pairs of NFC/NFD quick check values.)
756 * The norm16 values of those characters are directly indexes into the extraData array.
758 * The data structures for compositions lists and mappings are described in the design doc.
760 * uint8_t smallFCD[0x100]; -- new in format version 2
762 * This is a bit set to help speed up FCD value lookups in the absence of a full
763 * UTrie2 or other large data structure with the full FCD value mapping.
765 * Each smallFCD bit is set if any of the corresponding 32 BMP code points
766 * has a non-zero FCD value (lccc!=0 or tccc!=0).
767 * Bit 0 of smallFCD[0] is for U+0000..U+001F. Bit 7 of smallFCD[0xff] is for U+FFE0..U+FFFF.
768 * A bit for 32 lead surrogates is set if any of the 32k corresponding
769 * _supplementary_ code points has a non-zero FCD value.
771 * This bit set is most useful for the large blocks of CJK characters with FCD=0.
773 * Changes from format version 1 to format version 2 ---------------------------
775 * - Addition of data for raw (not recursively decomposed) mappings.
776 * + The MAPPING_NO_COMP_BOUNDARY_AFTER bit in the extraData is now also set when
777 * the mapping is to an empty string or when the character combines-forward.
778 * This subsumes the one actual use of the MAPPING_PLUS_COMPOSITION_LIST bit which
779 * is then repurposed for the MAPPING_HAS_RAW_MAPPING bit.
780 * + For details see the design doc.
781 * - Addition of indexes[IX_MIN_YES_NO_MAPPINGS_ONLY] and separation of the yesNo extraData into
782 * distinct ranges (combines-forward vs. not)
783 * so that a range check can be used to find out if there is a compositions list.
784 * This is fully equivalent with formatVersion 1's MAPPING_PLUS_COMPOSITION_LIST flag.
785 * It is needed for the new (in ICU 49) composePair(), not for other normalization.
786 * - Addition of the smallFCD[] bit set.
789 #endif /* !UCONFIG_NO_NORMALIZATION */
790 #endif /* __NORMALIZER2IMPL_H__ */