11cb0ef41Sopenharmony_ci// © 2016 and later: Unicode, Inc. and others. 21cb0ef41Sopenharmony_ci// License & terms of use: http://www.unicode.org/copyright.html 31cb0ef41Sopenharmony_ci/* 41cb0ef41Sopenharmony_ci******************************************************************************* 51cb0ef41Sopenharmony_ci* 61cb0ef41Sopenharmony_ci* Copyright (C) 2001-2011, International Business Machines 71cb0ef41Sopenharmony_ci* Corporation and others. All Rights Reserved. 81cb0ef41Sopenharmony_ci* 91cb0ef41Sopenharmony_ci******************************************************************************* 101cb0ef41Sopenharmony_ci* file name: unormimp.h 111cb0ef41Sopenharmony_ci* encoding: UTF-8 121cb0ef41Sopenharmony_ci* tab size: 8 (not used) 131cb0ef41Sopenharmony_ci* indentation:4 141cb0ef41Sopenharmony_ci* 151cb0ef41Sopenharmony_ci* created on: 2001may25 161cb0ef41Sopenharmony_ci* created by: Markus W. Scherer 171cb0ef41Sopenharmony_ci*/ 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci#ifndef __UNORMIMP_H__ 201cb0ef41Sopenharmony_ci#define __UNORMIMP_H__ 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci#include "unicode/utypes.h" 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci#if !UCONFIG_NO_NORMALIZATION 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci#include "udataswp.h" 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci/* 291cb0ef41Sopenharmony_ci * The 2001-2010 implementation of the normalization code loads its data from 301cb0ef41Sopenharmony_ci * unorm.icu, which is generated with the gennorm tool. 311cb0ef41Sopenharmony_ci * The format of that file is described at the end of this file. 321cb0ef41Sopenharmony_ci */ 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci/* norm32 value constants */ 351cb0ef41Sopenharmony_cienum { 361cb0ef41Sopenharmony_ci /* quick check flags 0..3 set mean "no" for their forms */ 371cb0ef41Sopenharmony_ci _NORM_QC_NFC=0x11, /* no|maybe */ 381cb0ef41Sopenharmony_ci _NORM_QC_NFKC=0x22, /* no|maybe */ 391cb0ef41Sopenharmony_ci _NORM_QC_NFD=4, /* no */ 401cb0ef41Sopenharmony_ci _NORM_QC_NFKD=8, /* no */ 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci _NORM_QC_ANY_NO=0xf, 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci /* quick check flags 4..5 mean "maybe" for their forms; test flags>=_NORM_QC_MAYBE */ 451cb0ef41Sopenharmony_ci _NORM_QC_MAYBE=0x10, 461cb0ef41Sopenharmony_ci _NORM_QC_ANY_MAYBE=0x30, 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci _NORM_QC_MASK=0x3f, 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci _NORM_COMBINES_FWD=0x40, 511cb0ef41Sopenharmony_ci _NORM_COMBINES_BACK=0x80, 521cb0ef41Sopenharmony_ci _NORM_COMBINES_ANY=0xc0, 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci _NORM_CC_SHIFT=8, /* UnicodeData.txt combining class in bits 15..8 */ 551cb0ef41Sopenharmony_ci _NORM_CC_MASK=0xff00, 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ci _NORM_EXTRA_SHIFT=16, /* 16 bits for the index to UChars and other extra data */ 581cb0ef41Sopenharmony_ci _NORM_EXTRA_INDEX_TOP=0xfc00, /* start of surrogate specials after shift */ 591cb0ef41Sopenharmony_ci 601cb0ef41Sopenharmony_ci _NORM_EXTRA_SURROGATE_MASK=0x3ff, 611cb0ef41Sopenharmony_ci _NORM_EXTRA_SURROGATE_TOP=0x3f0, /* hangul etc. */ 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ci _NORM_EXTRA_HANGUL=_NORM_EXTRA_SURROGATE_TOP, 641cb0ef41Sopenharmony_ci _NORM_EXTRA_JAMO_L, 651cb0ef41Sopenharmony_ci _NORM_EXTRA_JAMO_V, 661cb0ef41Sopenharmony_ci _NORM_EXTRA_JAMO_T 671cb0ef41Sopenharmony_ci}; 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_ci/* norm32 value constants using >16 bits */ 701cb0ef41Sopenharmony_ci#define _NORM_MIN_SPECIAL 0xfc000000 711cb0ef41Sopenharmony_ci#define _NORM_SURROGATES_TOP 0xfff00000 721cb0ef41Sopenharmony_ci#define _NORM_MIN_HANGUL 0xfff00000 731cb0ef41Sopenharmony_ci#define _NORM_MIN_JAMO_V 0xfff20000 741cb0ef41Sopenharmony_ci#define _NORM_JAMO_V_TOP 0xfff30000 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_ci/* value constants for auxTrie */ 771cb0ef41Sopenharmony_cienum { 781cb0ef41Sopenharmony_ci _NORM_AUX_COMP_EX_SHIFT=10, 791cb0ef41Sopenharmony_ci _NORM_AUX_UNSAFE_SHIFT=11, 801cb0ef41Sopenharmony_ci _NORM_AUX_NFC_SKIPPABLE_F_SHIFT=12 811cb0ef41Sopenharmony_ci}; 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_ci#define _NORM_AUX_MAX_FNC ((int32_t)1<<_NORM_AUX_COMP_EX_SHIFT) 841cb0ef41Sopenharmony_ci 851cb0ef41Sopenharmony_ci#define _NORM_AUX_FNC_MASK (uint32_t)(_NORM_AUX_MAX_FNC-1) 861cb0ef41Sopenharmony_ci#define _NORM_AUX_COMP_EX_MASK ((uint32_t)1<<_NORM_AUX_COMP_EX_SHIFT) 871cb0ef41Sopenharmony_ci#define _NORM_AUX_UNSAFE_MASK ((uint32_t)1<<_NORM_AUX_UNSAFE_SHIFT) 881cb0ef41Sopenharmony_ci#define _NORM_AUX_NFC_SKIP_F_MASK ((uint32_t)1<<_NORM_AUX_NFC_SKIPPABLE_F_SHIFT) 891cb0ef41Sopenharmony_ci 901cb0ef41Sopenharmony_ci/* canonStartSets[0..31] contains indexes for what is in the array */ 911cb0ef41Sopenharmony_cienum { 921cb0ef41Sopenharmony_ci _NORM_SET_INDEX_CANON_SETS_LENGTH, /* number of uint16_t in canonical starter sets */ 931cb0ef41Sopenharmony_ci _NORM_SET_INDEX_CANON_BMP_TABLE_LENGTH, /* number of uint16_t in the BMP search table (contains pairs) */ 941cb0ef41Sopenharmony_ci _NORM_SET_INDEX_CANON_SUPP_TABLE_LENGTH,/* number of uint16_t in the supplementary search table (contains triplets) */ 951cb0ef41Sopenharmony_ci 961cb0ef41Sopenharmony_ci /* from formatVersion 2.3: */ 971cb0ef41Sopenharmony_ci _NORM_SET_INDEX_NX_CJK_COMPAT_OFFSET, /* uint16_t offset from canonStartSets[0] to the 981cb0ef41Sopenharmony_ci exclusion set for CJK compatibility characters */ 991cb0ef41Sopenharmony_ci _NORM_SET_INDEX_NX_UNICODE32_OFFSET, /* uint16_t offset from canonStartSets[0] to the 1001cb0ef41Sopenharmony_ci exclusion set for Unicode 3.2 characters */ 1011cb0ef41Sopenharmony_ci _NORM_SET_INDEX_NX_RESERVED_OFFSET, /* uint16_t offset from canonStartSets[0] to the 1021cb0ef41Sopenharmony_ci end of the previous exclusion set */ 1031cb0ef41Sopenharmony_ci 1041cb0ef41Sopenharmony_ci _NORM_SET_INDEX_TOP=32 /* changing this requires a new formatVersion */ 1051cb0ef41Sopenharmony_ci}; 1061cb0ef41Sopenharmony_ci 1071cb0ef41Sopenharmony_ci/* more constants for canonical starter sets */ 1081cb0ef41Sopenharmony_ci 1091cb0ef41Sopenharmony_ci/* 14 bit indexes to canonical USerializedSets */ 1101cb0ef41Sopenharmony_ci#define _NORM_MAX_CANON_SETS 0x4000 1111cb0ef41Sopenharmony_ci 1121cb0ef41Sopenharmony_ci/* single-code point BMP sets are encoded directly in the search table except if result=0x4000..0x7fff */ 1131cb0ef41Sopenharmony_ci#define _NORM_CANON_SET_BMP_MASK 0xc000 1141cb0ef41Sopenharmony_ci#define _NORM_CANON_SET_BMP_IS_INDEX 0x4000 1151cb0ef41Sopenharmony_ci 1161cb0ef41Sopenharmony_ci/* indexes[] value names */ 1171cb0ef41Sopenharmony_cienum { 1181cb0ef41Sopenharmony_ci _NORM_INDEX_TRIE_SIZE, /* number of bytes in normalization trie */ 1191cb0ef41Sopenharmony_ci _NORM_INDEX_UCHAR_COUNT, /* number of UChars in extra data */ 1201cb0ef41Sopenharmony_ci 1211cb0ef41Sopenharmony_ci _NORM_INDEX_COMBINE_DATA_COUNT, /* number of uint16_t words for combining data */ 1221cb0ef41Sopenharmony_ci _NORM_INDEX_COMBINE_FWD_COUNT, /* number of code points that combine forward */ 1231cb0ef41Sopenharmony_ci _NORM_INDEX_COMBINE_BOTH_COUNT, /* number of code points that combine forward and backward */ 1241cb0ef41Sopenharmony_ci _NORM_INDEX_COMBINE_BACK_COUNT, /* number of code points that combine backward */ 1251cb0ef41Sopenharmony_ci 1261cb0ef41Sopenharmony_ci _NORM_INDEX_MIN_NFC_NO_MAYBE, /* first code point with quick check NFC NO/MAYBE */ 1271cb0ef41Sopenharmony_ci _NORM_INDEX_MIN_NFKC_NO_MAYBE, /* first code point with quick check NFKC NO/MAYBE */ 1281cb0ef41Sopenharmony_ci _NORM_INDEX_MIN_NFD_NO_MAYBE, /* first code point with quick check NFD NO/MAYBE */ 1291cb0ef41Sopenharmony_ci _NORM_INDEX_MIN_NFKD_NO_MAYBE, /* first code point with quick check NFKD NO/MAYBE */ 1301cb0ef41Sopenharmony_ci 1311cb0ef41Sopenharmony_ci _NORM_INDEX_FCD_TRIE_SIZE, /* number of bytes in FCD trie */ 1321cb0ef41Sopenharmony_ci 1331cb0ef41Sopenharmony_ci _NORM_INDEX_AUX_TRIE_SIZE, /* number of bytes in the auxiliary trie */ 1341cb0ef41Sopenharmony_ci _NORM_INDEX_CANON_SET_COUNT, /* number of uint16_t in the array of serialized USet */ 1351cb0ef41Sopenharmony_ci 1361cb0ef41Sopenharmony_ci _NORM_INDEX_TOP=32 /* changing this requires a new formatVersion */ 1371cb0ef41Sopenharmony_ci}; 1381cb0ef41Sopenharmony_ci 1391cb0ef41Sopenharmony_cienum { 1401cb0ef41Sopenharmony_ci /* FCD check: everything below this code point is known to have a 0 lead combining class */ 1411cb0ef41Sopenharmony_ci _NORM_MIN_WITH_LEAD_CC=0x300 1421cb0ef41Sopenharmony_ci}; 1431cb0ef41Sopenharmony_ci 1441cb0ef41Sopenharmony_cienum { 1451cb0ef41Sopenharmony_ci /** 1461cb0ef41Sopenharmony_ci * Bit 7 of the length byte for a decomposition string in extra data is 1471cb0ef41Sopenharmony_ci * a flag indicating whether the decomposition string is 1481cb0ef41Sopenharmony_ci * preceded by a 16-bit word with the leading and trailing cc 1491cb0ef41Sopenharmony_ci * of the decomposition (like for A-umlaut); 1501cb0ef41Sopenharmony_ci * if not, then both cc's are zero (like for compatibility ideographs). 1511cb0ef41Sopenharmony_ci */ 1521cb0ef41Sopenharmony_ci _NORM_DECOMP_FLAG_LENGTH_HAS_CC=0x80, 1531cb0ef41Sopenharmony_ci /** 1541cb0ef41Sopenharmony_ci * Bits 6..0 of the length byte contain the actual length. 1551cb0ef41Sopenharmony_ci */ 1561cb0ef41Sopenharmony_ci _NORM_DECOMP_LENGTH_MASK=0x7f 1571cb0ef41Sopenharmony_ci}; 1581cb0ef41Sopenharmony_ci 1591cb0ef41Sopenharmony_ci/** Constants for options flags for normalization. */ 1601cb0ef41Sopenharmony_cienum { 1611cb0ef41Sopenharmony_ci /** Options bit 0, do not decompose Hangul syllables. */ 1621cb0ef41Sopenharmony_ci UNORM_NX_HANGUL=1, 1631cb0ef41Sopenharmony_ci /** Options bit 1, do not decompose CJK compatibility characters. */ 1641cb0ef41Sopenharmony_ci UNORM_NX_CJK_COMPAT=2 1651cb0ef41Sopenharmony_ci}; 1661cb0ef41Sopenharmony_ci 1671cb0ef41Sopenharmony_ci/** 1681cb0ef41Sopenharmony_ci * Description of the format of unorm.icu version 2.3. 1691cb0ef41Sopenharmony_ci * 1701cb0ef41Sopenharmony_ci * Main change from version 1 to version 2: 1711cb0ef41Sopenharmony_ci * Use of new, common UTrie instead of normalization-specific tries. 1721cb0ef41Sopenharmony_ci * Change to version 2.1: add third/auxiliary trie with associated data. 1731cb0ef41Sopenharmony_ci * Change to version 2.2: add skippable (f) flag data (_NORM_AUX_NFC_SKIP_F_MASK). 1741cb0ef41Sopenharmony_ci * Change to version 2.3: add serialized sets for normalization exclusions 1751cb0ef41Sopenharmony_ci * stored inside canonStartSets[] 1761cb0ef41Sopenharmony_ci * 1771cb0ef41Sopenharmony_ci * For more details of how to use the data structures see the code 1781cb0ef41Sopenharmony_ci * in unorm.cpp (runtime normalization code) and 1791cb0ef41Sopenharmony_ci * in gennorm.c and gennorm/store.c (build-time data generation). 1801cb0ef41Sopenharmony_ci * 1811cb0ef41Sopenharmony_ci * For the serialized format of UTrie see utrie.c/UTrieHeader. 1821cb0ef41Sopenharmony_ci * 1831cb0ef41Sopenharmony_ci * - Overall partition 1841cb0ef41Sopenharmony_ci * 1851cb0ef41Sopenharmony_ci * unorm.dat customarily begins with a UDataInfo structure, see udata.h and .c. 1861cb0ef41Sopenharmony_ci * After that there are the following structures: 1871cb0ef41Sopenharmony_ci * 1881cb0ef41Sopenharmony_ci * int32_t indexes[_NORM_INDEX_TOP]; -- _NORM_INDEX_TOP=32, see enum in this file 1891cb0ef41Sopenharmony_ci * 1901cb0ef41Sopenharmony_ci * UTrie normTrie; -- size in bytes=indexes[_NORM_INDEX_TRIE_SIZE] 1911cb0ef41Sopenharmony_ci * 1921cb0ef41Sopenharmony_ci * uint16_t extraData[extraDataTop]; -- extraDataTop=indexes[_NORM_INDEX_UCHAR_COUNT] 1931cb0ef41Sopenharmony_ci * extraData[0] contains the number of units for 1941cb0ef41Sopenharmony_ci * FC_NFKC_Closure (formatVersion>=2.1) 1951cb0ef41Sopenharmony_ci * 1961cb0ef41Sopenharmony_ci * uint16_t combiningTable[combiningTableTop]; -- combiningTableTop=indexes[_NORM_INDEX_COMBINE_DATA_COUNT] 1971cb0ef41Sopenharmony_ci * combiningTableTop may include one 16-bit padding unit 1981cb0ef41Sopenharmony_ci * to make sure that fcdTrie is 32-bit-aligned 1991cb0ef41Sopenharmony_ci * 2001cb0ef41Sopenharmony_ci * UTrie fcdTrie; -- size in bytes=indexes[_NORM_INDEX_FCD_TRIE_SIZE] 2011cb0ef41Sopenharmony_ci * 2021cb0ef41Sopenharmony_ci * UTrie auxTrie; -- size in bytes=indexes[_NORM_INDEX_AUX_TRIE_SIZE] 2031cb0ef41Sopenharmony_ci * 2041cb0ef41Sopenharmony_ci * uint16_t canonStartSets[canonStartSetsTop] -- canonStartSetsTop=indexes[_NORM_INDEX_CANON_SET_COUNT] 2051cb0ef41Sopenharmony_ci * serialized USets and binary search tables, see below 2061cb0ef41Sopenharmony_ci * 2071cb0ef41Sopenharmony_ci * 2081cb0ef41Sopenharmony_ci * The indexes array contains lengths and sizes of the following arrays and structures 2091cb0ef41Sopenharmony_ci * as well as the following values: 2101cb0ef41Sopenharmony_ci * indexes[_NORM_INDEX_COMBINE_FWD_COUNT]=combineFwdTop 2111cb0ef41Sopenharmony_ci * -- one more than the highest combining index computed for forward-only-combining characters 2121cb0ef41Sopenharmony_ci * indexes[_NORM_INDEX_COMBINE_BOTH_COUNT]=combineBothTop-combineFwdTop 2131cb0ef41Sopenharmony_ci * -- number of combining indexes computed for both-ways-combining characters 2141cb0ef41Sopenharmony_ci * indexes[_NORM_INDEX_COMBINE_BACK_COUNT]=combineBackTop-combineBothTop 2151cb0ef41Sopenharmony_ci * -- number of combining indexes computed for backward-only-combining characters 2161cb0ef41Sopenharmony_ci * 2171cb0ef41Sopenharmony_ci * indexes[_NORM_INDEX_MIN_NF*_NO_MAYBE] (where *={ C, D, KC, KD }) 2181cb0ef41Sopenharmony_ci * -- first code point with a quick check NF* value of NO/MAYBE 2191cb0ef41Sopenharmony_ci * 2201cb0ef41Sopenharmony_ci * 2211cb0ef41Sopenharmony_ci * - Tries 2221cb0ef41Sopenharmony_ci * 2231cb0ef41Sopenharmony_ci * The main structures are two UTrie tables ("compact arrays"), 2241cb0ef41Sopenharmony_ci * each with one index array and one data array. 2251cb0ef41Sopenharmony_ci * See utrie.h and utrie.c. 2261cb0ef41Sopenharmony_ci * 2271cb0ef41Sopenharmony_ci * 2281cb0ef41Sopenharmony_ci * - Tries in unorm.dat 2291cb0ef41Sopenharmony_ci * 2301cb0ef41Sopenharmony_ci * The first trie (normTrie above) 2311cb0ef41Sopenharmony_ci * provides data for the NF* quick checks and normalization. 2321cb0ef41Sopenharmony_ci * The second trie (fcdTrie above) provides data just for FCD checks. 2331cb0ef41Sopenharmony_ci * 2341cb0ef41Sopenharmony_ci * 2351cb0ef41Sopenharmony_ci * - norm32 data words from the first trie 2361cb0ef41Sopenharmony_ci * 2371cb0ef41Sopenharmony_ci * The norm32Table contains one 32-bit word "norm32" per code point. 2381cb0ef41Sopenharmony_ci * It contains the following bit fields: 2391cb0ef41Sopenharmony_ci * 31..16 extra data index, _NORM_EXTRA_SHIFT is used to shift this field down 2401cb0ef41Sopenharmony_ci * if this index is <_NORM_EXTRA_INDEX_TOP then it is an index into 2411cb0ef41Sopenharmony_ci * extraData[] where variable-length normalization data for this 2421cb0ef41Sopenharmony_ci * code point is found 2431cb0ef41Sopenharmony_ci * if this index is <_NORM_EXTRA_INDEX_TOP+_NORM_EXTRA_SURROGATE_TOP 2441cb0ef41Sopenharmony_ci * then this is a norm32 for a leading surrogate, and the index 2451cb0ef41Sopenharmony_ci * value is used together with the following trailing surrogate 2461cb0ef41Sopenharmony_ci * code unit in the second trie access 2471cb0ef41Sopenharmony_ci * if this index is >=_NORM_EXTRA_INDEX_TOP+_NORM_EXTRA_SURROGATE_TOP 2481cb0ef41Sopenharmony_ci * then this is a norm32 for a "special" character, 2491cb0ef41Sopenharmony_ci * i.e., the character is a Hangul syllable or a Jamo 2501cb0ef41Sopenharmony_ci * see _NORM_EXTRA_HANGUL etc. 2511cb0ef41Sopenharmony_ci * generally, instead of extracting this index from the norm32 and 2521cb0ef41Sopenharmony_ci * comparing it with the above constants, 2531cb0ef41Sopenharmony_ci * the normalization code compares the entire norm32 value 2541cb0ef41Sopenharmony_ci * with _NORM_MIN_SPECIAL, _NORM_SURROGATES_TOP, _NORM_MIN_HANGUL etc. 2551cb0ef41Sopenharmony_ci * 2561cb0ef41Sopenharmony_ci * 15..8 combining class (cc) according to UnicodeData.txt 2571cb0ef41Sopenharmony_ci * 2581cb0ef41Sopenharmony_ci * 7..6 _NORM_COMBINES_ANY flags, used in composition to see if a character 2591cb0ef41Sopenharmony_ci * combines with any following or preceding character(s) 2601cb0ef41Sopenharmony_ci * at all 2611cb0ef41Sopenharmony_ci * 7 _NORM_COMBINES_BACK 2621cb0ef41Sopenharmony_ci * 6 _NORM_COMBINES_FWD 2631cb0ef41Sopenharmony_ci * 2641cb0ef41Sopenharmony_ci * 5..0 quick check flags, set for "no" or "maybe", with separate flags for 2651cb0ef41Sopenharmony_ci * each normalization form 2661cb0ef41Sopenharmony_ci * the higher bits are "maybe" flags; for NF*D there are no such flags 2671cb0ef41Sopenharmony_ci * the lower bits are "no" flags for all forms, in the same order 2681cb0ef41Sopenharmony_ci * as the "maybe" flags, 2691cb0ef41Sopenharmony_ci * which is (MSB to LSB): NFKD NFD NFKC NFC 2701cb0ef41Sopenharmony_ci * 5..4 _NORM_QC_ANY_MAYBE 2711cb0ef41Sopenharmony_ci * 3..0 _NORM_QC_ANY_NO 2721cb0ef41Sopenharmony_ci * see further related constants 2731cb0ef41Sopenharmony_ci * 2741cb0ef41Sopenharmony_ci * 2751cb0ef41Sopenharmony_ci * - Extra data per code point 2761cb0ef41Sopenharmony_ci * 2771cb0ef41Sopenharmony_ci * "Extra data" is referenced by the index in norm32. 2781cb0ef41Sopenharmony_ci * It is variable-length data. It is only present, and only those parts 2791cb0ef41Sopenharmony_ci * of it are, as needed for a given character. 2801cb0ef41Sopenharmony_ci * The norm32 extra data index is added to the beginning of extraData[] 2811cb0ef41Sopenharmony_ci * to get to a vector of 16-bit words with data at the following offsets: 2821cb0ef41Sopenharmony_ci * 2831cb0ef41Sopenharmony_ci * [-1] Combining index for composition. 2841cb0ef41Sopenharmony_ci * Stored only if norm32&_NORM_COMBINES_ANY . 2851cb0ef41Sopenharmony_ci * [0] Lengths of the canonical and compatibility decomposition strings. 2861cb0ef41Sopenharmony_ci * Stored only if there are decompositions, i.e., 2871cb0ef41Sopenharmony_ci * if norm32&(_NORM_QC_NFD|_NORM_QC_NFKD) 2881cb0ef41Sopenharmony_ci * High byte: length of NFKD, or 0 if none 2891cb0ef41Sopenharmony_ci * Low byte: length of NFD, or 0 if none 2901cb0ef41Sopenharmony_ci * Each length byte also has another flag: 2911cb0ef41Sopenharmony_ci * Bit 7 of a length byte is set if there are non-zero 2921cb0ef41Sopenharmony_ci * combining classes (cc's) associated with the respective 2931cb0ef41Sopenharmony_ci * decomposition. If this flag is set, then the decomposition 2941cb0ef41Sopenharmony_ci * is preceded by a 16-bit word that contains the 2951cb0ef41Sopenharmony_ci * leading and trailing cc's. 2961cb0ef41Sopenharmony_ci * Bits 6..0 of a length byte are the length of the 2971cb0ef41Sopenharmony_ci * decomposition string, not counting the cc word. 2981cb0ef41Sopenharmony_ci * [1..n] NFD 2991cb0ef41Sopenharmony_ci * [n+1..] NFKD 3001cb0ef41Sopenharmony_ci * 3011cb0ef41Sopenharmony_ci * Each of the two decompositions consists of up to two parts: 3021cb0ef41Sopenharmony_ci * - The 16-bit words with the leading and trailing cc's. 3031cb0ef41Sopenharmony_ci * This is only stored if bit 7 of the corresponding length byte 3041cb0ef41Sopenharmony_ci * is set. In this case, at least one of the cc's is not zero. 3051cb0ef41Sopenharmony_ci * High byte: leading cc==cc of the first code point in the decomposition string 3061cb0ef41Sopenharmony_ci * Low byte: trailing cc==cc of the last code point in the decomposition string 3071cb0ef41Sopenharmony_ci * - The decomposition string in UTF-16, with length code units. 3081cb0ef41Sopenharmony_ci * 3091cb0ef41Sopenharmony_ci * 3101cb0ef41Sopenharmony_ci * - Combining indexes and combiningTable[] 3111cb0ef41Sopenharmony_ci * 3121cb0ef41Sopenharmony_ci * Combining indexes are stored at the [-1] offset of the extra data 3131cb0ef41Sopenharmony_ci * if the character combines forward or backward with any other characters. 3141cb0ef41Sopenharmony_ci * They are used for (re)composition in NF*C. 3151cb0ef41Sopenharmony_ci * Values of combining indexes are arranged according to whether a character 3161cb0ef41Sopenharmony_ci * combines forward, backward, or both ways: 3171cb0ef41Sopenharmony_ci * forward-only < both ways < backward-only 3181cb0ef41Sopenharmony_ci * 3191cb0ef41Sopenharmony_ci * The index values for forward-only and both-ways combining characters 3201cb0ef41Sopenharmony_ci * are indexes into the combiningTable[]. 3211cb0ef41Sopenharmony_ci * The index values for backward-only combining characters are simply 3221cb0ef41Sopenharmony_ci * incremented from the preceding index values to be unique. 3231cb0ef41Sopenharmony_ci * 3241cb0ef41Sopenharmony_ci * In the combiningTable[], a variable-length list 3251cb0ef41Sopenharmony_ci * of variable-length (back-index, code point) pair entries is stored 3261cb0ef41Sopenharmony_ci * for each forward-combining character. 3271cb0ef41Sopenharmony_ci * 3281cb0ef41Sopenharmony_ci * These back-indexes are the combining indexes of both-ways or backward-only 3291cb0ef41Sopenharmony_ci * combining characters that the forward-combining character combines with. 3301cb0ef41Sopenharmony_ci * 3311cb0ef41Sopenharmony_ci * Each list is sorted in ascending order of back-indexes. 3321cb0ef41Sopenharmony_ci * Each list is terminated with the last back-index having bit 15 set. 3331cb0ef41Sopenharmony_ci * 3341cb0ef41Sopenharmony_ci * Each pair (back-index, code point) takes up either 2 or 3 3351cb0ef41Sopenharmony_ci * 16-bit words. 3361cb0ef41Sopenharmony_ci * The first word of a list entry is the back-index, with its bit 15 set if 3371cb0ef41Sopenharmony_ci * this is the last pair in the list. 3381cb0ef41Sopenharmony_ci * 3391cb0ef41Sopenharmony_ci * The second word contains flags in bits 15..13 that determine 3401cb0ef41Sopenharmony_ci * if there is a third word and how the combined character is encoded: 3411cb0ef41Sopenharmony_ci * 15 set if there is a third word in this list entry 3421cb0ef41Sopenharmony_ci * 14 set if the result is a supplementary character 3431cb0ef41Sopenharmony_ci * 13 set if the result itself combines forward 3441cb0ef41Sopenharmony_ci * 3451cb0ef41Sopenharmony_ci * According to these bits 15..14 of the second word, 3461cb0ef41Sopenharmony_ci * the result character is encoded as follows: 3471cb0ef41Sopenharmony_ci * 00 or 01 The result is <=0x1fff and stored in bits 12..0 of 3481cb0ef41Sopenharmony_ci * the second word. 3491cb0ef41Sopenharmony_ci * 10 The result is 0x2000..0xffff and stored in the third word. 3501cb0ef41Sopenharmony_ci * Bits 12..0 of the second word are not used. 3511cb0ef41Sopenharmony_ci * 11 The result is a supplementary character. 3521cb0ef41Sopenharmony_ci * Bits 9..0 of the leading surrogate are in bits 9..0 of 3531cb0ef41Sopenharmony_ci * the second word. 3541cb0ef41Sopenharmony_ci * Add 0xd800 to these bits to get the complete surrogate. 3551cb0ef41Sopenharmony_ci * Bits 12..10 of the second word are not used. 3561cb0ef41Sopenharmony_ci * The trailing surrogate is stored in the third word. 3571cb0ef41Sopenharmony_ci * 3581cb0ef41Sopenharmony_ci * 3591cb0ef41Sopenharmony_ci * - FCD trie 3601cb0ef41Sopenharmony_ci * 3611cb0ef41Sopenharmony_ci * The FCD trie is very simple. 3621cb0ef41Sopenharmony_ci * It is a folded trie with 16-bit data words. 3631cb0ef41Sopenharmony_ci * In each word, the high byte contains the leading cc of the character, 3641cb0ef41Sopenharmony_ci * and the low byte contains the trailing cc of the character. 3651cb0ef41Sopenharmony_ci * These cc's are the cc's of the first and last code points in the 3661cb0ef41Sopenharmony_ci * canonical decomposition of the character. 3671cb0ef41Sopenharmony_ci * 3681cb0ef41Sopenharmony_ci * Since all 16 bits are used for cc's, lead surrogates must be tested 3691cb0ef41Sopenharmony_ci * by checking the code unit instead of the trie data. 3701cb0ef41Sopenharmony_ci * This is done only if the 16-bit data word is not zero. 3711cb0ef41Sopenharmony_ci * If the code unit is a leading surrogate and the data word is not zero, 3721cb0ef41Sopenharmony_ci * then instead of cc's it contains the offset for the second trie lookup. 3731cb0ef41Sopenharmony_ci * 3741cb0ef41Sopenharmony_ci * 3751cb0ef41Sopenharmony_ci * - Auxiliary trie and data 3761cb0ef41Sopenharmony_ci * 3771cb0ef41Sopenharmony_ci * The auxiliary 16-bit trie contains data for additional properties. 3781cb0ef41Sopenharmony_ci * Bits 3791cb0ef41Sopenharmony_ci * 15..13 reserved 3801cb0ef41Sopenharmony_ci * 12 not NFC_Skippable (f) (formatVersion>=2.2) 3811cb0ef41Sopenharmony_ci * 11 flag: not a safe starter for canonical closure 3821cb0ef41Sopenharmony_ci * 10 composition exclusion 3831cb0ef41Sopenharmony_ci * 9.. 0 index into extraData[] to FC_NFKC_Closure string 3841cb0ef41Sopenharmony_ci * (not for lead surrogate), 3851cb0ef41Sopenharmony_ci * or lead surrogate offset (for lead surrogate, if 9..0 not zero) 3861cb0ef41Sopenharmony_ci * 3871cb0ef41Sopenharmony_ci * - FC_NFKC_Closure strings in extraData[] 3881cb0ef41Sopenharmony_ci * 3891cb0ef41Sopenharmony_ci * Strings are either stored as a single code unit or as the length 3901cb0ef41Sopenharmony_ci * followed by that many units. 3911cb0ef41Sopenharmony_ci * const char16_t *s=extraData+(index from auxTrie data bits 9..0); 3921cb0ef41Sopenharmony_ci * int32_t length; 3931cb0ef41Sopenharmony_ci * if(*s<0xff00) { 3941cb0ef41Sopenharmony_ci * // s points to the single-unit string 3951cb0ef41Sopenharmony_ci * length=1; 3961cb0ef41Sopenharmony_ci * } else { 3971cb0ef41Sopenharmony_ci * length=*s&0xff; 3981cb0ef41Sopenharmony_ci * ++s; 3991cb0ef41Sopenharmony_ci * } 4001cb0ef41Sopenharmony_ci * 4011cb0ef41Sopenharmony_ci * Conditions for "NF* Skippable" from Mark Davis' com.ibm.text.UCD.NFSkippable: 4021cb0ef41Sopenharmony_ci * (used in NormalizerTransliterator) 4031cb0ef41Sopenharmony_ci * 4041cb0ef41Sopenharmony_ci * A skippable character is 4051cb0ef41Sopenharmony_ci * a) unassigned, or ALL of the following: 4061cb0ef41Sopenharmony_ci * b) of combining class 0. 4071cb0ef41Sopenharmony_ci * c) not decomposed by this normalization form. 4081cb0ef41Sopenharmony_ci * AND if NFC or NFKC, 4091cb0ef41Sopenharmony_ci * d) can never compose with a previous character. 4101cb0ef41Sopenharmony_ci * e) can never compose with a following character. 4111cb0ef41Sopenharmony_ci * f) can never change if another character is added. 4121cb0ef41Sopenharmony_ci * Example: a-breve might satisfy all but f, but if you 4131cb0ef41Sopenharmony_ci * add an ogonek it changes to a-ogonek + breve 4141cb0ef41Sopenharmony_ci * 4151cb0ef41Sopenharmony_ci * a)..e) must be tested from norm32. 4161cb0ef41Sopenharmony_ci * Since f) is more complicated, the (not-)NFC_Skippable flag (f) is built 4171cb0ef41Sopenharmony_ci * into the auxiliary trie. 4181cb0ef41Sopenharmony_ci * The same bit is used for NFC and NFKC; (c) differs for them. 4191cb0ef41Sopenharmony_ci * As usual, we build the "not skippable" flags so that unassigned 4201cb0ef41Sopenharmony_ci * code points get a 0 bit. 4211cb0ef41Sopenharmony_ci * This bit is only valid after (a)..(e) test false; test NFD_NO before (f) as well. 4221cb0ef41Sopenharmony_ci * Test Hangul LV syllables entirely in code. 4231cb0ef41Sopenharmony_ci * 4241cb0ef41Sopenharmony_ci * 4251cb0ef41Sopenharmony_ci * - structure inside canonStartSets[] 4261cb0ef41Sopenharmony_ci * 4271cb0ef41Sopenharmony_ci * This array maps from code points c to sets of code points (USerializedSet). 4281cb0ef41Sopenharmony_ci * The result sets are the code points whose canonical decompositions start 4291cb0ef41Sopenharmony_ci * with c. 4301cb0ef41Sopenharmony_ci * 4311cb0ef41Sopenharmony_ci * canonStartSets[] contains the following sub-arrays: 4321cb0ef41Sopenharmony_ci * 4331cb0ef41Sopenharmony_ci * indexes[_NORM_SET_INDEX_TOP] 4341cb0ef41Sopenharmony_ci * - contains lengths of sub-arrays etc. 4351cb0ef41Sopenharmony_ci * 4361cb0ef41Sopenharmony_ci * startSets[indexes[_NORM_SET_INDEX_CANON_SETS_LENGTH]-_NORM_SET_INDEX_TOP] 4371cb0ef41Sopenharmony_ci * - contains serialized sets (USerializedSet) of canonical starters for 4381cb0ef41Sopenharmony_ci * enumerating canonically equivalent strings 4391cb0ef41Sopenharmony_ci * indexes[_NORM_SET_INDEX_CANON_SETS_LENGTH] includes _NORM_SET_INDEX_TOP 4401cb0ef41Sopenharmony_ci * for details about the structure see uset.c 4411cb0ef41Sopenharmony_ci * 4421cb0ef41Sopenharmony_ci * bmpTable[indexes[_NORM_SET_INDEX_CANON_BMP_TABLE_LENGTH]] 4431cb0ef41Sopenharmony_ci * - a sorted search table for BMP code points whose results are 4441cb0ef41Sopenharmony_ci * either indexes to USerializedSets or single code points for 4451cb0ef41Sopenharmony_ci * single-code point sets; 4461cb0ef41Sopenharmony_ci * each entry is a pair of { code point, result } with result=(binary) yy xxxxxx xxxxxxxx 4471cb0ef41Sopenharmony_ci * if yy==01 then there is a USerializedSet at canonStartSets+x 4481cb0ef41Sopenharmony_ci * else build a USerializedSet with result as the single code point 4491cb0ef41Sopenharmony_ci * 4501cb0ef41Sopenharmony_ci * suppTable[indexes[_NORM_SET_INDEX_CANON_SUPP_TABLE_LENGTH]] 4511cb0ef41Sopenharmony_ci * - a sorted search table for supplementary code points whose results are 4521cb0ef41Sopenharmony_ci * either indexes to USerializedSets or single code points for 4531cb0ef41Sopenharmony_ci * single-code point sets; 4541cb0ef41Sopenharmony_ci * each entry is a triplet of { high16(cp), low16(cp), result } 4551cb0ef41Sopenharmony_ci * each code point's high-word may contain extra data in bits 15..5: 4561cb0ef41Sopenharmony_ci * if the high word has bit 15 set, then build a set with a single code point 4571cb0ef41Sopenharmony_ci * which is (((high16(cp)&0x1f00)<<8)|result; 4581cb0ef41Sopenharmony_ci * else there is a USerializedSet at canonStartSets+result 4591cb0ef41Sopenharmony_ci * 4601cb0ef41Sopenharmony_ci * FormatVersion 2.3 adds 2 serialized sets for normalization exclusions. 4611cb0ef41Sopenharmony_ci * They are stored in the data file so that the runtime normalization code need 4621cb0ef41Sopenharmony_ci * not depend on other properties and their data and implementation files. 4631cb0ef41Sopenharmony_ci * The _NORM_SET_INDEX_NX_..._OFFSET offsets in the canonStartSets index table 4641cb0ef41Sopenharmony_ci * give the location for each set. 4651cb0ef41Sopenharmony_ci * There is no set stored for UNORM_NX_HANGUL because it's trivial to create 4661cb0ef41Sopenharmony_ci * without using properties. 4671cb0ef41Sopenharmony_ci * 4681cb0ef41Sopenharmony_ci * Set contents: 4691cb0ef41Sopenharmony_ci * 4701cb0ef41Sopenharmony_ci * _NORM_SET_INDEX_NX_CJK_COMPAT_OFFSET (for UNORM_NX_CJK_COMPAT) 4711cb0ef41Sopenharmony_ci * [[:Ideographic:]&[:NFD_QC=No:]] 4721cb0ef41Sopenharmony_ci * =[CJK Ideographs]&[has canonical decomposition] 4731cb0ef41Sopenharmony_ci * 4741cb0ef41Sopenharmony_ci * _NORM_SET_INDEX_NX_UNICODE32_OFFSET (for UNORM_UNICODE_3_2) 4751cb0ef41Sopenharmony_ci * [:^Age=3.2:] 4761cb0ef41Sopenharmony_ci * =set with all code points that were not designated by the specified Unicode version 4771cb0ef41Sopenharmony_ci * 4781cb0ef41Sopenharmony_ci * _NORM_SET_INDEX_NX_RESERVED_OFFSET 4791cb0ef41Sopenharmony_ci * This is an offset that points to where the next, future set would start. 4801cb0ef41Sopenharmony_ci * Currently it indicates where the previous set ends, and thus its length. 4811cb0ef41Sopenharmony_ci * The name for this enum constant may in the future be applied to different 4821cb0ef41Sopenharmony_ci * index slots. In order to get the limit of a set, use its index slot and 4831cb0ef41Sopenharmony_ci * the immediately following one regardless of that one's enum name. 4841cb0ef41Sopenharmony_ci */ 4851cb0ef41Sopenharmony_ci 4861cb0ef41Sopenharmony_ci#endif /* #if !UCONFIG_NO_NORMALIZATION */ 4871cb0ef41Sopenharmony_ci 4881cb0ef41Sopenharmony_ci#endif 489