1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others. 2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html 3*0e209d39SAndroid Build Coastguard Worker /* 4*0e209d39SAndroid Build Coastguard Worker ******************************************************************************* 5*0e209d39SAndroid Build Coastguard Worker * 6*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 2001-2011, International Business Machines 7*0e209d39SAndroid Build Coastguard Worker * Corporation and others. All Rights Reserved. 8*0e209d39SAndroid Build Coastguard Worker * 9*0e209d39SAndroid Build Coastguard Worker ******************************************************************************* 10*0e209d39SAndroid Build Coastguard Worker * file name: unormimp.h 11*0e209d39SAndroid Build Coastguard Worker * encoding: UTF-8 12*0e209d39SAndroid Build Coastguard Worker * tab size: 8 (not used) 13*0e209d39SAndroid Build Coastguard Worker * indentation:4 14*0e209d39SAndroid Build Coastguard Worker * 15*0e209d39SAndroid Build Coastguard Worker * created on: 2001may25 16*0e209d39SAndroid Build Coastguard Worker * created by: Markus W. Scherer 17*0e209d39SAndroid Build Coastguard Worker */ 18*0e209d39SAndroid Build Coastguard Worker 19*0e209d39SAndroid Build Coastguard Worker #ifndef __UNORMIMP_H__ 20*0e209d39SAndroid Build Coastguard Worker #define __UNORMIMP_H__ 21*0e209d39SAndroid Build Coastguard Worker 22*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h" 23*0e209d39SAndroid Build Coastguard Worker 24*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_NORMALIZATION 25*0e209d39SAndroid Build Coastguard Worker 26*0e209d39SAndroid Build Coastguard Worker #include "udataswp.h" 27*0e209d39SAndroid Build Coastguard Worker 28*0e209d39SAndroid Build Coastguard Worker /* 29*0e209d39SAndroid Build Coastguard Worker * The 2001-2010 implementation of the normalization code loads its data from 30*0e209d39SAndroid Build Coastguard Worker * unorm.icu, which is generated with the gennorm tool. 31*0e209d39SAndroid Build Coastguard Worker * The format of that file is described at the end of this file. 32*0e209d39SAndroid Build Coastguard Worker */ 33*0e209d39SAndroid Build Coastguard Worker 34*0e209d39SAndroid Build Coastguard Worker /* norm32 value constants */ 35*0e209d39SAndroid Build Coastguard Worker enum { 36*0e209d39SAndroid Build Coastguard Worker /* quick check flags 0..3 set mean "no" for their forms */ 37*0e209d39SAndroid Build Coastguard Worker _NORM_QC_NFC=0x11, /* no|maybe */ 38*0e209d39SAndroid Build Coastguard Worker _NORM_QC_NFKC=0x22, /* no|maybe */ 39*0e209d39SAndroid Build Coastguard Worker _NORM_QC_NFD=4, /* no */ 40*0e209d39SAndroid Build Coastguard Worker _NORM_QC_NFKD=8, /* no */ 41*0e209d39SAndroid Build Coastguard Worker 42*0e209d39SAndroid Build Coastguard Worker _NORM_QC_ANY_NO=0xf, 43*0e209d39SAndroid Build Coastguard Worker 44*0e209d39SAndroid Build Coastguard Worker /* quick check flags 4..5 mean "maybe" for their forms; test flags>=_NORM_QC_MAYBE */ 45*0e209d39SAndroid Build Coastguard Worker _NORM_QC_MAYBE=0x10, 46*0e209d39SAndroid Build Coastguard Worker _NORM_QC_ANY_MAYBE=0x30, 47*0e209d39SAndroid Build Coastguard Worker 48*0e209d39SAndroid Build Coastguard Worker _NORM_QC_MASK=0x3f, 49*0e209d39SAndroid Build Coastguard Worker 50*0e209d39SAndroid Build Coastguard Worker _NORM_COMBINES_FWD=0x40, 51*0e209d39SAndroid Build Coastguard Worker _NORM_COMBINES_BACK=0x80, 52*0e209d39SAndroid Build Coastguard Worker _NORM_COMBINES_ANY=0xc0, 53*0e209d39SAndroid Build Coastguard Worker 54*0e209d39SAndroid Build Coastguard Worker _NORM_CC_SHIFT=8, /* UnicodeData.txt combining class in bits 15..8 */ 55*0e209d39SAndroid Build Coastguard Worker _NORM_CC_MASK=0xff00, 56*0e209d39SAndroid Build Coastguard Worker 57*0e209d39SAndroid Build Coastguard Worker _NORM_EXTRA_SHIFT=16, /* 16 bits for the index to UChars and other extra data */ 58*0e209d39SAndroid Build Coastguard Worker _NORM_EXTRA_INDEX_TOP=0xfc00, /* start of surrogate specials after shift */ 59*0e209d39SAndroid Build Coastguard Worker 60*0e209d39SAndroid Build Coastguard Worker _NORM_EXTRA_SURROGATE_MASK=0x3ff, 61*0e209d39SAndroid Build Coastguard Worker _NORM_EXTRA_SURROGATE_TOP=0x3f0, /* hangul etc. */ 62*0e209d39SAndroid Build Coastguard Worker 63*0e209d39SAndroid Build Coastguard Worker _NORM_EXTRA_HANGUL=_NORM_EXTRA_SURROGATE_TOP, 64*0e209d39SAndroid Build Coastguard Worker _NORM_EXTRA_JAMO_L, 65*0e209d39SAndroid Build Coastguard Worker _NORM_EXTRA_JAMO_V, 66*0e209d39SAndroid Build Coastguard Worker _NORM_EXTRA_JAMO_T 67*0e209d39SAndroid Build Coastguard Worker }; 68*0e209d39SAndroid Build Coastguard Worker 69*0e209d39SAndroid Build Coastguard Worker /* norm32 value constants using >16 bits */ 70*0e209d39SAndroid Build Coastguard Worker #define _NORM_MIN_SPECIAL 0xfc000000 71*0e209d39SAndroid Build Coastguard Worker #define _NORM_SURROGATES_TOP 0xfff00000 72*0e209d39SAndroid Build Coastguard Worker #define _NORM_MIN_HANGUL 0xfff00000 73*0e209d39SAndroid Build Coastguard Worker #define _NORM_MIN_JAMO_V 0xfff20000 74*0e209d39SAndroid Build Coastguard Worker #define _NORM_JAMO_V_TOP 0xfff30000 75*0e209d39SAndroid Build Coastguard Worker 76*0e209d39SAndroid Build Coastguard Worker /* value constants for auxTrie */ 77*0e209d39SAndroid Build Coastguard Worker enum { 78*0e209d39SAndroid Build Coastguard Worker _NORM_AUX_COMP_EX_SHIFT=10, 79*0e209d39SAndroid Build Coastguard Worker _NORM_AUX_UNSAFE_SHIFT=11, 80*0e209d39SAndroid Build Coastguard Worker _NORM_AUX_NFC_SKIPPABLE_F_SHIFT=12 81*0e209d39SAndroid Build Coastguard Worker }; 82*0e209d39SAndroid Build Coastguard Worker 83*0e209d39SAndroid Build Coastguard Worker #define _NORM_AUX_MAX_FNC ((int32_t)1<<_NORM_AUX_COMP_EX_SHIFT) 84*0e209d39SAndroid Build Coastguard Worker 85*0e209d39SAndroid Build Coastguard Worker #define _NORM_AUX_FNC_MASK (uint32_t)(_NORM_AUX_MAX_FNC-1) 86*0e209d39SAndroid Build Coastguard Worker #define _NORM_AUX_COMP_EX_MASK ((uint32_t)1<<_NORM_AUX_COMP_EX_SHIFT) 87*0e209d39SAndroid Build Coastguard Worker #define _NORM_AUX_UNSAFE_MASK ((uint32_t)1<<_NORM_AUX_UNSAFE_SHIFT) 88*0e209d39SAndroid Build Coastguard Worker #define _NORM_AUX_NFC_SKIP_F_MASK ((uint32_t)1<<_NORM_AUX_NFC_SKIPPABLE_F_SHIFT) 89*0e209d39SAndroid Build Coastguard Worker 90*0e209d39SAndroid Build Coastguard Worker /* canonStartSets[0..31] contains indexes for what is in the array */ 91*0e209d39SAndroid Build Coastguard Worker enum { 92*0e209d39SAndroid Build Coastguard Worker _NORM_SET_INDEX_CANON_SETS_LENGTH, /* number of uint16_t in canonical starter sets */ 93*0e209d39SAndroid Build Coastguard Worker _NORM_SET_INDEX_CANON_BMP_TABLE_LENGTH, /* number of uint16_t in the BMP search table (contains pairs) */ 94*0e209d39SAndroid Build Coastguard Worker _NORM_SET_INDEX_CANON_SUPP_TABLE_LENGTH,/* number of uint16_t in the supplementary search table (contains triplets) */ 95*0e209d39SAndroid Build Coastguard Worker 96*0e209d39SAndroid Build Coastguard Worker /* from formatVersion 2.3: */ 97*0e209d39SAndroid Build Coastguard Worker _NORM_SET_INDEX_NX_CJK_COMPAT_OFFSET, /* uint16_t offset from canonStartSets[0] to the 98*0e209d39SAndroid Build Coastguard Worker exclusion set for CJK compatibility characters */ 99*0e209d39SAndroid Build Coastguard Worker _NORM_SET_INDEX_NX_UNICODE32_OFFSET, /* uint16_t offset from canonStartSets[0] to the 100*0e209d39SAndroid Build Coastguard Worker exclusion set for Unicode 3.2 characters */ 101*0e209d39SAndroid Build Coastguard Worker _NORM_SET_INDEX_NX_RESERVED_OFFSET, /* uint16_t offset from canonStartSets[0] to the 102*0e209d39SAndroid Build Coastguard Worker end of the previous exclusion set */ 103*0e209d39SAndroid Build Coastguard Worker 104*0e209d39SAndroid Build Coastguard Worker _NORM_SET_INDEX_TOP=32 /* changing this requires a new formatVersion */ 105*0e209d39SAndroid Build Coastguard Worker }; 106*0e209d39SAndroid Build Coastguard Worker 107*0e209d39SAndroid Build Coastguard Worker /* more constants for canonical starter sets */ 108*0e209d39SAndroid Build Coastguard Worker 109*0e209d39SAndroid Build Coastguard Worker /* 14 bit indexes to canonical USerializedSets */ 110*0e209d39SAndroid Build Coastguard Worker #define _NORM_MAX_CANON_SETS 0x4000 111*0e209d39SAndroid Build Coastguard Worker 112*0e209d39SAndroid Build Coastguard Worker /* single-code point BMP sets are encoded directly in the search table except if result=0x4000..0x7fff */ 113*0e209d39SAndroid Build Coastguard Worker #define _NORM_CANON_SET_BMP_MASK 0xc000 114*0e209d39SAndroid Build Coastguard Worker #define _NORM_CANON_SET_BMP_IS_INDEX 0x4000 115*0e209d39SAndroid Build Coastguard Worker 116*0e209d39SAndroid Build Coastguard Worker /* indexes[] value names */ 117*0e209d39SAndroid Build Coastguard Worker enum { 118*0e209d39SAndroid Build Coastguard Worker _NORM_INDEX_TRIE_SIZE, /* number of bytes in normalization trie */ 119*0e209d39SAndroid Build Coastguard Worker _NORM_INDEX_UCHAR_COUNT, /* number of UChars in extra data */ 120*0e209d39SAndroid Build Coastguard Worker 121*0e209d39SAndroid Build Coastguard Worker _NORM_INDEX_COMBINE_DATA_COUNT, /* number of uint16_t words for combining data */ 122*0e209d39SAndroid Build Coastguard Worker _NORM_INDEX_COMBINE_FWD_COUNT, /* number of code points that combine forward */ 123*0e209d39SAndroid Build Coastguard Worker _NORM_INDEX_COMBINE_BOTH_COUNT, /* number of code points that combine forward and backward */ 124*0e209d39SAndroid Build Coastguard Worker _NORM_INDEX_COMBINE_BACK_COUNT, /* number of code points that combine backward */ 125*0e209d39SAndroid Build Coastguard Worker 126*0e209d39SAndroid Build Coastguard Worker _NORM_INDEX_MIN_NFC_NO_MAYBE, /* first code point with quick check NFC NO/MAYBE */ 127*0e209d39SAndroid Build Coastguard Worker _NORM_INDEX_MIN_NFKC_NO_MAYBE, /* first code point with quick check NFKC NO/MAYBE */ 128*0e209d39SAndroid Build Coastguard Worker _NORM_INDEX_MIN_NFD_NO_MAYBE, /* first code point with quick check NFD NO/MAYBE */ 129*0e209d39SAndroid Build Coastguard Worker _NORM_INDEX_MIN_NFKD_NO_MAYBE, /* first code point with quick check NFKD NO/MAYBE */ 130*0e209d39SAndroid Build Coastguard Worker 131*0e209d39SAndroid Build Coastguard Worker _NORM_INDEX_FCD_TRIE_SIZE, /* number of bytes in FCD trie */ 132*0e209d39SAndroid Build Coastguard Worker 133*0e209d39SAndroid Build Coastguard Worker _NORM_INDEX_AUX_TRIE_SIZE, /* number of bytes in the auxiliary trie */ 134*0e209d39SAndroid Build Coastguard Worker _NORM_INDEX_CANON_SET_COUNT, /* number of uint16_t in the array of serialized USet */ 135*0e209d39SAndroid Build Coastguard Worker 136*0e209d39SAndroid Build Coastguard Worker _NORM_INDEX_TOP=32 /* changing this requires a new formatVersion */ 137*0e209d39SAndroid Build Coastguard Worker }; 138*0e209d39SAndroid Build Coastguard Worker 139*0e209d39SAndroid Build Coastguard Worker enum { 140*0e209d39SAndroid Build Coastguard Worker /* FCD check: everything below this code point is known to have a 0 lead combining class */ 141*0e209d39SAndroid Build Coastguard Worker _NORM_MIN_WITH_LEAD_CC=0x300 142*0e209d39SAndroid Build Coastguard Worker }; 143*0e209d39SAndroid Build Coastguard Worker 144*0e209d39SAndroid Build Coastguard Worker enum { 145*0e209d39SAndroid Build Coastguard Worker /** 146*0e209d39SAndroid Build Coastguard Worker * Bit 7 of the length byte for a decomposition string in extra data is 147*0e209d39SAndroid Build Coastguard Worker * a flag indicating whether the decomposition string is 148*0e209d39SAndroid Build Coastguard Worker * preceded by a 16-bit word with the leading and trailing cc 149*0e209d39SAndroid Build Coastguard Worker * of the decomposition (like for A-umlaut); 150*0e209d39SAndroid Build Coastguard Worker * if not, then both cc's are zero (like for compatibility ideographs). 151*0e209d39SAndroid Build Coastguard Worker */ 152*0e209d39SAndroid Build Coastguard Worker _NORM_DECOMP_FLAG_LENGTH_HAS_CC=0x80, 153*0e209d39SAndroid Build Coastguard Worker /** 154*0e209d39SAndroid Build Coastguard Worker * Bits 6..0 of the length byte contain the actual length. 155*0e209d39SAndroid Build Coastguard Worker */ 156*0e209d39SAndroid Build Coastguard Worker _NORM_DECOMP_LENGTH_MASK=0x7f 157*0e209d39SAndroid Build Coastguard Worker }; 158*0e209d39SAndroid Build Coastguard Worker 159*0e209d39SAndroid Build Coastguard Worker /** Constants for options flags for normalization. */ 160*0e209d39SAndroid Build Coastguard Worker enum { 161*0e209d39SAndroid Build Coastguard Worker /** Options bit 0, do not decompose Hangul syllables. */ 162*0e209d39SAndroid Build Coastguard Worker UNORM_NX_HANGUL=1, 163*0e209d39SAndroid Build Coastguard Worker /** Options bit 1, do not decompose CJK compatibility characters. */ 164*0e209d39SAndroid Build Coastguard Worker UNORM_NX_CJK_COMPAT=2 165*0e209d39SAndroid Build Coastguard Worker }; 166*0e209d39SAndroid Build Coastguard Worker 167*0e209d39SAndroid Build Coastguard Worker /** 168*0e209d39SAndroid Build Coastguard Worker * Description of the format of unorm.icu version 2.3. 169*0e209d39SAndroid Build Coastguard Worker * 170*0e209d39SAndroid Build Coastguard Worker * Main change from version 1 to version 2: 171*0e209d39SAndroid Build Coastguard Worker * Use of new, common UTrie instead of normalization-specific tries. 172*0e209d39SAndroid Build Coastguard Worker * Change to version 2.1: add third/auxiliary trie with associated data. 173*0e209d39SAndroid Build Coastguard Worker * Change to version 2.2: add skippable (f) flag data (_NORM_AUX_NFC_SKIP_F_MASK). 174*0e209d39SAndroid Build Coastguard Worker * Change to version 2.3: add serialized sets for normalization exclusions 175*0e209d39SAndroid Build Coastguard Worker * stored inside canonStartSets[] 176*0e209d39SAndroid Build Coastguard Worker * 177*0e209d39SAndroid Build Coastguard Worker * For more details of how to use the data structures see the code 178*0e209d39SAndroid Build Coastguard Worker * in unorm.cpp (runtime normalization code) and 179*0e209d39SAndroid Build Coastguard Worker * in gennorm.c and gennorm/store.c (build-time data generation). 180*0e209d39SAndroid Build Coastguard Worker * 181*0e209d39SAndroid Build Coastguard Worker * For the serialized format of UTrie see utrie.c/UTrieHeader. 182*0e209d39SAndroid Build Coastguard Worker * 183*0e209d39SAndroid Build Coastguard Worker * - Overall partition 184*0e209d39SAndroid Build Coastguard Worker * 185*0e209d39SAndroid Build Coastguard Worker * unorm.dat customarily begins with a UDataInfo structure, see udata.h and .c. 186*0e209d39SAndroid Build Coastguard Worker * After that there are the following structures: 187*0e209d39SAndroid Build Coastguard Worker * 188*0e209d39SAndroid Build Coastguard Worker * int32_t indexes[_NORM_INDEX_TOP]; -- _NORM_INDEX_TOP=32, see enum in this file 189*0e209d39SAndroid Build Coastguard Worker * 190*0e209d39SAndroid Build Coastguard Worker * UTrie normTrie; -- size in bytes=indexes[_NORM_INDEX_TRIE_SIZE] 191*0e209d39SAndroid Build Coastguard Worker * 192*0e209d39SAndroid Build Coastguard Worker * uint16_t extraData[extraDataTop]; -- extraDataTop=indexes[_NORM_INDEX_UCHAR_COUNT] 193*0e209d39SAndroid Build Coastguard Worker * extraData[0] contains the number of units for 194*0e209d39SAndroid Build Coastguard Worker * FC_NFKC_Closure (formatVersion>=2.1) 195*0e209d39SAndroid Build Coastguard Worker * 196*0e209d39SAndroid Build Coastguard Worker * uint16_t combiningTable[combiningTableTop]; -- combiningTableTop=indexes[_NORM_INDEX_COMBINE_DATA_COUNT] 197*0e209d39SAndroid Build Coastguard Worker * combiningTableTop may include one 16-bit padding unit 198*0e209d39SAndroid Build Coastguard Worker * to make sure that fcdTrie is 32-bit-aligned 199*0e209d39SAndroid Build Coastguard Worker * 200*0e209d39SAndroid Build Coastguard Worker * UTrie fcdTrie; -- size in bytes=indexes[_NORM_INDEX_FCD_TRIE_SIZE] 201*0e209d39SAndroid Build Coastguard Worker * 202*0e209d39SAndroid Build Coastguard Worker * UTrie auxTrie; -- size in bytes=indexes[_NORM_INDEX_AUX_TRIE_SIZE] 203*0e209d39SAndroid Build Coastguard Worker * 204*0e209d39SAndroid Build Coastguard Worker * uint16_t canonStartSets[canonStartSetsTop] -- canonStartSetsTop=indexes[_NORM_INDEX_CANON_SET_COUNT] 205*0e209d39SAndroid Build Coastguard Worker * serialized USets and binary search tables, see below 206*0e209d39SAndroid Build Coastguard Worker * 207*0e209d39SAndroid Build Coastguard Worker * 208*0e209d39SAndroid Build Coastguard Worker * The indexes array contains lengths and sizes of the following arrays and structures 209*0e209d39SAndroid Build Coastguard Worker * as well as the following values: 210*0e209d39SAndroid Build Coastguard Worker * indexes[_NORM_INDEX_COMBINE_FWD_COUNT]=combineFwdTop 211*0e209d39SAndroid Build Coastguard Worker * -- one more than the highest combining index computed for forward-only-combining characters 212*0e209d39SAndroid Build Coastguard Worker * indexes[_NORM_INDEX_COMBINE_BOTH_COUNT]=combineBothTop-combineFwdTop 213*0e209d39SAndroid Build Coastguard Worker * -- number of combining indexes computed for both-ways-combining characters 214*0e209d39SAndroid Build Coastguard Worker * indexes[_NORM_INDEX_COMBINE_BACK_COUNT]=combineBackTop-combineBothTop 215*0e209d39SAndroid Build Coastguard Worker * -- number of combining indexes computed for backward-only-combining characters 216*0e209d39SAndroid Build Coastguard Worker * 217*0e209d39SAndroid Build Coastguard Worker * indexes[_NORM_INDEX_MIN_NF*_NO_MAYBE] (where *={ C, D, KC, KD }) 218*0e209d39SAndroid Build Coastguard Worker * -- first code point with a quick check NF* value of NO/MAYBE 219*0e209d39SAndroid Build Coastguard Worker * 220*0e209d39SAndroid Build Coastguard Worker * 221*0e209d39SAndroid Build Coastguard Worker * - Tries 222*0e209d39SAndroid Build Coastguard Worker * 223*0e209d39SAndroid Build Coastguard Worker * The main structures are two UTrie tables ("compact arrays"), 224*0e209d39SAndroid Build Coastguard Worker * each with one index array and one data array. 225*0e209d39SAndroid Build Coastguard Worker * See utrie.h and utrie.c. 226*0e209d39SAndroid Build Coastguard Worker * 227*0e209d39SAndroid Build Coastguard Worker * 228*0e209d39SAndroid Build Coastguard Worker * - Tries in unorm.dat 229*0e209d39SAndroid Build Coastguard Worker * 230*0e209d39SAndroid Build Coastguard Worker * The first trie (normTrie above) 231*0e209d39SAndroid Build Coastguard Worker * provides data for the NF* quick checks and normalization. 232*0e209d39SAndroid Build Coastguard Worker * The second trie (fcdTrie above) provides data just for FCD checks. 233*0e209d39SAndroid Build Coastguard Worker * 234*0e209d39SAndroid Build Coastguard Worker * 235*0e209d39SAndroid Build Coastguard Worker * - norm32 data words from the first trie 236*0e209d39SAndroid Build Coastguard Worker * 237*0e209d39SAndroid Build Coastguard Worker * The norm32Table contains one 32-bit word "norm32" per code point. 238*0e209d39SAndroid Build Coastguard Worker * It contains the following bit fields: 239*0e209d39SAndroid Build Coastguard Worker * 31..16 extra data index, _NORM_EXTRA_SHIFT is used to shift this field down 240*0e209d39SAndroid Build Coastguard Worker * if this index is <_NORM_EXTRA_INDEX_TOP then it is an index into 241*0e209d39SAndroid Build Coastguard Worker * extraData[] where variable-length normalization data for this 242*0e209d39SAndroid Build Coastguard Worker * code point is found 243*0e209d39SAndroid Build Coastguard Worker * if this index is <_NORM_EXTRA_INDEX_TOP+_NORM_EXTRA_SURROGATE_TOP 244*0e209d39SAndroid Build Coastguard Worker * then this is a norm32 for a leading surrogate, and the index 245*0e209d39SAndroid Build Coastguard Worker * value is used together with the following trailing surrogate 246*0e209d39SAndroid Build Coastguard Worker * code unit in the second trie access 247*0e209d39SAndroid Build Coastguard Worker * if this index is >=_NORM_EXTRA_INDEX_TOP+_NORM_EXTRA_SURROGATE_TOP 248*0e209d39SAndroid Build Coastguard Worker * then this is a norm32 for a "special" character, 249*0e209d39SAndroid Build Coastguard Worker * i.e., the character is a Hangul syllable or a Jamo 250*0e209d39SAndroid Build Coastguard Worker * see _NORM_EXTRA_HANGUL etc. 251*0e209d39SAndroid Build Coastguard Worker * generally, instead of extracting this index from the norm32 and 252*0e209d39SAndroid Build Coastguard Worker * comparing it with the above constants, 253*0e209d39SAndroid Build Coastguard Worker * the normalization code compares the entire norm32 value 254*0e209d39SAndroid Build Coastguard Worker * with _NORM_MIN_SPECIAL, _NORM_SURROGATES_TOP, _NORM_MIN_HANGUL etc. 255*0e209d39SAndroid Build Coastguard Worker * 256*0e209d39SAndroid Build Coastguard Worker * 15..8 combining class (cc) according to UnicodeData.txt 257*0e209d39SAndroid Build Coastguard Worker * 258*0e209d39SAndroid Build Coastguard Worker * 7..6 _NORM_COMBINES_ANY flags, used in composition to see if a character 259*0e209d39SAndroid Build Coastguard Worker * combines with any following or preceding character(s) 260*0e209d39SAndroid Build Coastguard Worker * at all 261*0e209d39SAndroid Build Coastguard Worker * 7 _NORM_COMBINES_BACK 262*0e209d39SAndroid Build Coastguard Worker * 6 _NORM_COMBINES_FWD 263*0e209d39SAndroid Build Coastguard Worker * 264*0e209d39SAndroid Build Coastguard Worker * 5..0 quick check flags, set for "no" or "maybe", with separate flags for 265*0e209d39SAndroid Build Coastguard Worker * each normalization form 266*0e209d39SAndroid Build Coastguard Worker * the higher bits are "maybe" flags; for NF*D there are no such flags 267*0e209d39SAndroid Build Coastguard Worker * the lower bits are "no" flags for all forms, in the same order 268*0e209d39SAndroid Build Coastguard Worker * as the "maybe" flags, 269*0e209d39SAndroid Build Coastguard Worker * which is (MSB to LSB): NFKD NFD NFKC NFC 270*0e209d39SAndroid Build Coastguard Worker * 5..4 _NORM_QC_ANY_MAYBE 271*0e209d39SAndroid Build Coastguard Worker * 3..0 _NORM_QC_ANY_NO 272*0e209d39SAndroid Build Coastguard Worker * see further related constants 273*0e209d39SAndroid Build Coastguard Worker * 274*0e209d39SAndroid Build Coastguard Worker * 275*0e209d39SAndroid Build Coastguard Worker * - Extra data per code point 276*0e209d39SAndroid Build Coastguard Worker * 277*0e209d39SAndroid Build Coastguard Worker * "Extra data" is referenced by the index in norm32. 278*0e209d39SAndroid Build Coastguard Worker * It is variable-length data. It is only present, and only those parts 279*0e209d39SAndroid Build Coastguard Worker * of it are, as needed for a given character. 280*0e209d39SAndroid Build Coastguard Worker * The norm32 extra data index is added to the beginning of extraData[] 281*0e209d39SAndroid Build Coastguard Worker * to get to a vector of 16-bit words with data at the following offsets: 282*0e209d39SAndroid Build Coastguard Worker * 283*0e209d39SAndroid Build Coastguard Worker * [-1] Combining index for composition. 284*0e209d39SAndroid Build Coastguard Worker * Stored only if norm32&_NORM_COMBINES_ANY . 285*0e209d39SAndroid Build Coastguard Worker * [0] Lengths of the canonical and compatibility decomposition strings. 286*0e209d39SAndroid Build Coastguard Worker * Stored only if there are decompositions, i.e., 287*0e209d39SAndroid Build Coastguard Worker * if norm32&(_NORM_QC_NFD|_NORM_QC_NFKD) 288*0e209d39SAndroid Build Coastguard Worker * High byte: length of NFKD, or 0 if none 289*0e209d39SAndroid Build Coastguard Worker * Low byte: length of NFD, or 0 if none 290*0e209d39SAndroid Build Coastguard Worker * Each length byte also has another flag: 291*0e209d39SAndroid Build Coastguard Worker * Bit 7 of a length byte is set if there are non-zero 292*0e209d39SAndroid Build Coastguard Worker * combining classes (cc's) associated with the respective 293*0e209d39SAndroid Build Coastguard Worker * decomposition. If this flag is set, then the decomposition 294*0e209d39SAndroid Build Coastguard Worker * is preceded by a 16-bit word that contains the 295*0e209d39SAndroid Build Coastguard Worker * leading and trailing cc's. 296*0e209d39SAndroid Build Coastguard Worker * Bits 6..0 of a length byte are the length of the 297*0e209d39SAndroid Build Coastguard Worker * decomposition string, not counting the cc word. 298*0e209d39SAndroid Build Coastguard Worker * [1..n] NFD 299*0e209d39SAndroid Build Coastguard Worker * [n+1..] NFKD 300*0e209d39SAndroid Build Coastguard Worker * 301*0e209d39SAndroid Build Coastguard Worker * Each of the two decompositions consists of up to two parts: 302*0e209d39SAndroid Build Coastguard Worker * - The 16-bit words with the leading and trailing cc's. 303*0e209d39SAndroid Build Coastguard Worker * This is only stored if bit 7 of the corresponding length byte 304*0e209d39SAndroid Build Coastguard Worker * is set. In this case, at least one of the cc's is not zero. 305*0e209d39SAndroid Build Coastguard Worker * High byte: leading cc==cc of the first code point in the decomposition string 306*0e209d39SAndroid Build Coastguard Worker * Low byte: trailing cc==cc of the last code point in the decomposition string 307*0e209d39SAndroid Build Coastguard Worker * - The decomposition string in UTF-16, with length code units. 308*0e209d39SAndroid Build Coastguard Worker * 309*0e209d39SAndroid Build Coastguard Worker * 310*0e209d39SAndroid Build Coastguard Worker * - Combining indexes and combiningTable[] 311*0e209d39SAndroid Build Coastguard Worker * 312*0e209d39SAndroid Build Coastguard Worker * Combining indexes are stored at the [-1] offset of the extra data 313*0e209d39SAndroid Build Coastguard Worker * if the character combines forward or backward with any other characters. 314*0e209d39SAndroid Build Coastguard Worker * They are used for (re)composition in NF*C. 315*0e209d39SAndroid Build Coastguard Worker * Values of combining indexes are arranged according to whether a character 316*0e209d39SAndroid Build Coastguard Worker * combines forward, backward, or both ways: 317*0e209d39SAndroid Build Coastguard Worker * forward-only < both ways < backward-only 318*0e209d39SAndroid Build Coastguard Worker * 319*0e209d39SAndroid Build Coastguard Worker * The index values for forward-only and both-ways combining characters 320*0e209d39SAndroid Build Coastguard Worker * are indexes into the combiningTable[]. 321*0e209d39SAndroid Build Coastguard Worker * The index values for backward-only combining characters are simply 322*0e209d39SAndroid Build Coastguard Worker * incremented from the preceding index values to be unique. 323*0e209d39SAndroid Build Coastguard Worker * 324*0e209d39SAndroid Build Coastguard Worker * In the combiningTable[], a variable-length list 325*0e209d39SAndroid Build Coastguard Worker * of variable-length (back-index, code point) pair entries is stored 326*0e209d39SAndroid Build Coastguard Worker * for each forward-combining character. 327*0e209d39SAndroid Build Coastguard Worker * 328*0e209d39SAndroid Build Coastguard Worker * These back-indexes are the combining indexes of both-ways or backward-only 329*0e209d39SAndroid Build Coastguard Worker * combining characters that the forward-combining character combines with. 330*0e209d39SAndroid Build Coastguard Worker * 331*0e209d39SAndroid Build Coastguard Worker * Each list is sorted in ascending order of back-indexes. 332*0e209d39SAndroid Build Coastguard Worker * Each list is terminated with the last back-index having bit 15 set. 333*0e209d39SAndroid Build Coastguard Worker * 334*0e209d39SAndroid Build Coastguard Worker * Each pair (back-index, code point) takes up either 2 or 3 335*0e209d39SAndroid Build Coastguard Worker * 16-bit words. 336*0e209d39SAndroid Build Coastguard Worker * The first word of a list entry is the back-index, with its bit 15 set if 337*0e209d39SAndroid Build Coastguard Worker * this is the last pair in the list. 338*0e209d39SAndroid Build Coastguard Worker * 339*0e209d39SAndroid Build Coastguard Worker * The second word contains flags in bits 15..13 that determine 340*0e209d39SAndroid Build Coastguard Worker * if there is a third word and how the combined character is encoded: 341*0e209d39SAndroid Build Coastguard Worker * 15 set if there is a third word in this list entry 342*0e209d39SAndroid Build Coastguard Worker * 14 set if the result is a supplementary character 343*0e209d39SAndroid Build Coastguard Worker * 13 set if the result itself combines forward 344*0e209d39SAndroid Build Coastguard Worker * 345*0e209d39SAndroid Build Coastguard Worker * According to these bits 15..14 of the second word, 346*0e209d39SAndroid Build Coastguard Worker * the result character is encoded as follows: 347*0e209d39SAndroid Build Coastguard Worker * 00 or 01 The result is <=0x1fff and stored in bits 12..0 of 348*0e209d39SAndroid Build Coastguard Worker * the second word. 349*0e209d39SAndroid Build Coastguard Worker * 10 The result is 0x2000..0xffff and stored in the third word. 350*0e209d39SAndroid Build Coastguard Worker * Bits 12..0 of the second word are not used. 351*0e209d39SAndroid Build Coastguard Worker * 11 The result is a supplementary character. 352*0e209d39SAndroid Build Coastguard Worker * Bits 9..0 of the leading surrogate are in bits 9..0 of 353*0e209d39SAndroid Build Coastguard Worker * the second word. 354*0e209d39SAndroid Build Coastguard Worker * Add 0xd800 to these bits to get the complete surrogate. 355*0e209d39SAndroid Build Coastguard Worker * Bits 12..10 of the second word are not used. 356*0e209d39SAndroid Build Coastguard Worker * The trailing surrogate is stored in the third word. 357*0e209d39SAndroid Build Coastguard Worker * 358*0e209d39SAndroid Build Coastguard Worker * 359*0e209d39SAndroid Build Coastguard Worker * - FCD trie 360*0e209d39SAndroid Build Coastguard Worker * 361*0e209d39SAndroid Build Coastguard Worker * The FCD trie is very simple. 362*0e209d39SAndroid Build Coastguard Worker * It is a folded trie with 16-bit data words. 363*0e209d39SAndroid Build Coastguard Worker * In each word, the high byte contains the leading cc of the character, 364*0e209d39SAndroid Build Coastguard Worker * and the low byte contains the trailing cc of the character. 365*0e209d39SAndroid Build Coastguard Worker * These cc's are the cc's of the first and last code points in the 366*0e209d39SAndroid Build Coastguard Worker * canonical decomposition of the character. 367*0e209d39SAndroid Build Coastguard Worker * 368*0e209d39SAndroid Build Coastguard Worker * Since all 16 bits are used for cc's, lead surrogates must be tested 369*0e209d39SAndroid Build Coastguard Worker * by checking the code unit instead of the trie data. 370*0e209d39SAndroid Build Coastguard Worker * This is done only if the 16-bit data word is not zero. 371*0e209d39SAndroid Build Coastguard Worker * If the code unit is a leading surrogate and the data word is not zero, 372*0e209d39SAndroid Build Coastguard Worker * then instead of cc's it contains the offset for the second trie lookup. 373*0e209d39SAndroid Build Coastguard Worker * 374*0e209d39SAndroid Build Coastguard Worker * 375*0e209d39SAndroid Build Coastguard Worker * - Auxiliary trie and data 376*0e209d39SAndroid Build Coastguard Worker * 377*0e209d39SAndroid Build Coastguard Worker * The auxiliary 16-bit trie contains data for additional properties. 378*0e209d39SAndroid Build Coastguard Worker * Bits 379*0e209d39SAndroid Build Coastguard Worker * 15..13 reserved 380*0e209d39SAndroid Build Coastguard Worker * 12 not NFC_Skippable (f) (formatVersion>=2.2) 381*0e209d39SAndroid Build Coastguard Worker * 11 flag: not a safe starter for canonical closure 382*0e209d39SAndroid Build Coastguard Worker * 10 composition exclusion 383*0e209d39SAndroid Build Coastguard Worker * 9.. 0 index into extraData[] to FC_NFKC_Closure string 384*0e209d39SAndroid Build Coastguard Worker * (not for lead surrogate), 385*0e209d39SAndroid Build Coastguard Worker * or lead surrogate offset (for lead surrogate, if 9..0 not zero) 386*0e209d39SAndroid Build Coastguard Worker * 387*0e209d39SAndroid Build Coastguard Worker * - FC_NFKC_Closure strings in extraData[] 388*0e209d39SAndroid Build Coastguard Worker * 389*0e209d39SAndroid Build Coastguard Worker * Strings are either stored as a single code unit or as the length 390*0e209d39SAndroid Build Coastguard Worker * followed by that many units. 391*0e209d39SAndroid Build Coastguard Worker * const char16_t *s=extraData+(index from auxTrie data bits 9..0); 392*0e209d39SAndroid Build Coastguard Worker * int32_t length; 393*0e209d39SAndroid Build Coastguard Worker * if(*s<0xff00) { 394*0e209d39SAndroid Build Coastguard Worker * // s points to the single-unit string 395*0e209d39SAndroid Build Coastguard Worker * length=1; 396*0e209d39SAndroid Build Coastguard Worker * } else { 397*0e209d39SAndroid Build Coastguard Worker * length=*s&0xff; 398*0e209d39SAndroid Build Coastguard Worker * ++s; 399*0e209d39SAndroid Build Coastguard Worker * } 400*0e209d39SAndroid Build Coastguard Worker * 401*0e209d39SAndroid Build Coastguard Worker * Conditions for "NF* Skippable" from Mark Davis' com.ibm.text.UCD.NFSkippable: 402*0e209d39SAndroid Build Coastguard Worker * (used in NormalizerTransliterator) 403*0e209d39SAndroid Build Coastguard Worker * 404*0e209d39SAndroid Build Coastguard Worker * A skippable character is 405*0e209d39SAndroid Build Coastguard Worker * a) unassigned, or ALL of the following: 406*0e209d39SAndroid Build Coastguard Worker * b) of combining class 0. 407*0e209d39SAndroid Build Coastguard Worker * c) not decomposed by this normalization form. 408*0e209d39SAndroid Build Coastguard Worker * AND if NFC or NFKC, 409*0e209d39SAndroid Build Coastguard Worker * d) can never compose with a previous character. 410*0e209d39SAndroid Build Coastguard Worker * e) can never compose with a following character. 411*0e209d39SAndroid Build Coastguard Worker * f) can never change if another character is added. 412*0e209d39SAndroid Build Coastguard Worker * Example: a-breve might satisfy all but f, but if you 413*0e209d39SAndroid Build Coastguard Worker * add an ogonek it changes to a-ogonek + breve 414*0e209d39SAndroid Build Coastguard Worker * 415*0e209d39SAndroid Build Coastguard Worker * a)..e) must be tested from norm32. 416*0e209d39SAndroid Build Coastguard Worker * Since f) is more complicated, the (not-)NFC_Skippable flag (f) is built 417*0e209d39SAndroid Build Coastguard Worker * into the auxiliary trie. 418*0e209d39SAndroid Build Coastguard Worker * The same bit is used for NFC and NFKC; (c) differs for them. 419*0e209d39SAndroid Build Coastguard Worker * As usual, we build the "not skippable" flags so that unassigned 420*0e209d39SAndroid Build Coastguard Worker * code points get a 0 bit. 421*0e209d39SAndroid Build Coastguard Worker * This bit is only valid after (a)..(e) test false; test NFD_NO before (f) as well. 422*0e209d39SAndroid Build Coastguard Worker * Test Hangul LV syllables entirely in code. 423*0e209d39SAndroid Build Coastguard Worker * 424*0e209d39SAndroid Build Coastguard Worker * 425*0e209d39SAndroid Build Coastguard Worker * - structure inside canonStartSets[] 426*0e209d39SAndroid Build Coastguard Worker * 427*0e209d39SAndroid Build Coastguard Worker * This array maps from code points c to sets of code points (USerializedSet). 428*0e209d39SAndroid Build Coastguard Worker * The result sets are the code points whose canonical decompositions start 429*0e209d39SAndroid Build Coastguard Worker * with c. 430*0e209d39SAndroid Build Coastguard Worker * 431*0e209d39SAndroid Build Coastguard Worker * canonStartSets[] contains the following sub-arrays: 432*0e209d39SAndroid Build Coastguard Worker * 433*0e209d39SAndroid Build Coastguard Worker * indexes[_NORM_SET_INDEX_TOP] 434*0e209d39SAndroid Build Coastguard Worker * - contains lengths of sub-arrays etc. 435*0e209d39SAndroid Build Coastguard Worker * 436*0e209d39SAndroid Build Coastguard Worker * startSets[indexes[_NORM_SET_INDEX_CANON_SETS_LENGTH]-_NORM_SET_INDEX_TOP] 437*0e209d39SAndroid Build Coastguard Worker * - contains serialized sets (USerializedSet) of canonical starters for 438*0e209d39SAndroid Build Coastguard Worker * enumerating canonically equivalent strings 439*0e209d39SAndroid Build Coastguard Worker * indexes[_NORM_SET_INDEX_CANON_SETS_LENGTH] includes _NORM_SET_INDEX_TOP 440*0e209d39SAndroid Build Coastguard Worker * for details about the structure see uset.c 441*0e209d39SAndroid Build Coastguard Worker * 442*0e209d39SAndroid Build Coastguard Worker * bmpTable[indexes[_NORM_SET_INDEX_CANON_BMP_TABLE_LENGTH]] 443*0e209d39SAndroid Build Coastguard Worker * - a sorted search table for BMP code points whose results are 444*0e209d39SAndroid Build Coastguard Worker * either indexes to USerializedSets or single code points for 445*0e209d39SAndroid Build Coastguard Worker * single-code point sets; 446*0e209d39SAndroid Build Coastguard Worker * each entry is a pair of { code point, result } with result=(binary) yy xxxxxx xxxxxxxx 447*0e209d39SAndroid Build Coastguard Worker * if yy==01 then there is a USerializedSet at canonStartSets+x 448*0e209d39SAndroid Build Coastguard Worker * else build a USerializedSet with result as the single code point 449*0e209d39SAndroid Build Coastguard Worker * 450*0e209d39SAndroid Build Coastguard Worker * suppTable[indexes[_NORM_SET_INDEX_CANON_SUPP_TABLE_LENGTH]] 451*0e209d39SAndroid Build Coastguard Worker * - a sorted search table for supplementary code points whose results are 452*0e209d39SAndroid Build Coastguard Worker * either indexes to USerializedSets or single code points for 453*0e209d39SAndroid Build Coastguard Worker * single-code point sets; 454*0e209d39SAndroid Build Coastguard Worker * each entry is a triplet of { high16(cp), low16(cp), result } 455*0e209d39SAndroid Build Coastguard Worker * each code point's high-word may contain extra data in bits 15..5: 456*0e209d39SAndroid Build Coastguard Worker * if the high word has bit 15 set, then build a set with a single code point 457*0e209d39SAndroid Build Coastguard Worker * which is (((high16(cp)&0x1f00)<<8)|result; 458*0e209d39SAndroid Build Coastguard Worker * else there is a USerializedSet at canonStartSets+result 459*0e209d39SAndroid Build Coastguard Worker * 460*0e209d39SAndroid Build Coastguard Worker * FormatVersion 2.3 adds 2 serialized sets for normalization exclusions. 461*0e209d39SAndroid Build Coastguard Worker * They are stored in the data file so that the runtime normalization code need 462*0e209d39SAndroid Build Coastguard Worker * not depend on other properties and their data and implementation files. 463*0e209d39SAndroid Build Coastguard Worker * The _NORM_SET_INDEX_NX_..._OFFSET offsets in the canonStartSets index table 464*0e209d39SAndroid Build Coastguard Worker * give the location for each set. 465*0e209d39SAndroid Build Coastguard Worker * There is no set stored for UNORM_NX_HANGUL because it's trivial to create 466*0e209d39SAndroid Build Coastguard Worker * without using properties. 467*0e209d39SAndroid Build Coastguard Worker * 468*0e209d39SAndroid Build Coastguard Worker * Set contents: 469*0e209d39SAndroid Build Coastguard Worker * 470*0e209d39SAndroid Build Coastguard Worker * _NORM_SET_INDEX_NX_CJK_COMPAT_OFFSET (for UNORM_NX_CJK_COMPAT) 471*0e209d39SAndroid Build Coastguard Worker * [[:Ideographic:]&[:NFD_QC=No:]] 472*0e209d39SAndroid Build Coastguard Worker * =[CJK Ideographs]&[has canonical decomposition] 473*0e209d39SAndroid Build Coastguard Worker * 474*0e209d39SAndroid Build Coastguard Worker * _NORM_SET_INDEX_NX_UNICODE32_OFFSET (for UNORM_UNICODE_3_2) 475*0e209d39SAndroid Build Coastguard Worker * [:^Age=3.2:] 476*0e209d39SAndroid Build Coastguard Worker * =set with all code points that were not designated by the specified Unicode version 477*0e209d39SAndroid Build Coastguard Worker * 478*0e209d39SAndroid Build Coastguard Worker * _NORM_SET_INDEX_NX_RESERVED_OFFSET 479*0e209d39SAndroid Build Coastguard Worker * This is an offset that points to where the next, future set would start. 480*0e209d39SAndroid Build Coastguard Worker * Currently it indicates where the previous set ends, and thus its length. 481*0e209d39SAndroid Build Coastguard Worker * The name for this enum constant may in the future be applied to different 482*0e209d39SAndroid Build Coastguard Worker * index slots. In order to get the limit of a set, use its index slot and 483*0e209d39SAndroid Build Coastguard Worker * the immediately following one regardless of that one's enum name. 484*0e209d39SAndroid Build Coastguard Worker */ 485*0e209d39SAndroid Build Coastguard Worker 486*0e209d39SAndroid Build Coastguard Worker #endif /* #if !UCONFIG_NO_NORMALIZATION */ 487*0e209d39SAndroid Build Coastguard Worker 488*0e209d39SAndroid Build Coastguard Worker #endif 489