2 *******************************************************************************
4 * Copyright (C) 2009-2010, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: normalizer2impl.h
10 * tab size: 8 (not used)
13 * created on: 2009nov22
14 * created by: Markus W. Scherer
17 #ifndef __NORMALIZER2IMPL_H__
18 #define __NORMALIZER2IMPL_H__
20 #include "unicode/utypes.h"
22 #if !UCONFIG_NO_NORMALIZATION
24 #include "unicode/normalizer2.h"
25 #include "unicode/udata.h"
26 #include "unicode/unistr.h"
27 #include "unicode/unorm.h"
38 /* Korean Hangul and Jamo constants */
40 JAMO_L_BASE
=0x1100, /* "lead" jamo */
41 JAMO_V_BASE
=0x1161, /* "vowel" jamo */
42 JAMO_T_BASE
=0x11a7, /* "trail" jamo */
50 JAMO_VT_COUNT
=JAMO_V_COUNT
*JAMO_T_COUNT
,
52 HANGUL_COUNT
=JAMO_L_COUNT
*JAMO_V_COUNT
*JAMO_T_COUNT
,
53 HANGUL_LIMIT
=HANGUL_BASE
+HANGUL_COUNT
56 static inline UBool
isHangul(UChar32 c
) {
57 return HANGUL_BASE
<=c
&& c
<HANGUL_LIMIT
;
60 isHangulWithoutJamoT(UChar c
) {
62 return c
<HANGUL_COUNT
&& c%JAMO_T_COUNT
==0;
64 static inline UBool
isJamoL(UChar32 c
) {
65 return (uint32_t)(c
-JAMO_L_BASE
)<JAMO_L_COUNT
;
67 static inline UBool
isJamoV(UChar32 c
) {
68 return (uint32_t)(c
-JAMO_V_BASE
)<JAMO_V_COUNT
;
72 * Decomposes c, which must be a Hangul syllable, into buffer
73 * and returns the length of the decomposition (2 or 3).
75 static inline int32_t decompose(UChar32 c
, UChar buffer
[3]) {
77 UChar32 c2
=c%JAMO_T_COUNT
;
79 buffer
[0]=(UChar
)(JAMO_L_BASE
+c
/JAMO_V_COUNT
);
80 buffer
[1]=(UChar
)(JAMO_V_BASE
+c%JAMO_V_COUNT
);
84 buffer
[2]=(UChar
)(JAMO_T_BASE
+c2
);
89 Hangul(); // no instantiation
92 class Normalizer2Impl
;
94 class ReorderingBuffer
: public UMemory
{
96 ReorderingBuffer(const Normalizer2Impl
&ni
, UnicodeString
&dest
) :
98 start(NULL
), reorderStart(NULL
), limit(NULL
),
99 remainingCapacity(0), lastCC(0) {}
100 ~ReorderingBuffer() {
102 str
.releaseBuffer((int32_t)(limit
-start
));
105 UBool
init(int32_t destCapacity
, UErrorCode
&errorCode
);
107 UBool
isEmpty() const { return start
==limit
; }
108 int32_t length() const { return (int32_t)(limit
-start
); }
109 UChar
*getStart() { return start
; }
110 UChar
*getLimit() { return limit
; }
111 uint8_t getLastCC() const { return lastCC
; }
113 UBool
equals(const UChar
*start
, const UChar
*limit
) const;
115 // For Hangul composition, replacing the Leading consonant Jamo with the syllable.
116 void setLastChar(UChar c
) {
120 UBool
append(UChar32 c
, uint8_t cc
, UErrorCode
&errorCode
) {
122 appendBMP((UChar
)c
, cc
, errorCode
) :
123 appendSupplementary(c
, cc
, errorCode
);
125 // s must be in NFD, otherwise change the implementation.
126 UBool
append(const UChar
*s
, int32_t length
,
127 uint8_t leadCC
, uint8_t trailCC
,
128 UErrorCode
&errorCode
);
129 UBool
appendBMP(UChar c
, uint8_t cc
, UErrorCode
&errorCode
) {
130 if(remainingCapacity
==0 && !resize(1, errorCode
)) {
133 if(lastCC
<=cc
|| cc
==0) {
145 UBool
appendZeroCC(UChar32 c
, UErrorCode
&errorCode
);
146 UBool
appendZeroCC(const UChar
*s
, const UChar
*sLimit
, UErrorCode
&errorCode
);
148 void removeSuffix(int32_t suffixLength
);
149 void setReorderingLimit(UChar
*newLimit
) {
150 remainingCapacity
+=(int32_t)(limit
-newLimit
);
151 reorderStart
=limit
=newLimit
;
156 * TODO: Revisit whether it makes sense to track reorderStart.
157 * It is set to after the last known character with cc<=1,
158 * which stops previousCC() before it reads that character and looks up its cc.
159 * previousCC() is normally only called from insert().
160 * In other words, reorderStart speeds up the insertion of a combining mark
161 * into a multi-combining mark sequence where it does not belong at the end.
162 * This might not be worth the trouble.
163 * On the other hand, it's not a huge amount of trouble.
165 * We probably need it for UNORM_SIMPLE_APPEND.
168 UBool
appendSupplementary(UChar32 c
, uint8_t cc
, UErrorCode
&errorCode
);
169 void insert(UChar32 c
, uint8_t cc
);
170 static void writeCodePoint(UChar
*p
, UChar32 c
) {
178 UBool
resize(int32_t appendLength
, UErrorCode
&errorCode
);
180 const Normalizer2Impl
&impl
;
182 UChar
*start
, *reorderStart
, *limit
;
183 int32_t remainingCapacity
;
186 // private backward iterator
187 void setIterator() { codePointStart
=limit
; }
188 void skipPrevious(); // Requires start<codePointStart.
189 uint8_t previousCC(); // Returns 0 if there is no previous character.
191 UChar
*codePointStart
, *codePointLimit
;
194 class U_COMMON_API Normalizer2Impl
: public UMemory
{
196 Normalizer2Impl() : memory(NULL
), normTrie(NULL
) {
197 fcdTrieSingleton
.fInstance
=NULL
;
198 canonIterDataSingleton
.fInstance
=NULL
;
202 void load(const char *packageName
, const char *name
, UErrorCode
&errorCode
);
204 void addPropertyStarts(const USetAdder
*sa
, UErrorCode
&errorCode
) const;
205 void addCanonIterPropertyStarts(const USetAdder
*sa
, UErrorCode
&errorCode
) const;
207 // low-level properties ------------------------------------------------ ***
209 const UTrie2
*getNormTrie() const { return normTrie
; }
210 const UTrie2
*getFCDTrie(UErrorCode
&errorCode
) const ;
212 UBool
ensureCanonIterData(UErrorCode
&errorCode
) const;
214 uint16_t getNorm16(UChar32 c
) const { return UTRIE2_GET16(normTrie
, c
); }
216 UNormalizationCheckResult
getCompQuickCheck(uint16_t norm16
) const {
217 if(norm16
<minNoNo
|| MIN_YES_YES_WITH_CC
<=norm16
) {
219 } else if(minMaybeYes
<=norm16
) {
225 UBool
isCompNo(uint16_t norm16
) const { return minNoNo
<=norm16
&& norm16
<minMaybeYes
; }
226 UBool
isDecompYes(uint16_t norm16
) const { return norm16
<minYesNo
|| minMaybeYes
<=norm16
; }
228 uint8_t getCC(uint16_t norm16
) const {
229 if(norm16
>=MIN_NORMAL_MAYBE_YES
) {
230 return (uint8_t)norm16
;
232 if(norm16
<minNoNo
|| limitNoNo
<=norm16
) {
235 return getCCFromNoNo(norm16
);
237 static uint8_t getCCFromYesOrMaybe(uint16_t norm16
) {
238 return norm16
>=MIN_NORMAL_MAYBE_YES
? (uint8_t)norm16
: 0;
241 uint16_t getFCD16(UChar32 c
) const { return UTRIE2_GET16(fcdTrie(), c
); }
242 uint16_t getFCD16FromSingleLead(UChar c
) const {
243 return UTRIE2_GET16_FROM_U16_SINGLE_LEAD(fcdTrie(), c
);
245 uint16_t getFCD16FromSupplementary(UChar32 c
) const {
246 return UTRIE2_GET16_FROM_SUPP(fcdTrie(), c
);
248 uint16_t getFCD16FromSurrogatePair(UChar c
, UChar c2
) const {
249 return getFCD16FromSupplementary(U16_GET_SUPPLEMENTARY(c
, c2
));
252 void setFCD16FromNorm16(UChar32 start
, UChar32 end
, uint16_t norm16
,
253 UTrie2
*newFCDTrie
, UErrorCode
&errorCode
) const;
255 void makeCanonIterDataFromNorm16(UChar32 start
, UChar32 end
, uint16_t norm16
,
256 CanonIterData
&newData
, UErrorCode
&errorCode
) const;
259 * Get the decomposition for one code point.
260 * @param c code point
261 * @param buffer out-only buffer for algorithmic decompositions
262 * @param length out-only, takes the length of the decomposition, if any
263 * @return pointer to the decomposition, or NULL if none
265 const UChar
*getDecomposition(UChar32 c
, UChar buffer
[4], int32_t &length
) const;
267 UBool
isCanonSegmentStarter(UChar32 c
) const;
268 UBool
getCanonStartSet(UChar32 c
, UnicodeSet
&set
) const;
271 MIN_CCC_LCCC_CP
=0x300
275 MIN_YES_YES_WITH_CC
=0xff01,
277 MIN_NORMAL_MAYBE_YES
=0xfe00,
283 // Byte offsets from the start of the data, after the generic header.
285 IX_EXTRA_DATA_OFFSET
,
293 // Code point thresholds for quick check codes.
295 IX_MIN_COMP_NO_MAYBE_CP
,
297 // Norm16 value thresholds for quick check combinations and types of extra data.
309 MAPPING_HAS_CCC_LCCC_WORD
=0x80,
310 MAPPING_PLUS_COMPOSITION_LIST
=0x40,
311 MAPPING_NO_COMP_BOUNDARY_AFTER
=0x20,
312 MAPPING_LENGTH_MASK
=0x1f
316 COMP_1_LAST_TUPLE
=0x8000,
318 COMP_1_TRAIL_LIMIT
=0x3400,
319 COMP_1_TRAIL_MASK
=0x7ffe,
320 COMP_1_TRAIL_SHIFT
=9, // 10-1 for the "triple" bit
321 COMP_2_TRAIL_SHIFT
=6,
322 COMP_2_TRAIL_MASK
=0xffc0
325 // higher-level functionality ------------------------------------------ ***
327 const UChar
*decompose(const UChar
*src
, const UChar
*limit
,
328 ReorderingBuffer
*buffer
, UErrorCode
&errorCode
) const;
329 void decomposeAndAppend(const UChar
*src
, const UChar
*limit
,
331 ReorderingBuffer
&buffer
,
332 UErrorCode
&errorCode
) const;
333 UBool
compose(const UChar
*src
, const UChar
*limit
,
334 UBool onlyContiguous
,
336 ReorderingBuffer
&buffer
,
337 UErrorCode
&errorCode
) const;
338 const UChar
*composeQuickCheck(const UChar
*src
, const UChar
*limit
,
339 UBool onlyContiguous
,
340 UNormalizationCheckResult
*pQCResult
) const;
341 void composeAndAppend(const UChar
*src
, const UChar
*limit
,
343 UBool onlyContiguous
,
344 ReorderingBuffer
&buffer
,
345 UErrorCode
&errorCode
) const;
346 const UChar
*makeFCD(const UChar
*src
, const UChar
*limit
,
347 ReorderingBuffer
*buffer
, UErrorCode
&errorCode
) const;
348 void makeFCDAndAppend(const UChar
*src
, const UChar
*limit
,
350 ReorderingBuffer
&buffer
,
351 UErrorCode
&errorCode
) const;
353 UBool
hasDecompBoundary(UChar32 c
, UBool before
) const;
354 UBool
isDecompInert(UChar32 c
) const { return isDecompYesAndZeroCC(getNorm16(c
)); }
356 UBool
hasCompBoundaryBefore(UChar32 c
) const {
357 return c
<minCompNoMaybeCP
|| hasCompBoundaryBefore(c
, getNorm16(c
));
359 UBool
hasCompBoundaryAfter(UChar32 c
, UBool onlyContiguous
, UBool testInert
) const;
361 UBool
hasFCDBoundaryBefore(UChar32 c
) const { return c
<MIN_CCC_LCCC_CP
|| getFCD16(c
)<=0xff; }
362 UBool
hasFCDBoundaryAfter(UChar32 c
) const {
363 uint16_t fcd16
=getFCD16(c
);
364 return fcd16
<=1 || (fcd16
&0xff)==0;
366 UBool
isFCDInert(UChar32 c
) const { return getFCD16(c
)<=1; }
368 static UBool U_CALLCONV
369 isAcceptable(void *context
, const char *type
, const char *name
, const UDataInfo
*pInfo
);
371 UBool
isMaybe(uint16_t norm16
) const { return minMaybeYes
<=norm16
&& norm16
<=JAMO_VT
; }
372 UBool
isMaybeOrNonZeroCC(uint16_t norm16
) const { return norm16
>=minMaybeYes
; }
373 static UBool
isInert(uint16_t norm16
) { return norm16
==0; }
374 // static UBool isJamoL(uint16_t norm16) const { return norm16==1; }
375 static UBool
isJamoVT(uint16_t norm16
) { return norm16
==JAMO_VT
; }
376 UBool
isHangul(uint16_t norm16
) const { return norm16
==minYesNo
; }
377 UBool
isCompYesAndZeroCC(uint16_t norm16
) const { return norm16
<minNoNo
; }
378 // UBool isCompYes(uint16_t norm16) const {
379 // return norm16>=MIN_YES_YES_WITH_CC || norm16<minNoNo;
381 // UBool isCompYesOrMaybe(uint16_t norm16) const {
382 // return norm16<minNoNo || minMaybeYes<=norm16;
384 // UBool hasZeroCCFromDecompYes(uint16_t norm16) const {
385 // return norm16<=MIN_NORMAL_MAYBE_YES || norm16==JAMO_VT;
387 UBool
isDecompYesAndZeroCC(uint16_t norm16
) const {
388 return norm16
<minYesNo
||
390 (minMaybeYes
<=norm16
&& norm16
<=MIN_NORMAL_MAYBE_YES
);
393 * A little faster and simpler than isDecompYesAndZeroCC() but does not include
394 * the MaybeYes which combine-forward and have ccc=0.
395 * (Standard Unicode 5.2 normalization does not have such characters.)
397 UBool
isMostDecompYesAndZeroCC(uint16_t norm16
) const {
398 return norm16
<minYesNo
|| norm16
==MIN_NORMAL_MAYBE_YES
|| norm16
==JAMO_VT
;
400 UBool
isDecompNoAlgorithmic(uint16_t norm16
) const { return norm16
>=limitNoNo
; }
402 // For use with isCompYes().
403 // Perhaps the compiler can combine the two tests for MIN_YES_YES_WITH_CC.
404 // static uint8_t getCCFromYes(uint16_t norm16) {
405 // return norm16>=MIN_YES_YES_WITH_CC ? (uint8_t)norm16 : 0;
407 uint8_t getCCFromNoNo(uint16_t norm16
) const {
408 const uint16_t *mapping
=getMapping(norm16
);
409 if(*mapping
&MAPPING_HAS_CCC_LCCC_WORD
) {
410 return (uint8_t)mapping
[1];
415 // requires that the [cpStart..cpLimit[ character passes isCompYesAndZeroCC()
416 uint8_t getTrailCCFromCompYesAndZeroCC(const UChar
*cpStart
, const UChar
*cpLimit
) const;
418 // Requires algorithmic-NoNo.
419 UChar32
mapAlgorithmic(UChar32 c
, uint16_t norm16
) const {
420 return c
+norm16
-(minMaybeYes
-MAX_DELTA
-1);
423 // Requires minYesNo<norm16<limitNoNo.
424 const uint16_t *getMapping(uint16_t norm16
) const { return extraData
+norm16
; }
425 const uint16_t *getCompositionsListForDecompYes(uint16_t norm16
) const {
426 if(norm16
==0 || MIN_NORMAL_MAYBE_YES
<=norm16
) {
428 } else if(norm16
<minMaybeYes
) {
429 return extraData
+norm16
; // for yesYes; if Jamo L: harmless empty list
431 return maybeYesCompositions
+norm16
-minMaybeYes
;
434 const uint16_t *getCompositionsListForComposite(uint16_t norm16
) const {
435 const uint16_t *list
=extraData
+norm16
; // composite has both mapping & compositions list
436 return list
+ // mapping pointer
437 1+ // +1 to skip the first unit with the mapping lenth
438 (*list
&MAPPING_LENGTH_MASK
)+ // + mapping length
439 ((*list
>>7)&1); // +1 if MAPPING_HAS_CCC_LCCC_WORD
442 * @param c code point must have compositions
443 * @return compositions list pointer
445 const uint16_t *getCompositionsList(uint16_t norm16
) const {
446 return isDecompYes(norm16
) ?
447 getCompositionsListForDecompYes(norm16
) :
448 getCompositionsListForComposite(norm16
);
451 const UChar
*copyLowPrefixFromNulTerminated(const UChar
*src
,
452 UChar32 minNeedDataCP
,
453 ReorderingBuffer
*buffer
,
454 UErrorCode
&errorCode
) const;
455 UBool
decomposeShort(const UChar
*src
, const UChar
*limit
,
456 ReorderingBuffer
&buffer
, UErrorCode
&errorCode
) const;
457 UBool
decompose(UChar32 c
, uint16_t norm16
,
458 ReorderingBuffer
&buffer
, UErrorCode
&errorCode
) const;
460 static int32_t combine(const uint16_t *list
, UChar32 trail
);
461 void addComposites(const uint16_t *list
, UnicodeSet
&set
) const;
462 void recompose(ReorderingBuffer
&buffer
, int32_t recomposeStartIndex
,
463 UBool onlyContiguous
) const;
465 UBool
hasCompBoundaryBefore(UChar32 c
, uint16_t norm16
) const;
466 const UChar
*findPreviousCompBoundary(const UChar
*start
, const UChar
*p
) const;
467 const UChar
*findNextCompBoundary(const UChar
*p
, const UChar
*limit
) const;
469 const UTrie2
*fcdTrie() const { return (const UTrie2
*)fcdTrieSingleton
.fInstance
; }
471 const UChar
*findPreviousFCDBoundary(const UChar
*start
, const UChar
*p
) const;
472 const UChar
*findNextFCDBoundary(const UChar
*p
, const UChar
*limit
) const;
474 int32_t getCanonValue(UChar32 c
) const;
475 const UnicodeSet
&getCanonStartSet(int32_t n
) const;
478 UVersionInfo dataVersion
;
480 // Code point thresholds for quick check codes.
481 UChar32 minDecompNoCP
;
482 UChar32 minCompNoMaybeCP
;
484 // Norm16 value thresholds for quick check combinations and types of extra data.
488 uint16_t minMaybeYes
;
491 const uint16_t *maybeYesCompositions
;
492 const uint16_t *extraData
; // mappings and/or compositions for yesYes, yesNo & noNo characters
494 SimpleSingleton fcdTrieSingleton
;
495 SimpleSingleton canonIterDataSingleton
;
498 // bits in canonIterData
499 #define CANON_NOT_SEGMENT_STARTER 0x80000000
500 #define CANON_HAS_COMPOSITIONS 0x40000000
501 #define CANON_HAS_SET 0x200000
502 #define CANON_VALUE_MASK 0x1fffff
505 * ICU-internal shortcut for quick access to standard Unicode normalization.
507 class U_COMMON_API Normalizer2Factory
{
509 static const Normalizer2
*getNFCInstance(UErrorCode
&errorCode
);
510 static const Normalizer2
*getNFDInstance(UErrorCode
&errorCode
);
511 static const Normalizer2
*getFCDInstance(UErrorCode
&errorCode
);
512 static const Normalizer2
*getFCCInstance(UErrorCode
&errorCode
);
513 static const Normalizer2
*getNFKCInstance(UErrorCode
&errorCode
);
514 static const Normalizer2
*getNFKDInstance(UErrorCode
&errorCode
);
515 static const Normalizer2
*getNFKC_CFInstance(UErrorCode
&errorCode
);
516 static const Normalizer2
*getNoopInstance(UErrorCode
&errorCode
);
518 static const Normalizer2
*getInstance(UNormalizationMode mode
, UErrorCode
&errorCode
);
520 static const Normalizer2Impl
*getNFCImpl(UErrorCode
&errorCode
);
521 static const Normalizer2Impl
*getNFKCImpl(UErrorCode
&errorCode
);
522 static const Normalizer2Impl
*getNFKC_CFImpl(UErrorCode
&errorCode
);
524 // Get the Impl instance of the Normalizer2.
525 // Must be used only when it is known that norm2 is a Normalizer2WithImpl instance.
526 static const Normalizer2Impl
*getImpl(const Normalizer2
*norm2
);
528 static const UTrie2
*getFCDTrie(UErrorCode
&errorCode
);
530 Normalizer2Factory(); // No instantiation.
535 U_CAPI
int32_t U_EXPORT2
536 unorm2_swap(const UDataSwapper
*ds
,
537 const void *inData
, int32_t length
, void *outData
,
538 UErrorCode
*pErrorCode
);
541 * Get the NF*_QC property for a code point, for u_getIntPropertyValue().
544 U_CFUNC UNormalizationCheckResult U_EXPORT2
545 unorm_getQuickCheck(UChar32 c
, UNormalizationMode mode
);
548 * Internal API, used by collation code.
549 * Get access to the internal FCD trie table to be able to perform
550 * incremental, per-code unit, FCD checks in collation.
551 * One pointer is sufficient because the trie index values are offset
552 * by the index size, so that the same pointer is used to access the trie data.
553 * Code points at fcdHighStart and above have a zero FCD value.
556 U_CAPI
const uint16_t * U_EXPORT2
557 unorm_getFCDTrieIndex(UChar32
&fcdHighStart
, UErrorCode
*pErrorCode
);
560 * Internal API, used by collation code.
561 * Get the FCD value for a code unit, with
562 * bits 15..8 lead combining class
563 * bits 7..0 trail combining class
565 * If c is a lead surrogate and the value is not 0,
566 * then some of c's associated supplementary code points have a non-zero FCD value.
570 static inline uint16_t
571 unorm_getFCD16(const uint16_t *fcdTrieIndex
, UChar c
) {
572 return fcdTrieIndex
[_UTRIE2_INDEX_FROM_U16_SINGLE_LEAD(fcdTrieIndex
, c
)];
576 * Internal API, used by collation code.
577 * Get the FCD value of the next code point (post-increment), with
578 * bits 15..8 lead combining class
579 * bits 7..0 trail combining class
583 static inline uint16_t
584 unorm_nextFCD16(const uint16_t *fcdTrieIndex
, UChar32 fcdHighStart
,
585 const UChar
*&s
, const UChar
*limit
) {
587 uint16_t fcd
=fcdTrieIndex
[_UTRIE2_INDEX_FROM_U16_SINGLE_LEAD(fcdTrieIndex
, c
)];
588 if(fcd
!=0 && U16_IS_LEAD(c
)) {
590 if(s
!=limit
&& U16_IS_TRAIL(c2
=*s
)) {
592 c
=U16_GET_SUPPLEMENTARY(c
, c2
);
594 fcd
=fcdTrieIndex
[_UTRIE2_INDEX_FROM_SUPP(fcdTrieIndex
, c
)];
598 } else /* unpaired lead surrogate */ {
606 * Internal API, used by collation code.
607 * Get the FCD value of the previous code point (pre-decrement), with
608 * bits 15..8 lead combining class
609 * bits 7..0 trail combining class
613 static inline uint16_t
614 unorm_prevFCD16(const uint16_t *fcdTrieIndex
, UChar32 fcdHighStart
,
615 const UChar
*start
, const UChar
*&s
) {
618 if(!U16_IS_SURROGATE(c
)) {
619 fcd
=fcdTrieIndex
[_UTRIE2_INDEX_FROM_U16_SINGLE_LEAD(fcdTrieIndex
, c
)];
622 if(U16_IS_SURROGATE_TRAIL(c
) && s
!=start
&& U16_IS_LEAD(c2
=*(s
-1))) {
624 c
=U16_GET_SUPPLEMENTARY(c2
, c
);
626 fcd
=fcdTrieIndex
[_UTRIE2_INDEX_FROM_SUPP(fcdTrieIndex
, c
)];
630 } else /* unpaired surrogate */ {
638 * Format of Normalizer2 .nrm data files.
639 * Format version 1.0.
641 * Normalizer2 .nrm data files provide data for the Unicode Normalization algorithms.
642 * ICU ships with data files for standard Unicode Normalization Forms
643 * NFC and NFD (nfc.nrm), NFKC and NFKD (nfkc.nrm) and NFKC_Casefold (nfkc_cf.nrm).
644 * Custom (application-specific) data can be built into additional .nrm files
645 * with the gennorm2 build tool.
647 * Normalizer2.getInstance() causes a .nrm file to be loaded, unless it has been
648 * cached already. Internally, Normalizer2Impl.load() reads the .nrm file.
650 * A .nrm file begins with a standard ICU data file header
651 * (DataHeader, see ucmndata.h and unicode/udata.h).
652 * The UDataInfo.dataVersion field usually contains the Unicode version
653 * for which the data was generated.
655 * After the header, the file contains the following parts.
656 * Constants are defined as enum values of the Normalizer2Impl class.
658 * Many details of the data structures are described in the design doc
659 * which is at http://site.icu-project.org/design/normalization/custom
661 * int32_t indexes[indexesLength]; -- indexesLength=indexes[IX_NORM_TRIE_OFFSET]/4;
663 * The first eight indexes are byte offsets in ascending order.
664 * Each byte offset marks the start of the next part in the data file,
665 * and the end of the previous one.
666 * When two consecutive byte offsets are the same, then the corresponding part is empty.
667 * Byte offsets are offsets from after the header,
668 * that is, from the beginning of the indexes[].
669 * Each part starts at an offset with proper alignment for its data.
670 * If necessary, the previous part may include padding bytes to achieve this alignment.
672 * minDecompNoCP=indexes[IX_MIN_DECOMP_NO_CP] is the lowest code point
673 * with a decomposition mapping, that is, with NF*D_QC=No.
674 * minCompNoMaybeCP=indexes[IX_MIN_COMP_NO_MAYBE_CP] is the lowest code point
675 * with NF*C_QC=No (has a one-way mapping) or Maybe (combines backward).
677 * The next four indexes are thresholds of 16-bit trie values for ranges of
678 * values indicating multiple normalization properties.
679 * minYesNo=indexes[IX_MIN_YES_NO];
680 * minNoNo=indexes[IX_MIN_NO_NO];
681 * limitNoNo=indexes[IX_LIMIT_NO_NO];
682 * minMaybeYes=indexes[IX_MIN_MAYBE_YES];
683 * See the normTrie description below and the design doc for details.
685 * UTrie2 normTrie; -- see utrie2_impl.h and utrie2.h
687 * The trie holds the main normalization data. Each code point is mapped to a 16-bit value.
688 * Rather than using independent bits in the value (which would require more than 16 bits),
689 * information is extracted primarily via range checks.
690 * For example, a 16-bit value norm16 in the range minYesNo<=norm16<minNoNo
691 * means that the character has NF*C_QC=Yes and NF*D_QC=No properties,
692 * which means it has a two-way (round-trip) decomposition mapping.
693 * Values in the range 2<=norm16<limitNoNo are also directly indexes into the extraData
694 * pointing to mappings, composition lists, or both.
695 * Value norm16==0 means that the character is normalization-inert, that is,
696 * it does not have a mapping, does not participate in composition, has a zero
697 * canonical combining class, and forms a boundary where text before it and after it
698 * can be normalized independently.
699 * For details about how multiple properties are encoded in 16-bit values
700 * see the design doc.
701 * Note that the encoding cannot express all combinations of the properties involved;
702 * it only supports those combinations that are allowed by
703 * the Unicode Normalization algorithms. Details are in the design doc as well.
704 * The gennorm2 tool only builds .nrm files for data that conforms to the limitations.
706 * The trie has a value for each lead surrogate code unit representing the "worst case"
707 * properties of the 1024 supplementary characters whose UTF-16 form starts with
708 * the lead surrogate. If all of the 1024 supplementary characters are normalization-inert,
709 * then their lead surrogate code unit has the trie value 0.
710 * When the lead surrogate unit's value exceeds the quick check minimum during processing,
711 * the properties for the full supplementary code point need to be looked up.
713 * uint16_t maybeYesCompositions[MIN_NORMAL_MAYBE_YES-minMaybeYes];
714 * uint16_t extraData[];
716 * There is only one byte offset for the end of these two arrays.
717 * The split between them is given by the constant and variable mentioned above.
719 * The maybeYesCompositions array contains composition lists for characters that
720 * combine both forward (as starters in composition pairs)
721 * and backward (as trailing characters in composition pairs).
722 * Such characters do not occur in Unicode 5.2 but are allowed by
723 * the Unicode Normalization algorithms.
724 * If there are no such characters, then minMaybeYes==MIN_NORMAL_MAYBE_YES
725 * and the maybeYesCompositions array is empty.
726 * If there are such characters, then minMaybeYes is subtracted from their norm16 values
727 * to get the index into this array.
729 * The extraData array contains composition lists for "YesYes" characters,
730 * followed by mappings and optional composition lists for "YesNo" characters,
731 * followed by only mappings for "NoNo" characters.
732 * (Referring to pairs of NFC/NFD quick check values.)
733 * The norm16 values of those characters are directly indexes into the extraData array.
735 * The data structures for composition lists and mappings are described in the design doc.
738 #endif /* !UCONFIG_NO_NORMALIZATION */
739 #endif /* __NORMALIZER2IMPL_H__ */