sl@0: /* sl@0: ******************************************************************************* sl@0: * sl@0: * Copyright (C) 2001-2004, International Business Machines sl@0: * Corporation and others. All Rights Reserved. sl@0: * sl@0: ******************************************************************************* sl@0: * file name: unormimp.h sl@0: * encoding: US-ASCII sl@0: * tab size: 8 (not used) sl@0: * indentation:4 sl@0: * sl@0: * created on: 2001may25 sl@0: * created by: Markus W. Scherer sl@0: */ sl@0: sl@0: #ifndef __UNORMIMP_H__ sl@0: #define __UNORMIMP_H__ sl@0: sl@0: #include "unicode/utypes.h" sl@0: sl@0: #if !UCONFIG_NO_NORMALIZATION sl@0: sl@0: #ifdef XP_CPLUSPLUS sl@0: #include "unicode/uniset.h" sl@0: #endif sl@0: sl@0: #include "unicode/uiter.h" sl@0: #include "unicode/unorm.h" sl@0: #include "unicode/uset.h" sl@0: #include "utrie.h" sl@0: #include "ustr_imp.h" sl@0: #include "udataswp.h" sl@0: sl@0: /* sl@0: * This new implementation of the normalization code loads its data from sl@0: * unorm.icu, which is generated with the gennorm tool. sl@0: * The format of that file is described at the end of this file. sl@0: */ sl@0: sl@0: /* norm32 value constants */ sl@0: enum { sl@0: /* quick check flags 0..3 set mean "no" for their forms */ sl@0: _NORM_QC_NFC=0x11, /* no|maybe */ sl@0: _NORM_QC_NFKC=0x22, /* no|maybe */ sl@0: _NORM_QC_NFD=4, /* no */ sl@0: _NORM_QC_NFKD=8, /* no */ sl@0: sl@0: _NORM_QC_ANY_NO=0xf, sl@0: sl@0: /* quick check flags 4..5 mean "maybe" for their forms; test flags>=_NORM_QC_MAYBE */ sl@0: _NORM_QC_MAYBE=0x10, sl@0: _NORM_QC_ANY_MAYBE=0x30, sl@0: sl@0: _NORM_QC_MASK=0x3f, sl@0: sl@0: _NORM_COMBINES_FWD=0x40, sl@0: _NORM_COMBINES_BACK=0x80, sl@0: _NORM_COMBINES_ANY=0xc0, sl@0: sl@0: _NORM_CC_SHIFT=8, /* UnicodeData.txt combining class in bits 15..8 */ sl@0: _NORM_CC_MASK=0xff00, sl@0: sl@0: _NORM_EXTRA_SHIFT=16, /* 16 bits for the index to UChars and other extra data */ sl@0: _NORM_EXTRA_INDEX_TOP=0xfc00, /* start of surrogate specials after shift */ sl@0: sl@0: _NORM_EXTRA_SURROGATE_MASK=0x3ff, sl@0: _NORM_EXTRA_SURROGATE_TOP=0x3f0, /* hangul etc. */ sl@0: sl@0: _NORM_EXTRA_HANGUL=_NORM_EXTRA_SURROGATE_TOP, sl@0: _NORM_EXTRA_JAMO_L, sl@0: _NORM_EXTRA_JAMO_V, sl@0: _NORM_EXTRA_JAMO_T sl@0: }; sl@0: sl@0: /* norm32 value constants using >16 bits */ sl@0: #define _NORM_MIN_SPECIAL 0xfc000000 sl@0: #define _NORM_SURROGATES_TOP 0xfff00000 sl@0: #define _NORM_MIN_HANGUL 0xfff00000 sl@0: #define _NORM_MIN_JAMO_V 0xfff20000 sl@0: #define _NORM_JAMO_V_TOP 0xfff30000 sl@0: sl@0: /* value constants for auxTrie */ sl@0: enum { sl@0: _NORM_AUX_COMP_EX_SHIFT=10, sl@0: _NORM_AUX_UNSAFE_SHIFT=11, sl@0: _NORM_AUX_NFC_SKIPPABLE_F_SHIFT=12 sl@0: }; sl@0: sl@0: #define _NORM_AUX_MAX_FNC ((int32_t)1<<_NORM_AUX_COMP_EX_SHIFT) sl@0: sl@0: #define _NORM_AUX_FNC_MASK (uint32_t)(_NORM_AUX_MAX_FNC-1) sl@0: #define _NORM_AUX_COMP_EX_MASK ((uint32_t)1<<_NORM_AUX_COMP_EX_SHIFT) sl@0: #define _NORM_AUX_UNSAFE_MASK ((uint32_t)1<<_NORM_AUX_UNSAFE_SHIFT) sl@0: #define _NORM_AUX_NFC_SKIP_F_MASK ((uint32_t)1<<_NORM_AUX_NFC_SKIPPABLE_F_SHIFT) sl@0: sl@0: /* canonStartSets[0..31] contains indexes for what is in the array */ sl@0: enum { sl@0: _NORM_SET_INDEX_CANON_SETS_LENGTH, /* number of uint16_t in canonical starter sets */ sl@0: _NORM_SET_INDEX_CANON_BMP_TABLE_LENGTH, /* number of uint16_t in the BMP search table (contains pairs) */ sl@0: _NORM_SET_INDEX_CANON_SUPP_TABLE_LENGTH,/* number of uint16_t in the supplementary search table (contains triplets) */ sl@0: sl@0: /* from formatVersion 2.3: */ sl@0: _NORM_SET_INDEX_NX_CJK_COMPAT_OFFSET, /* uint16_t offset from canonStartSets[0] to the sl@0: exclusion set for CJK compatibility characters */ sl@0: _NORM_SET_INDEX_NX_UNICODE32_OFFSET, /* uint16_t offset from canonStartSets[0] to the sl@0: exclusion set for Unicode 3.2 characters */ sl@0: _NORM_SET_INDEX_NX_RESERVED_OFFSET, /* uint16_t offset from canonStartSets[0] to the sl@0: end of the previous exclusion set */ sl@0: sl@0: _NORM_SET_INDEX_TOP=32 /* changing this requires a new formatVersion */ sl@0: }; sl@0: sl@0: /* more constants for canonical starter sets */ sl@0: sl@0: /* 14 bit indexes to canonical USerializedSets */ sl@0: #define _NORM_MAX_CANON_SETS 0x4000 sl@0: sl@0: /* single-code point BMP sets are encoded directly in the search table except if result=0x4000..0x7fff */ sl@0: #define _NORM_CANON_SET_BMP_MASK 0xc000 sl@0: #define _NORM_CANON_SET_BMP_IS_INDEX 0x4000 sl@0: sl@0: /* indexes[] value names */ sl@0: enum { sl@0: _NORM_INDEX_TRIE_SIZE, /* number of bytes in normalization trie */ sl@0: _NORM_INDEX_UCHAR_COUNT, /* number of UChars in extra data */ sl@0: sl@0: _NORM_INDEX_COMBINE_DATA_COUNT, /* number of uint16_t words for combining data */ sl@0: _NORM_INDEX_COMBINE_FWD_COUNT, /* number of code points that combine forward */ sl@0: _NORM_INDEX_COMBINE_BOTH_COUNT, /* number of code points that combine forward and backward */ sl@0: _NORM_INDEX_COMBINE_BACK_COUNT, /* number of code points that combine backward */ sl@0: sl@0: _NORM_INDEX_MIN_NFC_NO_MAYBE, /* first code point with quick check NFC NO/MAYBE */ sl@0: _NORM_INDEX_MIN_NFKC_NO_MAYBE, /* first code point with quick check NFKC NO/MAYBE */ sl@0: _NORM_INDEX_MIN_NFD_NO_MAYBE, /* first code point with quick check NFD NO/MAYBE */ sl@0: _NORM_INDEX_MIN_NFKD_NO_MAYBE, /* first code point with quick check NFKD NO/MAYBE */ sl@0: sl@0: _NORM_INDEX_FCD_TRIE_SIZE, /* number of bytes in FCD trie */ sl@0: sl@0: _NORM_INDEX_AUX_TRIE_SIZE, /* number of bytes in the auxiliary trie */ sl@0: _NORM_INDEX_CANON_SET_COUNT, /* number of uint16_t in the array of serialized USet */ sl@0: sl@0: _NORM_INDEX_TOP=32 /* changing this requires a new formatVersion */ sl@0: }; sl@0: sl@0: enum { sl@0: /* FCD check: everything below this code point is known to have a 0 lead combining class */ sl@0: _NORM_MIN_WITH_LEAD_CC=0x300 sl@0: }; sl@0: sl@0: enum { sl@0: /** sl@0: * Bit 7 of the length byte for a decomposition string in extra data is sl@0: * a flag indicating whether the decomposition string is sl@0: * preceded by a 16-bit word with the leading and trailing cc sl@0: * of the decomposition (like for A-umlaut); sl@0: * if not, then both cc's are zero (like for compatibility ideographs). sl@0: */ sl@0: _NORM_DECOMP_FLAG_LENGTH_HAS_CC=0x80, sl@0: /** sl@0: * Bits 6..0 of the length byte contain the actual length. sl@0: */ sl@0: _NORM_DECOMP_LENGTH_MASK=0x7f sl@0: }; sl@0: sl@0: #endif /* #if !UCONFIG_NO_NORMALIZATION */ sl@0: sl@0: /* Korean Hangul and Jamo constants */ sl@0: enum { sl@0: JAMO_L_BASE=0x1100, /* "lead" jamo */ sl@0: JAMO_V_BASE=0x1161, /* "vowel" jamo */ sl@0: JAMO_T_BASE=0x11a7, /* "trail" jamo */ sl@0: sl@0: HANGUL_BASE=0xac00, sl@0: sl@0: JAMO_L_COUNT=19, sl@0: JAMO_V_COUNT=21, sl@0: JAMO_T_COUNT=28, sl@0: sl@0: HANGUL_COUNT=JAMO_L_COUNT*JAMO_V_COUNT*JAMO_T_COUNT sl@0: }; sl@0: sl@0: #if !UCONFIG_NO_NORMALIZATION sl@0: sl@0: /* Constants for options flags for normalization. @draft ICU 2.6 */ sl@0: enum { sl@0: /** Options bit 0, do not decompose Hangul syllables. @draft ICU 2.6 */ sl@0: UNORM_NX_HANGUL=1, sl@0: /** Options bit 1, do not decompose CJK compatibility characters. @draft ICU 2.6 */ sl@0: UNORM_NX_CJK_COMPAT=2, sl@0: /** sl@0: * Options bit 8, use buggy recomposition described in sl@0: * Unicode Public Review Issue #29 sl@0: * at http://www.unicode.org/review/resolved-pri.html#pri29 sl@0: * sl@0: * Used in IDNA implementation according to strict interpretation sl@0: * of IDNA definition based on Unicode 3.2 which predates PRI #29. sl@0: */ sl@0: UNORM_BEFORE_PRI_29=0x100 sl@0: }; sl@0: sl@0: /** sl@0: * Is the normalizer data loaded? sl@0: * This is used internally before other internal normalizer functions sl@0: * are called. sl@0: * It saves this check in each of many normalization calls that sl@0: * are made for, e.g., collation. sl@0: * sl@0: * @param pErrorCode as usual sl@0: * @return boolean value for whether the normalization data is loaded sl@0: * sl@0: * @internal sl@0: */ sl@0: U_CAPI UBool U_EXPORT2 sl@0: unorm_haveData(UErrorCode *pErrorCode); sl@0: sl@0: /** sl@0: * Internal API for normalizing. sl@0: * Does not check for bad input. sl@0: * @internal sl@0: */ sl@0: U_CAPI int32_t U_EXPORT2 sl@0: unorm_internalNormalize(UChar *dest, int32_t destCapacity, sl@0: const UChar *src, int32_t srcLength, sl@0: UNormalizationMode mode, int32_t options, sl@0: UErrorCode *pErrorCode); sl@0: sl@0: #ifdef XP_CPLUSPLUS sl@0: sl@0: /** sl@0: * Internal API for normalizing. sl@0: * Does not check for bad input. sl@0: * Requires _haveData() to be true. sl@0: * @internal sl@0: */ sl@0: U_CFUNC int32_t sl@0: unorm_internalNormalizeWithNX(UChar *dest, int32_t destCapacity, sl@0: const UChar *src, int32_t srcLength, sl@0: UNormalizationMode mode, int32_t options, const UnicodeSet *nx, sl@0: UErrorCode *pErrorCode); sl@0: sl@0: #endif sl@0: sl@0: /** sl@0: * internal API, used by normlzr.cpp sl@0: * @internal sl@0: */ sl@0: U_CAPI int32_t U_EXPORT2 sl@0: unorm_decompose(UChar *dest, int32_t destCapacity, sl@0: const UChar *src, int32_t srcLength, sl@0: UBool compat, int32_t options, sl@0: UErrorCode *pErrorCode); sl@0: sl@0: /** sl@0: * internal API, used by normlzr.cpp sl@0: * @internal sl@0: */ sl@0: U_CAPI int32_t U_EXPORT2 sl@0: unorm_compose(UChar *dest, int32_t destCapacity, sl@0: const UChar *src, int32_t srcLength, sl@0: UBool compat, int32_t options, sl@0: UErrorCode *pErrorCode); sl@0: sl@0: #ifdef XP_CPLUSPLUS sl@0: sl@0: /** sl@0: * internal API, used by unormcmp.cpp sl@0: * @internal sl@0: */ sl@0: U_CFUNC UNormalizationCheckResult sl@0: unorm_internalQuickCheck(const UChar *src, sl@0: int32_t srcLength, sl@0: UNormalizationMode mode, sl@0: UBool allowMaybe, sl@0: const UnicodeSet *nx, sl@0: UErrorCode *pErrorCode); sl@0: sl@0: #endif sl@0: sl@0: #endif /* #if !UCONFIG_NO_NORMALIZATION */ sl@0: sl@0: /** sl@0: * Internal option for unorm_cmpEquivFold() for decomposing. sl@0: * If not set, just do strcasecmp(). sl@0: * @internal sl@0: */ sl@0: #define _COMPARE_EQUIV 0x80000 sl@0: sl@0: #ifndef U_COMPARE_IGNORE_CASE sl@0: /* see also unorm.h */ sl@0: /** sl@0: * Option bit for unorm_compare: sl@0: * Perform case-insensitive comparison. sl@0: * @draft ICU 2.2 sl@0: */ sl@0: #define U_COMPARE_IGNORE_CASE 0x10000 sl@0: #endif sl@0: sl@0: /** sl@0: * Internal option for unorm_cmpEquivFold() for strncmp style. sl@0: * If set, checks for both string length and terminating NUL. sl@0: * @internal sl@0: */ sl@0: #define _STRNCMP_STYLE 0x1000 sl@0: sl@0: #if !UCONFIG_NO_NORMALIZATION sl@0: sl@0: /** sl@0: * Internal API to get the 16-bit FCD value (lccc + tccc) for c, sl@0: * for u_getIntPropertyValue(). sl@0: * @internal sl@0: */ sl@0: U_CAPI uint16_t U_EXPORT2 sl@0: unorm_getFCD16FromCodePoint(UChar32 c); sl@0: sl@0: /** sl@0: * Internal API, used by collation code. sl@0: * Get access to the internal FCD trie table to be able to perform sl@0: * incremental, per-code unit, FCD checks in collation. sl@0: * One pointer is sufficient because the trie index values are offset sl@0: * by the index size, so that the same pointer is used to access the trie data. sl@0: * @internal sl@0: */ sl@0: U_CAPI const uint16_t * U_EXPORT2 sl@0: unorm_getFCDTrie(UErrorCode *pErrorCode); sl@0: sl@0: #ifdef XP_CPLUSPLUS sl@0: sl@0: U_NAMESPACE_BEGIN sl@0: /** sl@0: * Internal API, used by collation code. sl@0: * Get the FCD value for a code unit, with sl@0: * bits 15..8 lead combining class sl@0: * bits 7..0 trail combining class sl@0: * sl@0: * If c is a lead surrogate and the value is not 0, sl@0: * then instead of combining classes the value sl@0: * is used in unorm_getFCD16FromSurrogatePair() to get the real value sl@0: * of the supplementary code point. sl@0: * sl@0: * @internal sl@0: */ sl@0: inline uint16_t sl@0: unorm_getFCD16(const uint16_t *fcdTrieIndex, UChar c) { sl@0: return sl@0: fcdTrieIndex[ sl@0: (fcdTrieIndex[ sl@0: c>>UTRIE_SHIFT sl@0: ]<>UTRIE_SHIFT) sl@0: ]<-skippable code point? See unormimp.h. sl@0: * @internal sl@0: */ sl@0: U_CAPI UBool U_EXPORT2 sl@0: unorm_isNFSkippable(UChar32 c, UNormalizationMode mode); sl@0: sl@0: #ifdef XP_CPLUSPLUS sl@0: sl@0: /** sl@0: * Get normalization exclusion set for the options. sl@0: * Requires unorm_haveData(). sl@0: * @internal sl@0: */ sl@0: U_CFUNC const UnicodeSet * sl@0: unorm_getNX(int32_t options, UErrorCode *pErrorCode); sl@0: sl@0: #endif sl@0: sl@0: /** sl@0: * Enumerate each normalization data trie and add the sl@0: * start of each range of same properties to the set. sl@0: * @internal sl@0: */ sl@0: U_CAPI void U_EXPORT2 sl@0: unorm_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode); sl@0: sl@0: /** sl@0: * Swap unorm.icu. See udataswp.h. sl@0: * @internal sl@0: */ sl@0: U_CAPI int32_t U_EXPORT2 sl@0: unorm_swap(const UDataSwapper *ds, sl@0: const void *inData, int32_t length, void *outData, sl@0: UErrorCode *pErrorCode); sl@0: sl@0: /** sl@0: * Get the NF*_QC property for a code point, for u_getIntPropertyValue(). sl@0: * @internal sl@0: */ sl@0: U_CAPI UNormalizationCheckResult U_EXPORT2 sl@0: unorm_getQuickCheck(UChar32 c, UNormalizationMode mode); sl@0: sl@0: /** sl@0: * Description of the format of unorm.icu version 2.3. sl@0: * sl@0: * Main change from version 1 to version 2: sl@0: * Use of new, common UTrie instead of normalization-specific tries. sl@0: * Change to version 2.1: add third/auxiliary trie with associated data. sl@0: * Change to version 2.2: add skippable (f) flag data (_NORM_AUX_NFC_SKIP_F_MASK). sl@0: * Change to version 2.3: add serialized sets for normalization exclusions sl@0: * stored inside canonStartSets[] sl@0: * sl@0: * For more details of how to use the data structures see the code sl@0: * in unorm.cpp (runtime normalization code) and sl@0: * in gennorm.c and gennorm/store.c (build-time data generation). sl@0: * sl@0: * For the serialized format of UTrie see utrie.c/UTrieHeader. sl@0: * sl@0: * - Overall partition sl@0: * sl@0: * unorm.dat customarily begins with a UDataInfo structure, see udata.h and .c. sl@0: * After that there are the following structures: sl@0: * sl@0: * int32_t indexes[_NORM_INDEX_TOP]; -- _NORM_INDEX_TOP=32, see enum in this file sl@0: * sl@0: * UTrie normTrie; -- size in bytes=indexes[_NORM_INDEX_TRIE_SIZE] sl@0: * sl@0: * uint16_t extraData[extraDataTop]; -- extraDataTop=indexes[_NORM_INDEX_UCHAR_COUNT] sl@0: * extraData[0] contains the number of units for sl@0: * FC_NFKC_Closure (formatVersion>=2.1) sl@0: * sl@0: * uint16_t combiningTable[combiningTableTop]; -- combiningTableTop=indexes[_NORM_INDEX_COMBINE_DATA_COUNT] sl@0: * combiningTableTop may include one 16-bit padding unit sl@0: * to make sure that fcdTrie is 32-bit-aligned sl@0: * sl@0: * UTrie fcdTrie; -- size in bytes=indexes[_NORM_INDEX_FCD_TRIE_SIZE] sl@0: * sl@0: * UTrie auxTrie; -- size in bytes=indexes[_NORM_INDEX_AUX_TRIE_SIZE] sl@0: * sl@0: * uint16_t canonStartSets[canonStartSetsTop] -- canonStartSetsTop=indexes[_NORM_INDEX_CANON_SET_COUNT] sl@0: * serialized USets and binary search tables, see below sl@0: * sl@0: * sl@0: * The indexes array contains lengths and sizes of the following arrays and structures sl@0: * as well as the following values: sl@0: * indexes[_NORM_INDEX_COMBINE_FWD_COUNT]=combineFwdTop sl@0: * -- one more than the highest combining index computed for forward-only-combining characters sl@0: * indexes[_NORM_INDEX_COMBINE_BOTH_COUNT]=combineBothTop-combineFwdTop sl@0: * -- number of combining indexes computed for both-ways-combining characters sl@0: * indexes[_NORM_INDEX_COMBINE_BACK_COUNT]=combineBackTop-combineBothTop sl@0: * -- number of combining indexes computed for backward-only-combining characters sl@0: * sl@0: * indexes[_NORM_INDEX_MIN_NF*_NO_MAYBE] (where *={ C, D, KC, KD }) sl@0: * -- first code point with a quick check NF* value of NO/MAYBE sl@0: * sl@0: * sl@0: * - Tries sl@0: * sl@0: * The main structures are two UTrie tables ("compact arrays"), sl@0: * each with one index array and one data array. sl@0: * See utrie.h and utrie.c. sl@0: * sl@0: * sl@0: * - Tries in unorm.dat sl@0: * sl@0: * The first trie (normTrie above) sl@0: * provides data for the NF* quick checks and normalization. sl@0: * The second trie (fcdTrie above) provides data just for FCD checks. sl@0: * sl@0: * sl@0: * - norm32 data words from the first trie sl@0: * sl@0: * The norm32Table contains one 32-bit word "norm32" per code point. sl@0: * It contains the following bit fields: sl@0: * 31..16 extra data index, _NORM_EXTRA_SHIFT is used to shift this field down sl@0: * if this index is <_NORM_EXTRA_INDEX_TOP then it is an index into sl@0: * extraData[] where variable-length normalization data for this sl@0: * code point is found sl@0: * if this index is <_NORM_EXTRA_INDEX_TOP+_NORM_EXTRA_SURROGATE_TOP sl@0: * then this is a norm32 for a leading surrogate, and the index sl@0: * value is used together with the following trailing surrogate sl@0: * code unit in the second trie access sl@0: * if this index is >=_NORM_EXTRA_INDEX_TOP+_NORM_EXTRA_SURROGATE_TOP sl@0: * then this is a norm32 for a "special" character, sl@0: * i.e., the character is a Hangul syllable or a Jamo sl@0: * see _NORM_EXTRA_HANGUL etc. sl@0: * generally, instead of extracting this index from the norm32 and sl@0: * comparing it with the above constants, sl@0: * the normalization code compares the entire norm32 value sl@0: * with _NORM_MIN_SPECIAL, _NORM_SURROGATES_TOP, _NORM_MIN_HANGUL etc. sl@0: * sl@0: * 15..8 combining class (cc) according to UnicodeData.txt sl@0: * sl@0: * 7..6 _NORM_COMBINES_ANY flags, used in composition to see if a character sl@0: * combines with any following or preceding character(s) sl@0: * at all sl@0: * 7 _NORM_COMBINES_BACK sl@0: * 6 _NORM_COMBINES_FWD sl@0: * sl@0: * 5..0 quick check flags, set for "no" or "maybe", with separate flags for sl@0: * each normalization form sl@0: * the higher bits are "maybe" flags; for NF*D there are no such flags sl@0: * the lower bits are "no" flags for all forms, in the same order sl@0: * as the "maybe" flags, sl@0: * which is (MSB to LSB): NFKD NFD NFKC NFC sl@0: * 5..4 _NORM_QC_ANY_MAYBE sl@0: * 3..0 _NORM_QC_ANY_NO sl@0: * see further related constants sl@0: * sl@0: * sl@0: * - Extra data per code point sl@0: * sl@0: * "Extra data" is referenced by the index in norm32. sl@0: * It is variable-length data. It is only present, and only those parts sl@0: * of it are, as needed for a given character. sl@0: * The norm32 extra data index is added to the beginning of extraData[] sl@0: * to get to a vector of 16-bit words with data at the following offsets: sl@0: * sl@0: * [-1] Combining index for composition. sl@0: * Stored only if norm32&_NORM_COMBINES_ANY . sl@0: * [0] Lengths of the canonical and compatibility decomposition strings. sl@0: * Stored only if there are decompositions, i.e., sl@0: * if norm32&(_NORM_QC_NFD|_NORM_QC_NFKD) sl@0: * High byte: length of NFKD, or 0 if none sl@0: * Low byte: length of NFD, or 0 if none sl@0: * Each length byte also has another flag: sl@0: * Bit 7 of a length byte is set if there are non-zero sl@0: * combining classes (cc's) associated with the respective sl@0: * decomposition. If this flag is set, then the decomposition sl@0: * is preceded by a 16-bit word that contains the sl@0: * leading and trailing cc's. sl@0: * Bits 6..0 of a length byte are the length of the sl@0: * decomposition string, not counting the cc word. sl@0: * [1..n] NFD sl@0: * [n+1..] NFKD sl@0: * sl@0: * Each of the two decompositions consists of up to two parts: sl@0: * - The 16-bit words with the leading and trailing cc's. sl@0: * This is only stored if bit 7 of the corresponding length byte sl@0: * is set. In this case, at least one of the cc's is not zero. sl@0: * High byte: leading cc==cc of the first code point in the decomposition string sl@0: * Low byte: trailing cc==cc of the last code point in the decomposition string sl@0: * - The decomposition string in UTF-16, with length code units. sl@0: * sl@0: * sl@0: * - Combining indexes and combiningTable[] sl@0: * sl@0: * Combining indexes are stored at the [-1] offset of the extra data sl@0: * if the character combines forward or backward with any other characters. sl@0: * They are used for (re)composition in NF*C. sl@0: * Values of combining indexes are arranged according to whether a character sl@0: * combines forward, backward, or both ways: sl@0: * forward-only < both ways < backward-only sl@0: * sl@0: * The index values for forward-only and both-ways combining characters sl@0: * are indexes into the combiningTable[]. sl@0: * The index values for backward-only combining characters are simply sl@0: * incremented from the preceding index values to be unique. sl@0: * sl@0: * In the combiningTable[], a variable-length list sl@0: * of variable-length (back-index, code point) pair entries is stored sl@0: * for each forward-combining character. sl@0: * sl@0: * These back-indexes are the combining indexes of both-ways or backward-only sl@0: * combining characters that the forward-combining character combines with. sl@0: * sl@0: * Each list is sorted in ascending order of back-indexes. sl@0: * Each list is terminated with the last back-index having bit 15 set. sl@0: * sl@0: * Each pair (back-index, code point) takes up either 2 or 3 sl@0: * 16-bit words. sl@0: * The first word of a list entry is the back-index, with its bit 15 set if sl@0: * this is the last pair in the list. sl@0: * sl@0: * The second word contains flags in bits 15..13 that determine sl@0: * if there is a third word and how the combined character is encoded: sl@0: * 15 set if there is a third word in this list entry sl@0: * 14 set if the result is a supplementary character sl@0: * 13 set if the result itself combines forward sl@0: * sl@0: * According to these bits 15..14 of the second word, sl@0: * the result character is encoded as follows: sl@0: * 00 or 01 The result is <=0x1fff and stored in bits 12..0 of sl@0: * the second word. sl@0: * 10 The result is 0x2000..0xffff and stored in the third word. sl@0: * Bits 12..0 of the second word are not used. sl@0: * 11 The result is a supplementary character. sl@0: * Bits 9..0 of the leading surrogate are in bits 9..0 of sl@0: * the second word. sl@0: * Add 0xd800 to these bits to get the complete surrogate. sl@0: * Bits 12..10 of the second word are not used. sl@0: * The trailing surrogate is stored in the third word. sl@0: * sl@0: * sl@0: * - FCD trie sl@0: * sl@0: * The FCD trie is very simple. sl@0: * It is a folded trie with 16-bit data words. sl@0: * In each word, the high byte contains the leading cc of the character, sl@0: * and the low byte contains the trailing cc of the character. sl@0: * These cc's are the cc's of the first and last code points in the sl@0: * canonical decomposition of the character. sl@0: * sl@0: * Since all 16 bits are used for cc's, lead surrogates must be tested sl@0: * by checking the code unit instead of the trie data. sl@0: * This is done only if the 16-bit data word is not zero. sl@0: * If the code unit is a leading surrogate and the data word is not zero, sl@0: * then instead of cc's it contains the offset for the second trie lookup. sl@0: * sl@0: * sl@0: * - Auxiliary trie and data sl@0: * sl@0: * The auxiliary 16-bit trie contains data for additional properties. sl@0: * Bits sl@0: * 15..13 reserved sl@0: * 12 not NFC_Skippable (f) (formatVersion>=2.2) sl@0: * 11 flag: not a safe starter for canonical closure sl@0: * 10 composition exclusion sl@0: * 9.. 0 index into extraData[] to FC_NFKC_Closure string sl@0: * (not for lead surrogate), sl@0: * or lead surrogate offset (for lead surrogate, if 9..0 not zero) sl@0: * sl@0: * - FC_NFKC_Closure strings in extraData[] sl@0: * sl@0: * Strings are either stored as a single code unit or as the length sl@0: * followed by that many units. sl@0: * const UChar *s=extraData+(index from auxTrie data bits 9..0); sl@0: * int32_t length; sl@0: * if(*s<0xff00) { sl@0: * // s points to the single-unit string sl@0: * length=1; sl@0: * } else { sl@0: * length=*s&0xff; sl@0: * ++s; sl@0: * } sl@0: * sl@0: * Conditions for "NF* Skippable" from Mark Davis' com.ibm.text.UCD.NFSkippable: sl@0: * (used in NormalizerTransliterator) sl@0: * sl@0: * A skippable character is sl@0: * a) unassigned, or ALL of the following: sl@0: * b) of combining class 0. sl@0: * c) not decomposed by this normalization form. sl@0: * AND if NFC or NFKC, sl@0: * d) can never compose with a previous character. sl@0: * e) can never compose with a following character. sl@0: * f) can never change if another character is added. sl@0: * Example: a-breve might satisfy all but f, but if you sl@0: * add an ogonek it changes to a-ogonek + breve sl@0: * sl@0: * a)..e) must be tested from norm32. sl@0: * Since f) is more complicated, the (not-)NFC_Skippable flag (f) is built sl@0: * into the auxiliary trie. sl@0: * The same bit is used for NFC and NFKC; (c) differs for them. sl@0: * As usual, we build the "not skippable" flags so that unassigned sl@0: * code points get a 0 bit. sl@0: * This bit is only valid after (a)..(e) test FALSE; test NFD_NO before (f) as well. sl@0: * Test Hangul LV syllables entirely in code. sl@0: * sl@0: * sl@0: * - structure inside canonStartSets[] sl@0: * sl@0: * This array maps from code points c to sets of code points (USerializedSet). sl@0: * The result sets are the code points whose canonical decompositions start sl@0: * with c. sl@0: * sl@0: * canonStartSets[] contains the following sub-arrays: sl@0: * sl@0: * indexes[_NORM_SET_INDEX_TOP] sl@0: * - contains lengths of sub-arrays etc. sl@0: * sl@0: * startSets[indexes[_NORM_SET_INDEX_CANON_SETS_LENGTH]-_NORM_SET_INDEX_TOP] sl@0: * - contains serialized sets (USerializedSet) of canonical starters for sl@0: * enumerating canonically equivalent strings sl@0: * indexes[_NORM_SET_INDEX_CANON_SETS_LENGTH] includes _NORM_SET_INDEX_TOP sl@0: * for details about the structure see uset.c sl@0: * sl@0: * bmpTable[indexes[_NORM_SET_INDEX_CANON_BMP_TABLE_LENGTH]] sl@0: * - a sorted search table for BMP code points whose results are sl@0: * either indexes to USerializedSets or single code points for sl@0: * single-code point sets; sl@0: * each entry is a pair of { code point, result } with result=(binary) yy xxxxxx xxxxxxxx sl@0: * if yy==01 then there is a USerializedSet at canonStartSets+x sl@0: * else build a USerializedSet with result as the single code point sl@0: * sl@0: * suppTable[indexes[_NORM_SET_INDEX_CANON_SUPP_TABLE_LENGTH]] sl@0: * - a sorted search table for supplementary code points whose results are sl@0: * either indexes to USerializedSets or single code points for sl@0: * single-code point sets; sl@0: * each entry is a triplet of { high16(cp), low16(cp), result } sl@0: * each code point's high-word may contain extra data in bits 15..5: sl@0: * if the high word has bit 15 set, then build a set with a single code point sl@0: * which is (((high16(cp)&0x1f00)<<8)|result; sl@0: * else there is a USerializedSet at canonStartSets+result sl@0: * sl@0: * FormatVersion 2.3 adds 2 serialized sets for normalization exclusions. sl@0: * They are stored in the data file so that the runtime normalization code need sl@0: * not depend on other properties and their data and implementation files. sl@0: * The _NORM_SET_INDEX_NX_..._OFFSET offsets in the canonStartSets index table sl@0: * give the location for each set. sl@0: * There is no set stored for UNORM_NX_HANGUL because it's trivial to create sl@0: * without using properties. sl@0: * sl@0: * Set contents: sl@0: * sl@0: * _NORM_SET_INDEX_NX_CJK_COMPAT_OFFSET (for UNORM_NX_CJK_COMPAT) sl@0: * [[:Ideographic:]&[:NFD_QC=No:]] sl@0: * =[CJK Ideographs]&[has canonical decomposition] sl@0: * sl@0: * _NORM_SET_INDEX_NX_UNICODE32_OFFSET (for UNORM_UNICODE_3_2) sl@0: * [:^Age=3.2:] sl@0: * =set with all code points that were not designated by the specified Unicode version sl@0: * sl@0: * _NORM_SET_INDEX_NX_RESERVED_OFFSET sl@0: * This is an offset that points to where the next, future set would start. sl@0: * Currently it indicates where the previous set ends, and thus its length. sl@0: * The name for this enum constant may in the future be applied to different sl@0: * index slots. In order to get the limit of a set, use its index slot and sl@0: * the immediately following one regardless of that one's enum name. sl@0: */ sl@0: sl@0: #endif /* #if !UCONFIG_NO_NORMALIZATION */ sl@0: sl@0: #endif