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) 2003-2013, 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: ucnv_ext.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: 2003jun13 16*0e209d39SAndroid Build Coastguard Worker * created by: Markus W. Scherer 17*0e209d39SAndroid Build Coastguard Worker * 18*0e209d39SAndroid Build Coastguard Worker * Conversion extensions 19*0e209d39SAndroid Build Coastguard Worker */ 20*0e209d39SAndroid Build Coastguard Worker 21*0e209d39SAndroid Build Coastguard Worker #ifndef __UCNV_EXT_H__ 22*0e209d39SAndroid Build Coastguard Worker #define __UCNV_EXT_H__ 23*0e209d39SAndroid Build Coastguard Worker 24*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h" 25*0e209d39SAndroid Build Coastguard Worker 26*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_CONVERSION 27*0e209d39SAndroid Build Coastguard Worker 28*0e209d39SAndroid Build Coastguard Worker #include "unicode/ucnv.h" 29*0e209d39SAndroid Build Coastguard Worker #include "ucnv_cnv.h" 30*0e209d39SAndroid Build Coastguard Worker 31*0e209d39SAndroid Build Coastguard Worker /* 32*0e209d39SAndroid Build Coastguard Worker * See icuhtml/design/conversion/conversion_extensions.html 33*0e209d39SAndroid Build Coastguard Worker * 34*0e209d39SAndroid Build Coastguard Worker * Conversion extensions serve three purposes: 35*0e209d39SAndroid Build Coastguard Worker * 1. They support m:n mappings. 36*0e209d39SAndroid Build Coastguard Worker * 2. They support extension-only conversion files that are used together 37*0e209d39SAndroid Build Coastguard Worker * with the regular conversion data in base files. 38*0e209d39SAndroid Build Coastguard Worker * 3. They support mappings with more complicated meta data, 39*0e209d39SAndroid Build Coastguard Worker * for example "good one-way" mappings (|4). 40*0e209d39SAndroid Build Coastguard Worker * 41*0e209d39SAndroid Build Coastguard Worker * A base file may contain an extension table (explicitly requested or 42*0e209d39SAndroid Build Coastguard Worker * implicitly generated for m:n mappings), but its extension table is not 43*0e209d39SAndroid Build Coastguard Worker * used when an extension-only file is used. 44*0e209d39SAndroid Build Coastguard Worker * 45*0e209d39SAndroid Build Coastguard Worker * It is an error if a base file contains any regular (not extension) mapping 46*0e209d39SAndroid Build Coastguard Worker * from the same sequence as a mapping in the extension file 47*0e209d39SAndroid Build Coastguard Worker * because the base mapping would hide the extension mapping. 48*0e209d39SAndroid Build Coastguard Worker * 49*0e209d39SAndroid Build Coastguard Worker * 50*0e209d39SAndroid Build Coastguard Worker * Data for conversion extensions: 51*0e209d39SAndroid Build Coastguard Worker * 52*0e209d39SAndroid Build Coastguard Worker * One set of data structures per conversion direction (to/from Unicode). 53*0e209d39SAndroid Build Coastguard Worker * The data structures are sorted by input units to allow for binary search. 54*0e209d39SAndroid Build Coastguard Worker * Input sequences of more than one unit are handled like contraction tables 55*0e209d39SAndroid Build Coastguard Worker * in collation: 56*0e209d39SAndroid Build Coastguard Worker * The lookup value of a unit points to another table that is to be searched 57*0e209d39SAndroid Build Coastguard Worker * for the next unit, recursively. 58*0e209d39SAndroid Build Coastguard Worker * 59*0e209d39SAndroid Build Coastguard Worker * For conversion from Unicode, the initial code point is looked up in 60*0e209d39SAndroid Build Coastguard Worker * a 3-stage trie for speed, 61*0e209d39SAndroid Build Coastguard Worker * with an additional table of unique results to save space. 62*0e209d39SAndroid Build Coastguard Worker * 63*0e209d39SAndroid Build Coastguard Worker * Long output strings are stored in separate arrays, with length and index 64*0e209d39SAndroid Build Coastguard Worker * in the lookup tables. 65*0e209d39SAndroid Build Coastguard Worker * Output results also include a flag distinguishing roundtrip from 66*0e209d39SAndroid Build Coastguard Worker * (reverse) fallback mappings. 67*0e209d39SAndroid Build Coastguard Worker * 68*0e209d39SAndroid Build Coastguard Worker * Input Unicode strings must not begin or end with unpaired surrogates 69*0e209d39SAndroid Build Coastguard Worker * to avoid problems with matches on parts of surrogate pairs. 70*0e209d39SAndroid Build Coastguard Worker * 71*0e209d39SAndroid Build Coastguard Worker * Mappings from multiple characters (code points or codepage state 72*0e209d39SAndroid Build Coastguard Worker * table sequences) must be searched preferring the longest match. 73*0e209d39SAndroid Build Coastguard Worker * For this to work and be efficient, the variable-width table must contain 74*0e209d39SAndroid Build Coastguard Worker * all mappings that contain prefixes of the multiple characters. 75*0e209d39SAndroid Build Coastguard Worker * If an extension table is built on top of a base table in another file 76*0e209d39SAndroid Build Coastguard Worker * and a base table entry is a prefix of a multi-character mapping, then 77*0e209d39SAndroid Build Coastguard Worker * this is an error. 78*0e209d39SAndroid Build Coastguard Worker * 79*0e209d39SAndroid Build Coastguard Worker * 80*0e209d39SAndroid Build Coastguard Worker * Implementation note: 81*0e209d39SAndroid Build Coastguard Worker * 82*0e209d39SAndroid Build Coastguard Worker * Currently, the parser and several checks in the code limit the number 83*0e209d39SAndroid Build Coastguard Worker * of UChars or bytes in a mapping to 84*0e209d39SAndroid Build Coastguard Worker * UCNV_EXT_MAX_UCHARS and UCNV_EXT_MAX_BYTES, respectively, 85*0e209d39SAndroid Build Coastguard Worker * which are output value limits in the data structure. 86*0e209d39SAndroid Build Coastguard Worker * 87*0e209d39SAndroid Build Coastguard Worker * For input, this is not strictly necessary - it is a hard limit only for the 88*0e209d39SAndroid Build Coastguard Worker * buffers in UConverter that are used to store partial matches. 89*0e209d39SAndroid Build Coastguard Worker * 90*0e209d39SAndroid Build Coastguard Worker * Input sequences could otherwise be arbitrarily long if partial matches 91*0e209d39SAndroid Build Coastguard Worker * need not be stored (i.e., if a sequence does not span several buffers with too 92*0e209d39SAndroid Build Coastguard Worker * many units before the last buffer), although then results would differ 93*0e209d39SAndroid Build Coastguard Worker * depending on whether partial matches exceed the limits or not, 94*0e209d39SAndroid Build Coastguard Worker * which depends on the pattern of buffer sizes. 95*0e209d39SAndroid Build Coastguard Worker * 96*0e209d39SAndroid Build Coastguard Worker * 97*0e209d39SAndroid Build Coastguard Worker * Data structure: 98*0e209d39SAndroid Build Coastguard Worker * 99*0e209d39SAndroid Build Coastguard Worker * int32_t indexes[>=32]; 100*0e209d39SAndroid Build Coastguard Worker * 101*0e209d39SAndroid Build Coastguard Worker * Array of indexes and lengths etc. The length of the array is at least 32. 102*0e209d39SAndroid Build Coastguard Worker * The actual length is stored in indexes[0] to be forward compatible. 103*0e209d39SAndroid Build Coastguard Worker * 104*0e209d39SAndroid Build Coastguard Worker * Each index to another array is the number of bytes from indexes[]. 105*0e209d39SAndroid Build Coastguard Worker * Each length of an array is the number of array base units in that array. 106*0e209d39SAndroid Build Coastguard Worker * 107*0e209d39SAndroid Build Coastguard Worker * Some of the structures may not be present, in which case their indexes 108*0e209d39SAndroid Build Coastguard Worker * and lengths are 0. 109*0e209d39SAndroid Build Coastguard Worker * 110*0e209d39SAndroid Build Coastguard Worker * Usage of indexes[i]: 111*0e209d39SAndroid Build Coastguard Worker * [0] length of indexes[] 112*0e209d39SAndroid Build Coastguard Worker * 113*0e209d39SAndroid Build Coastguard Worker * // to Unicode table 114*0e209d39SAndroid Build Coastguard Worker * [1] index of toUTable[] (array of uint32_t) 115*0e209d39SAndroid Build Coastguard Worker * [2] length of toUTable[] 116*0e209d39SAndroid Build Coastguard Worker * [3] index of toUUChars[] (array of UChar) 117*0e209d39SAndroid Build Coastguard Worker * [4] length of toUUChars[] 118*0e209d39SAndroid Build Coastguard Worker * 119*0e209d39SAndroid Build Coastguard Worker * // from Unicode table, not for the initial code point 120*0e209d39SAndroid Build Coastguard Worker * [5] index of fromUTableUChars[] (array of UChar) 121*0e209d39SAndroid Build Coastguard Worker * [6] index of fromUTableValues[] (array of uint32_t) 122*0e209d39SAndroid Build Coastguard Worker * [7] length of fromUTableUChars[] and fromUTableValues[] 123*0e209d39SAndroid Build Coastguard Worker * [8] index of fromUBytes[] (array of char) 124*0e209d39SAndroid Build Coastguard Worker * [9] length of fromUBytes[] 125*0e209d39SAndroid Build Coastguard Worker * 126*0e209d39SAndroid Build Coastguard Worker * // from Unicode trie for initial-code point lookup 127*0e209d39SAndroid Build Coastguard Worker * [10] index of fromUStage12[] (combined array of uint16_t for stages 1 & 2) 128*0e209d39SAndroid Build Coastguard Worker * [11] length of stage 1 portion of fromUStage12[] 129*0e209d39SAndroid Build Coastguard Worker * [12] length of fromUStage12[] 130*0e209d39SAndroid Build Coastguard Worker * [13] index of fromUStage3[] (array of uint16_t indexes into fromUStage3b[]) 131*0e209d39SAndroid Build Coastguard Worker * [14] length of fromUStage3[] 132*0e209d39SAndroid Build Coastguard Worker * [15] index of fromUStage3b[] (array of uint32_t like fromUTableValues[]) 133*0e209d39SAndroid Build Coastguard Worker * [16] length of fromUStage3b[] 134*0e209d39SAndroid Build Coastguard Worker * 135*0e209d39SAndroid Build Coastguard Worker * [17] Bit field containing numbers of bytes: 136*0e209d39SAndroid Build Coastguard Worker * 31..24 reserved, 0 137*0e209d39SAndroid Build Coastguard Worker * 23..16 maximum input bytes 138*0e209d39SAndroid Build Coastguard Worker * 15.. 8 maximum output bytes 139*0e209d39SAndroid Build Coastguard Worker * 7.. 0 maximum bytes per UChar 140*0e209d39SAndroid Build Coastguard Worker * 141*0e209d39SAndroid Build Coastguard Worker * [18] Bit field containing numbers of UChars: 142*0e209d39SAndroid Build Coastguard Worker * 31..24 reserved, 0 143*0e209d39SAndroid Build Coastguard Worker * 23..16 maximum input UChars 144*0e209d39SAndroid Build Coastguard Worker * 15.. 8 maximum output UChars 145*0e209d39SAndroid Build Coastguard Worker * 7.. 0 maximum UChars per byte 146*0e209d39SAndroid Build Coastguard Worker * 147*0e209d39SAndroid Build Coastguard Worker * [19] Bit field containing flags: 148*0e209d39SAndroid Build Coastguard Worker * (extension table unicodeMask) 149*0e209d39SAndroid Build Coastguard Worker * 1 UCNV_HAS_SURROGATES flag for the extension table 150*0e209d39SAndroid Build Coastguard Worker * 0 UCNV_HAS_SUPPLEMENTARY flag for the extension table 151*0e209d39SAndroid Build Coastguard Worker * 152*0e209d39SAndroid Build Coastguard Worker * [20]..[30] reserved, 0 153*0e209d39SAndroid Build Coastguard Worker * [31] number of bytes for the entire extension structure 154*0e209d39SAndroid Build Coastguard Worker * [>31] reserved; there are indexes[0] indexes 155*0e209d39SAndroid Build Coastguard Worker * 156*0e209d39SAndroid Build Coastguard Worker * 157*0e209d39SAndroid Build Coastguard Worker * uint32_t toUTable[]; 158*0e209d39SAndroid Build Coastguard Worker * 159*0e209d39SAndroid Build Coastguard Worker * Array of byte/value pairs for lookups for toUnicode conversion. 160*0e209d39SAndroid Build Coastguard Worker * The array is partitioned into sections like collation contraction tables. 161*0e209d39SAndroid Build Coastguard Worker * Each section contains one word with the number of following words and 162*0e209d39SAndroid Build Coastguard Worker * a default value for when the lookup in this section yields no match. 163*0e209d39SAndroid Build Coastguard Worker * 164*0e209d39SAndroid Build Coastguard Worker * A section is sorted in ascending order of input bytes, 165*0e209d39SAndroid Build Coastguard Worker * allowing for fast linear or binary searches. 166*0e209d39SAndroid Build Coastguard Worker * The builder may store entries for a contiguous range of byte values 167*0e209d39SAndroid Build Coastguard Worker * (compare difference between the first and last one with count), 168*0e209d39SAndroid Build Coastguard Worker * which then allows for direct array access. 169*0e209d39SAndroid Build Coastguard Worker * The builder should always do this for the initial table section. 170*0e209d39SAndroid Build Coastguard Worker * 171*0e209d39SAndroid Build Coastguard Worker * Entries may have 0 values, see below. 172*0e209d39SAndroid Build Coastguard Worker * No two entries in a section have the same byte values. 173*0e209d39SAndroid Build Coastguard Worker * 174*0e209d39SAndroid Build Coastguard Worker * Each uint32_t contains an input byte value in bits 31..24 and the 175*0e209d39SAndroid Build Coastguard Worker * corresponding lookup value in bits 23..0. 176*0e209d39SAndroid Build Coastguard Worker * Interpret the value as follows: 177*0e209d39SAndroid Build Coastguard Worker * if(value==0) { 178*0e209d39SAndroid Build Coastguard Worker * no match, see below 179*0e209d39SAndroid Build Coastguard Worker * } else if(value<0x1f0000) { 180*0e209d39SAndroid Build Coastguard Worker * partial match - use value as index to the next toUTable section 181*0e209d39SAndroid Build Coastguard Worker * and match the next unit; (value indexes toUTable[value]) 182*0e209d39SAndroid Build Coastguard Worker * } else { 183*0e209d39SAndroid Build Coastguard Worker * if(bit 23 set) { 184*0e209d39SAndroid Build Coastguard Worker * roundtrip; 185*0e209d39SAndroid Build Coastguard Worker * } else { 186*0e209d39SAndroid Build Coastguard Worker * fallback; 187*0e209d39SAndroid Build Coastguard Worker * } 188*0e209d39SAndroid Build Coastguard Worker * unset value bit 23; 189*0e209d39SAndroid Build Coastguard Worker * if(value<=0x2fffff) { 190*0e209d39SAndroid Build Coastguard Worker * (value-0x1f0000) is a code point; (BMP: value<=0x1fffff) 191*0e209d39SAndroid Build Coastguard Worker * } else { 192*0e209d39SAndroid Build Coastguard Worker * bits 17..0 (value&0x3ffff) is an index to 193*0e209d39SAndroid Build Coastguard Worker * the result UChars in toUUChars[]; (0 indexes toUUChars[0]) 194*0e209d39SAndroid Build Coastguard Worker * length of the result=((value>>18)-12); (length=0..19) 195*0e209d39SAndroid Build Coastguard Worker * } 196*0e209d39SAndroid Build Coastguard Worker * } 197*0e209d39SAndroid Build Coastguard Worker * 198*0e209d39SAndroid Build Coastguard Worker * The first word in a section contains the number of following words in the 199*0e209d39SAndroid Build Coastguard Worker * input byte position (bits 31..24, number=1..0xff). 200*0e209d39SAndroid Build Coastguard Worker * The value of the initial word is used when the current byte is not found 201*0e209d39SAndroid Build Coastguard Worker * in this section. 202*0e209d39SAndroid Build Coastguard Worker * If the value is not 0, then it represents a result as above. 203*0e209d39SAndroid Build Coastguard Worker * If the value is 0, then the search has to return a shorter match with an 204*0e209d39SAndroid Build Coastguard Worker * earlier default value as the result, or result in "unmappable" even for the 205*0e209d39SAndroid Build Coastguard Worker * initial bytes. 206*0e209d39SAndroid Build Coastguard Worker * If the value is 0 for the initial toUTable entry, then the initial byte 207*0e209d39SAndroid Build Coastguard Worker * does not start any mapping input. 208*0e209d39SAndroid Build Coastguard Worker * 209*0e209d39SAndroid Build Coastguard Worker * 210*0e209d39SAndroid Build Coastguard Worker * UChar toUUChars[]; 211*0e209d39SAndroid Build Coastguard Worker * 212*0e209d39SAndroid Build Coastguard Worker * Contains toUnicode mapping results, stored as sequences of UChars. 213*0e209d39SAndroid Build Coastguard Worker * Indexes and lengths stored in the toUTable[]. 214*0e209d39SAndroid Build Coastguard Worker * 215*0e209d39SAndroid Build Coastguard Worker * 216*0e209d39SAndroid Build Coastguard Worker * UChar fromUTableUChars[]; 217*0e209d39SAndroid Build Coastguard Worker * uint32_t fromUTableValues[]; 218*0e209d39SAndroid Build Coastguard Worker * 219*0e209d39SAndroid Build Coastguard Worker * The fromUTable is split into two arrays, but works otherwise much like 220*0e209d39SAndroid Build Coastguard Worker * the toUTable. The array is partitioned into sections like collation 221*0e209d39SAndroid Build Coastguard Worker * contraction tables and toUTable. 222*0e209d39SAndroid Build Coastguard Worker * A row in the table consists of same-index entries in fromUTableUChars[] 223*0e209d39SAndroid Build Coastguard Worker * and fromUTableValues[]. 224*0e209d39SAndroid Build Coastguard Worker * 225*0e209d39SAndroid Build Coastguard Worker * Interpret a value as follows: 226*0e209d39SAndroid Build Coastguard Worker * if(value==0) { 227*0e209d39SAndroid Build Coastguard Worker * no match, see below 228*0e209d39SAndroid Build Coastguard Worker * } else if(value<=0xffffff) { (bits 31..24 are 0) 229*0e209d39SAndroid Build Coastguard Worker * partial match - use value as index to the next fromUTable section 230*0e209d39SAndroid Build Coastguard Worker * and match the next unit; (value indexes fromUTable[value]) 231*0e209d39SAndroid Build Coastguard Worker * } else { 232*0e209d39SAndroid Build Coastguard Worker * if(value==0x80000001) { 233*0e209d39SAndroid Build Coastguard Worker * return no mapping, but request for <subchar1>; 234*0e209d39SAndroid Build Coastguard Worker * } 235*0e209d39SAndroid Build Coastguard Worker * if(bit 31 set) { 236*0e209d39SAndroid Build Coastguard Worker * roundtrip (|0); 237*0e209d39SAndroid Build Coastguard Worker * } else if(bit 30 set) { 238*0e209d39SAndroid Build Coastguard Worker * "good one-way" mapping (|4); -- new in ICU4C 51, _MBCSHeader.version 5.4/4.4 239*0e209d39SAndroid Build Coastguard Worker * } else { 240*0e209d39SAndroid Build Coastguard Worker * normal fallback (|1); 241*0e209d39SAndroid Build Coastguard Worker * } 242*0e209d39SAndroid Build Coastguard Worker * // bit 29 reserved, 0 243*0e209d39SAndroid Build Coastguard Worker * length=(value>>24)&0x1f; (bits 28..24) 244*0e209d39SAndroid Build Coastguard Worker * if(length==1..3) { 245*0e209d39SAndroid Build Coastguard Worker * bits 23..0 contain 1..3 bytes, padded with 00s on the left; 246*0e209d39SAndroid Build Coastguard Worker * } else { 247*0e209d39SAndroid Build Coastguard Worker * bits 23..0 (value&0xffffff) is an index to 248*0e209d39SAndroid Build Coastguard Worker * the result bytes in fromUBytes[]; (0 indexes fromUBytes[0]) 249*0e209d39SAndroid Build Coastguard Worker * } 250*0e209d39SAndroid Build Coastguard Worker * } 251*0e209d39SAndroid Build Coastguard Worker * 252*0e209d39SAndroid Build Coastguard Worker * The first pair in a section contains the number of following pairs in the 253*0e209d39SAndroid Build Coastguard Worker * UChar position (16 bits, number=1..0xffff). 254*0e209d39SAndroid Build Coastguard Worker * The value of the initial pair is used when the current UChar is not found 255*0e209d39SAndroid Build Coastguard Worker * in this section. 256*0e209d39SAndroid Build Coastguard Worker * If the value is not 0, then it represents a result as above. 257*0e209d39SAndroid Build Coastguard Worker * If the value is 0, then the search has to return a shorter match with an 258*0e209d39SAndroid Build Coastguard Worker * earlier default value as the result, or result in "unmappable" even for the 259*0e209d39SAndroid Build Coastguard Worker * initial UChars. 260*0e209d39SAndroid Build Coastguard Worker * 261*0e209d39SAndroid Build Coastguard Worker * If the from Unicode trie is present, then the from Unicode search tables 262*0e209d39SAndroid Build Coastguard Worker * are not used for initial code points. 263*0e209d39SAndroid Build Coastguard Worker * In this case, the first entries (index 0) in the tables are not used 264*0e209d39SAndroid Build Coastguard Worker * (reserved, set to 0) because a value of 0 is used in trie results 265*0e209d39SAndroid Build Coastguard Worker * to indicate no mapping. 266*0e209d39SAndroid Build Coastguard Worker * 267*0e209d39SAndroid Build Coastguard Worker * 268*0e209d39SAndroid Build Coastguard Worker * uint16_t fromUStage12[]; 269*0e209d39SAndroid Build Coastguard Worker * 270*0e209d39SAndroid Build Coastguard Worker * Stages 1 & 2 of a trie that maps an initial code point. 271*0e209d39SAndroid Build Coastguard Worker * Indexes in stage 1 are all offset by the length of stage 1 so that the 272*0e209d39SAndroid Build Coastguard Worker * same array pointer can be used for both stages. 273*0e209d39SAndroid Build Coastguard Worker * If (c>>10)>=(length of stage 1) then c does not start any mapping. 274*0e209d39SAndroid Build Coastguard Worker * Same bit distribution as for regular conversion tries. 275*0e209d39SAndroid Build Coastguard Worker * 276*0e209d39SAndroid Build Coastguard Worker * 277*0e209d39SAndroid Build Coastguard Worker * uint16_t fromUStage3[]; 278*0e209d39SAndroid Build Coastguard Worker * uint32_t fromUStage3b[]; 279*0e209d39SAndroid Build Coastguard Worker * 280*0e209d39SAndroid Build Coastguard Worker * Stage 3 of the trie. The first array simply contains indexes to the second, 281*0e209d39SAndroid Build Coastguard Worker * which contains words in the same format as fromUTableValues[]. 282*0e209d39SAndroid Build Coastguard Worker * Use a stage 3 granularity of 4, which allows for 256k stage 3 entries, 283*0e209d39SAndroid Build Coastguard Worker * and 16-bit entries in stage 3 allow for 64k stage 3b entries. 284*0e209d39SAndroid Build Coastguard Worker * The stage 3 granularity means that the stage 2 entry needs to be left-shifted. 285*0e209d39SAndroid Build Coastguard Worker * 286*0e209d39SAndroid Build Coastguard Worker * Two arrays are used because it is expected that more than half of the stage 3 287*0e209d39SAndroid Build Coastguard Worker * entries will be zero. The 16-bit index stage 3 array saves space even 288*0e209d39SAndroid Build Coastguard Worker * considering storing a total of 6 bytes per non-zero entry in both arrays 289*0e209d39SAndroid Build Coastguard Worker * together. 290*0e209d39SAndroid Build Coastguard Worker * Using a stage 3 granularity of >1 diminishes the compactability in that stage 291*0e209d39SAndroid Build Coastguard Worker * but provides a larger effective addressing space in stage 2. 292*0e209d39SAndroid Build Coastguard Worker * All but the final result stage use 16-bit entries to save space. 293*0e209d39SAndroid Build Coastguard Worker * 294*0e209d39SAndroid Build Coastguard Worker * fromUStage3b[] contains a zero for "no mapping" at its index 0, 295*0e209d39SAndroid Build Coastguard Worker * and may contain UCNV_EXT_FROM_U_SUBCHAR1 at index 1 for "<subchar1> SUB mapping" 296*0e209d39SAndroid Build Coastguard Worker * (i.e., "no mapping" with preference for <subchar1> rather than <subchar>), 297*0e209d39SAndroid Build Coastguard Worker * and all other items are unique non-zero results. 298*0e209d39SAndroid Build Coastguard Worker * 299*0e209d39SAndroid Build Coastguard Worker * The default value of a fromUTableValues[] section that is referenced 300*0e209d39SAndroid Build Coastguard Worker * _directly_ from a fromUStage3b[] item may also be UCNV_EXT_FROM_U_SUBCHAR1, 301*0e209d39SAndroid Build Coastguard Worker * but this value must not occur anywhere else in fromUTableValues[] 302*0e209d39SAndroid Build Coastguard Worker * because "no mapping" is always a property of a single code point, 303*0e209d39SAndroid Build Coastguard Worker * never of multiple. 304*0e209d39SAndroid Build Coastguard Worker * 305*0e209d39SAndroid Build Coastguard Worker * 306*0e209d39SAndroid Build Coastguard Worker * char fromUBytes[]; 307*0e209d39SAndroid Build Coastguard Worker * 308*0e209d39SAndroid Build Coastguard Worker * Contains fromUnicode mapping results, stored as sequences of chars. 309*0e209d39SAndroid Build Coastguard Worker * Indexes and lengths stored in the fromUTableValues[]. 310*0e209d39SAndroid Build Coastguard Worker */ 311*0e209d39SAndroid Build Coastguard Worker enum { 312*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_INDEXES_LENGTH, /* 0 */ 313*0e209d39SAndroid Build Coastguard Worker 314*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_TO_U_INDEX, /* 1 */ 315*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_TO_U_LENGTH, 316*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_TO_U_UCHARS_INDEX, 317*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_TO_U_UCHARS_LENGTH, 318*0e209d39SAndroid Build Coastguard Worker 319*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_FROM_U_UCHARS_INDEX, /* 5 */ 320*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_FROM_U_VALUES_INDEX, 321*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_FROM_U_LENGTH, 322*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_FROM_U_BYTES_INDEX, 323*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_FROM_U_BYTES_LENGTH, 324*0e209d39SAndroid Build Coastguard Worker 325*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_FROM_U_STAGE_12_INDEX, /* 10 */ 326*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_FROM_U_STAGE_1_LENGTH, 327*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_FROM_U_STAGE_12_LENGTH, 328*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_FROM_U_STAGE_3_INDEX, 329*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_FROM_U_STAGE_3_LENGTH, 330*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_FROM_U_STAGE_3B_INDEX, 331*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_FROM_U_STAGE_3B_LENGTH, 332*0e209d39SAndroid Build Coastguard Worker 333*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_COUNT_BYTES, /* 17 */ 334*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_COUNT_UCHARS, 335*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_FLAGS, 336*0e209d39SAndroid Build Coastguard Worker 337*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_RESERVED_INDEX, /* 20, moves with additional indexes */ 338*0e209d39SAndroid Build Coastguard Worker 339*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_SIZE=31, 340*0e209d39SAndroid Build Coastguard Worker UCNV_EXT_INDEXES_MIN_LENGTH=32 341*0e209d39SAndroid Build Coastguard Worker }; 342*0e209d39SAndroid Build Coastguard Worker 343*0e209d39SAndroid Build Coastguard Worker /* get the pointer to an extension array from indexes[index] */ 344*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_ARRAY(indexes, index, itemType) \ 345*0e209d39SAndroid Build Coastguard Worker ((const itemType *)((const char *)(indexes)+(indexes)[index])) 346*0e209d39SAndroid Build Coastguard Worker 347*0e209d39SAndroid Build Coastguard Worker #define UCNV_GET_MAX_BYTES_PER_UCHAR(indexes) \ 348*0e209d39SAndroid Build Coastguard Worker ((indexes)[UCNV_EXT_COUNT_BYTES]&0xff) 349*0e209d39SAndroid Build Coastguard Worker 350*0e209d39SAndroid Build Coastguard Worker /* internal API ------------------------------------------------------------- */ 351*0e209d39SAndroid Build Coastguard Worker 352*0e209d39SAndroid Build Coastguard Worker U_CFUNC UBool 353*0e209d39SAndroid Build Coastguard Worker ucnv_extInitialMatchToU(UConverter *cnv, const int32_t *cx, 354*0e209d39SAndroid Build Coastguard Worker int32_t firstLength, 355*0e209d39SAndroid Build Coastguard Worker const char **src, const char *srcLimit, 356*0e209d39SAndroid Build Coastguard Worker UChar **target, const UChar *targetLimit, 357*0e209d39SAndroid Build Coastguard Worker int32_t **offsets, int32_t srcIndex, 358*0e209d39SAndroid Build Coastguard Worker UBool flush, 359*0e209d39SAndroid Build Coastguard Worker UErrorCode *pErrorCode); 360*0e209d39SAndroid Build Coastguard Worker 361*0e209d39SAndroid Build Coastguard Worker U_CFUNC UChar32 362*0e209d39SAndroid Build Coastguard Worker ucnv_extSimpleMatchToU(const int32_t *cx, 363*0e209d39SAndroid Build Coastguard Worker const char *source, int32_t length, 364*0e209d39SAndroid Build Coastguard Worker UBool useFallback); 365*0e209d39SAndroid Build Coastguard Worker 366*0e209d39SAndroid Build Coastguard Worker U_CFUNC void 367*0e209d39SAndroid Build Coastguard Worker ucnv_extContinueMatchToU(UConverter *cnv, 368*0e209d39SAndroid Build Coastguard Worker UConverterToUnicodeArgs *pArgs, int32_t srcIndex, 369*0e209d39SAndroid Build Coastguard Worker UErrorCode *pErrorCode); 370*0e209d39SAndroid Build Coastguard Worker 371*0e209d39SAndroid Build Coastguard Worker 372*0e209d39SAndroid Build Coastguard Worker U_CFUNC UBool 373*0e209d39SAndroid Build Coastguard Worker ucnv_extInitialMatchFromU(UConverter *cnv, const int32_t *cx, 374*0e209d39SAndroid Build Coastguard Worker UChar32 cp, 375*0e209d39SAndroid Build Coastguard Worker const UChar **src, const UChar *srcLimit, 376*0e209d39SAndroid Build Coastguard Worker char **target, const char *targetLimit, 377*0e209d39SAndroid Build Coastguard Worker int32_t **offsets, int32_t srcIndex, 378*0e209d39SAndroid Build Coastguard Worker UBool flush, 379*0e209d39SAndroid Build Coastguard Worker UErrorCode *pErrorCode); 380*0e209d39SAndroid Build Coastguard Worker 381*0e209d39SAndroid Build Coastguard Worker U_CFUNC int32_t 382*0e209d39SAndroid Build Coastguard Worker ucnv_extSimpleMatchFromU(const int32_t *cx, 383*0e209d39SAndroid Build Coastguard Worker UChar32 cp, uint32_t *pValue, 384*0e209d39SAndroid Build Coastguard Worker UBool useFallback); 385*0e209d39SAndroid Build Coastguard Worker 386*0e209d39SAndroid Build Coastguard Worker U_CFUNC void 387*0e209d39SAndroid Build Coastguard Worker ucnv_extContinueMatchFromU(UConverter *cnv, 388*0e209d39SAndroid Build Coastguard Worker UConverterFromUnicodeArgs *pArgs, int32_t srcIndex, 389*0e209d39SAndroid Build Coastguard Worker UErrorCode *pErrorCode); 390*0e209d39SAndroid Build Coastguard Worker 391*0e209d39SAndroid Build Coastguard Worker /* 392*0e209d39SAndroid Build Coastguard Worker * Add code points and strings to the set according to the extension mappings. 393*0e209d39SAndroid Build Coastguard Worker * Limitation on the UConverterSetFilter: 394*0e209d39SAndroid Build Coastguard Worker * The filters currently assume that they are used with 1:1 mappings. 395*0e209d39SAndroid Build Coastguard Worker * They only apply to single input code points, and then they pass through 396*0e209d39SAndroid Build Coastguard Worker * only mappings with single-charset-code results. 397*0e209d39SAndroid Build Coastguard Worker * For example, the Shift-JIS filter only works for 2-byte results and tests 398*0e209d39SAndroid Build Coastguard Worker * that those 2 bytes are in the JIS X 0208 range of Shift-JIS. 399*0e209d39SAndroid Build Coastguard Worker */ 400*0e209d39SAndroid Build Coastguard Worker U_CFUNC void 401*0e209d39SAndroid Build Coastguard Worker ucnv_extGetUnicodeSet(const UConverterSharedData *sharedData, 402*0e209d39SAndroid Build Coastguard Worker const USetAdder *sa, 403*0e209d39SAndroid Build Coastguard Worker UConverterUnicodeSet which, 404*0e209d39SAndroid Build Coastguard Worker UConverterSetFilter filter, 405*0e209d39SAndroid Build Coastguard Worker UErrorCode *pErrorCode); 406*0e209d39SAndroid Build Coastguard Worker 407*0e209d39SAndroid Build Coastguard Worker /* toUnicode helpers -------------------------------------------------------- */ 408*0e209d39SAndroid Build Coastguard Worker 409*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_TO_U_BYTE_SHIFT 24 410*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_TO_U_VALUE_MASK 0xffffff 411*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_TO_U_MIN_CODE_POINT 0x1f0000 412*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_TO_U_MAX_CODE_POINT 0x2fffff 413*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_TO_U_ROUNDTRIP_FLAG ((uint32_t)1<<23) 414*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_TO_U_INDEX_MASK 0x3ffff 415*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_TO_U_LENGTH_SHIFT 18 416*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_TO_U_LENGTH_OFFSET 12 417*0e209d39SAndroid Build Coastguard Worker 418*0e209d39SAndroid Build Coastguard Worker /* maximum number of indexed UChars */ 419*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_MAX_UCHARS 19 420*0e209d39SAndroid Build Coastguard Worker 421*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_TO_U_MAKE_WORD(byte, value) (((uint32_t)(byte)<<UCNV_EXT_TO_U_BYTE_SHIFT)|(value)) 422*0e209d39SAndroid Build Coastguard Worker 423*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_TO_U_GET_BYTE(word) ((word)>>UCNV_EXT_TO_U_BYTE_SHIFT) 424*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_TO_U_GET_VALUE(word) ((word)&UCNV_EXT_TO_U_VALUE_MASK) 425*0e209d39SAndroid Build Coastguard Worker 426*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_TO_U_IS_PARTIAL(value) ((value)<UCNV_EXT_TO_U_MIN_CODE_POINT) 427*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_TO_U_GET_PARTIAL_INDEX(value) (value) 428*0e209d39SAndroid Build Coastguard Worker 429*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_TO_U_IS_ROUNDTRIP(value) (((value)&UCNV_EXT_TO_U_ROUNDTRIP_FLAG)!=0) 430*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_TO_U_MASK_ROUNDTRIP(value) ((value)&~UCNV_EXT_TO_U_ROUNDTRIP_FLAG) 431*0e209d39SAndroid Build Coastguard Worker 432*0e209d39SAndroid Build Coastguard Worker /* use after masking off the roundtrip flag */ 433*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_TO_U_IS_CODE_POINT(value) ((value)<=UCNV_EXT_TO_U_MAX_CODE_POINT) 434*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_TO_U_GET_CODE_POINT(value) ((value)-UCNV_EXT_TO_U_MIN_CODE_POINT) 435*0e209d39SAndroid Build Coastguard Worker 436*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_TO_U_GET_INDEX(value) ((value)&UCNV_EXT_TO_U_INDEX_MASK) 437*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_TO_U_GET_LENGTH(value) (((value)>>UCNV_EXT_TO_U_LENGTH_SHIFT)-UCNV_EXT_TO_U_LENGTH_OFFSET) 438*0e209d39SAndroid Build Coastguard Worker 439*0e209d39SAndroid Build Coastguard Worker /* fromUnicode helpers ------------------------------------------------------ */ 440*0e209d39SAndroid Build Coastguard Worker 441*0e209d39SAndroid Build Coastguard Worker /* most trie constants are shared with ucnvmbcs.h */ 442*0e209d39SAndroid Build Coastguard Worker 443*0e209d39SAndroid Build Coastguard Worker /* see similar utrie.h UTRIE_INDEX_SHIFT and UTRIE_DATA_GRANULARITY */ 444*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_STAGE_2_LEFT_SHIFT 2 445*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_STAGE_3_GRANULARITY 4 446*0e209d39SAndroid Build Coastguard Worker 447*0e209d39SAndroid Build Coastguard Worker /* trie access, returns the stage 3 value=index to stage 3b; s1Index=c>>10 */ 448*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_FROM_U(stage12, stage3, s1Index, c) \ 449*0e209d39SAndroid Build Coastguard Worker (stage3)[ ((int32_t)(stage12)[ (stage12)[s1Index] +(((c)>>4)&0x3f) ]<<UCNV_EXT_STAGE_2_LEFT_SHIFT) +((c)&0xf) ] 450*0e209d39SAndroid Build Coastguard Worker 451*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_FROM_U_LENGTH_SHIFT 24 452*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_FROM_U_ROUNDTRIP_FLAG ((uint32_t)1<<31) 453*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_FROM_U_GOOD_ONE_WAY_FLAG 0x40000000 454*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_FROM_U_STATUS_MASK 0xc0000000 455*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_FROM_U_RESERVED_MASK 0x20000000 456*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_FROM_U_DATA_MASK 0xffffff 457*0e209d39SAndroid Build Coastguard Worker 458*0e209d39SAndroid Build Coastguard Worker /* special value for "no mapping" to <subchar1> (impossible roundtrip to 0 bytes, value 01) */ 459*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_FROM_U_SUBCHAR1 0x80000001 460*0e209d39SAndroid Build Coastguard Worker 461*0e209d39SAndroid Build Coastguard Worker /* at most 3 bytes in the lower part of the value */ 462*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_FROM_U_MAX_DIRECT_LENGTH 3 463*0e209d39SAndroid Build Coastguard Worker 464*0e209d39SAndroid Build Coastguard Worker /* maximum number of indexed bytes */ 465*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_MAX_BYTES 0x1f 466*0e209d39SAndroid Build Coastguard Worker 467*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_FROM_U_IS_PARTIAL(value) (((value)>>UCNV_EXT_FROM_U_LENGTH_SHIFT)==0) 468*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_FROM_U_GET_PARTIAL_INDEX(value) (value) 469*0e209d39SAndroid Build Coastguard Worker 470*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_FROM_U_IS_ROUNDTRIP(value) (((value)&UCNV_EXT_FROM_U_ROUNDTRIP_FLAG)!=0) 471*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_FROM_U_MASK_ROUNDTRIP(value) ((value)&~UCNV_EXT_FROM_U_ROUNDTRIP_FLAG) 472*0e209d39SAndroid Build Coastguard Worker 473*0e209d39SAndroid Build Coastguard Worker /* get length; masks away all other bits */ 474*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_FROM_U_GET_LENGTH(value) (int32_t)(((value)>>UCNV_EXT_FROM_U_LENGTH_SHIFT)&UCNV_EXT_MAX_BYTES) 475*0e209d39SAndroid Build Coastguard Worker 476*0e209d39SAndroid Build Coastguard Worker /* get bytes or bytes index */ 477*0e209d39SAndroid Build Coastguard Worker #define UCNV_EXT_FROM_U_GET_DATA(value) ((value)&UCNV_EXT_FROM_U_DATA_MASK) 478*0e209d39SAndroid Build Coastguard Worker 479*0e209d39SAndroid Build Coastguard Worker #endif 480*0e209d39SAndroid Build Coastguard Worker 481*0e209d39SAndroid Build Coastguard Worker #endif 482