xref: /aosp_15_r20/external/icu/icu4c/source/common/utrie.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
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:  utrie.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: 2001nov08
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 __UTRIE_H__
20*0e209d39SAndroid Build Coastguard Worker #define __UTRIE_H__
21*0e209d39SAndroid Build Coastguard Worker 
22*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
23*0e209d39SAndroid Build Coastguard Worker #include "unicode/utf16.h"
24*0e209d39SAndroid Build Coastguard Worker 
25*0e209d39SAndroid Build Coastguard Worker U_CDECL_BEGIN
26*0e209d39SAndroid Build Coastguard Worker 
27*0e209d39SAndroid Build Coastguard Worker /**
28*0e209d39SAndroid Build Coastguard Worker  * \file
29*0e209d39SAndroid Build Coastguard Worker  *
30*0e209d39SAndroid Build Coastguard Worker  * This is a common implementation of a "folded" trie.
31*0e209d39SAndroid Build Coastguard Worker  * It is a kind of compressed, serializable table of 16- or 32-bit values associated with
32*0e209d39SAndroid Build Coastguard Worker  * Unicode code points (0..0x10ffff).
33*0e209d39SAndroid Build Coastguard Worker  *
34*0e209d39SAndroid Build Coastguard Worker  * This implementation is optimized for getting values while walking forward
35*0e209d39SAndroid Build Coastguard Worker  * through a UTF-16 string.
36*0e209d39SAndroid Build Coastguard Worker  * Therefore, the simplest and fastest access macros are the
37*0e209d39SAndroid Build Coastguard Worker  * _FROM_LEAD() and _FROM_OFFSET_TRAIL() macros.
38*0e209d39SAndroid Build Coastguard Worker  *
39*0e209d39SAndroid Build Coastguard Worker  * The _FROM_BMP() macros are a little more complicated; they get values
40*0e209d39SAndroid Build Coastguard Worker  * even for lead surrogate code _points_, while the _FROM_LEAD() macros
41*0e209d39SAndroid Build Coastguard Worker  * get special "folded" values for lead surrogate code _units_ if
42*0e209d39SAndroid Build Coastguard Worker  * there is relevant data associated with them.
43*0e209d39SAndroid Build Coastguard Worker  * From such a folded value, an offset needs to be extracted to supply
44*0e209d39SAndroid Build Coastguard Worker  * to the _FROM_OFFSET_TRAIL() macros.
45*0e209d39SAndroid Build Coastguard Worker  *
46*0e209d39SAndroid Build Coastguard Worker  * Most of the more complex (and more convenient) functions/macros call a callback function
47*0e209d39SAndroid Build Coastguard Worker  * to get that offset from the folded value for a lead surrogate unit.
48*0e209d39SAndroid Build Coastguard Worker  */
49*0e209d39SAndroid Build Coastguard Worker 
50*0e209d39SAndroid Build Coastguard Worker /**
51*0e209d39SAndroid Build Coastguard Worker  * Trie constants, defining shift widths, index array lengths, etc.
52*0e209d39SAndroid Build Coastguard Worker  */
53*0e209d39SAndroid Build Coastguard Worker enum {
54*0e209d39SAndroid Build Coastguard Worker     /** Shift size for shifting right the input index. 1..9 */
55*0e209d39SAndroid Build Coastguard Worker     UTRIE_SHIFT=5,
56*0e209d39SAndroid Build Coastguard Worker 
57*0e209d39SAndroid Build Coastguard Worker     /** Number of data values in a stage 2 (data array) block. 2, 4, 8, .., 0x200 */
58*0e209d39SAndroid Build Coastguard Worker     UTRIE_DATA_BLOCK_LENGTH=1<<UTRIE_SHIFT,
59*0e209d39SAndroid Build Coastguard Worker 
60*0e209d39SAndroid Build Coastguard Worker     /** Mask for getting the lower bits from the input index. */
61*0e209d39SAndroid Build Coastguard Worker     UTRIE_MASK=UTRIE_DATA_BLOCK_LENGTH-1,
62*0e209d39SAndroid Build Coastguard Worker 
63*0e209d39SAndroid Build Coastguard Worker     /**
64*0e209d39SAndroid Build Coastguard Worker      * Lead surrogate code points' index displacement in the index array.
65*0e209d39SAndroid Build Coastguard Worker      * 0x10000-0xd800=0x2800
66*0e209d39SAndroid Build Coastguard Worker      */
67*0e209d39SAndroid Build Coastguard Worker     UTRIE_LEAD_INDEX_DISP=0x2800>>UTRIE_SHIFT,
68*0e209d39SAndroid Build Coastguard Worker 
69*0e209d39SAndroid Build Coastguard Worker     /**
70*0e209d39SAndroid Build Coastguard Worker      * Shift size for shifting left the index array values.
71*0e209d39SAndroid Build Coastguard Worker      * Increases possible data size with 16-bit index values at the cost
72*0e209d39SAndroid Build Coastguard Worker      * of compactability.
73*0e209d39SAndroid Build Coastguard Worker      * This requires blocks of stage 2 data to be aligned by UTRIE_DATA_GRANULARITY.
74*0e209d39SAndroid Build Coastguard Worker      * 0..UTRIE_SHIFT
75*0e209d39SAndroid Build Coastguard Worker      */
76*0e209d39SAndroid Build Coastguard Worker     UTRIE_INDEX_SHIFT=2,
77*0e209d39SAndroid Build Coastguard Worker 
78*0e209d39SAndroid Build Coastguard Worker     /** The alignment size of a stage 2 data block. Also the granularity for compaction. */
79*0e209d39SAndroid Build Coastguard Worker     UTRIE_DATA_GRANULARITY=1<<UTRIE_INDEX_SHIFT,
80*0e209d39SAndroid Build Coastguard Worker 
81*0e209d39SAndroid Build Coastguard Worker     /** Number of bits of a trail surrogate that are used in index table lookups. */
82*0e209d39SAndroid Build Coastguard Worker     UTRIE_SURROGATE_BLOCK_BITS=10-UTRIE_SHIFT,
83*0e209d39SAndroid Build Coastguard Worker 
84*0e209d39SAndroid Build Coastguard Worker     /**
85*0e209d39SAndroid Build Coastguard Worker      * Number of index (stage 1) entries per lead surrogate.
86*0e209d39SAndroid Build Coastguard Worker      * Same as number of index entries for 1024 trail surrogates,
87*0e209d39SAndroid Build Coastguard Worker      * ==0x400>>UTRIE_SHIFT
88*0e209d39SAndroid Build Coastguard Worker      */
89*0e209d39SAndroid Build Coastguard Worker     UTRIE_SURROGATE_BLOCK_COUNT=(1<<UTRIE_SURROGATE_BLOCK_BITS),
90*0e209d39SAndroid Build Coastguard Worker 
91*0e209d39SAndroid Build Coastguard Worker     /** Length of the BMP portion of the index (stage 1) array. */
92*0e209d39SAndroid Build Coastguard Worker     UTRIE_BMP_INDEX_LENGTH=0x10000>>UTRIE_SHIFT
93*0e209d39SAndroid Build Coastguard Worker };
94*0e209d39SAndroid Build Coastguard Worker 
95*0e209d39SAndroid Build Coastguard Worker /**
96*0e209d39SAndroid Build Coastguard Worker  * Length of the index (stage 1) array before folding.
97*0e209d39SAndroid Build Coastguard Worker  * Maximum number of Unicode code points (0x110000) shifted right by UTRIE_SHIFT.
98*0e209d39SAndroid Build Coastguard Worker  */
99*0e209d39SAndroid Build Coastguard Worker #define UTRIE_MAX_INDEX_LENGTH (0x110000>>UTRIE_SHIFT)
100*0e209d39SAndroid Build Coastguard Worker 
101*0e209d39SAndroid Build Coastguard Worker /**
102*0e209d39SAndroid Build Coastguard Worker  * Maximum length of the runtime data (stage 2) array.
103*0e209d39SAndroid Build Coastguard Worker  * Limited by 16-bit index values that are left-shifted by UTRIE_INDEX_SHIFT.
104*0e209d39SAndroid Build Coastguard Worker  */
105*0e209d39SAndroid Build Coastguard Worker #define UTRIE_MAX_DATA_LENGTH (0x10000<<UTRIE_INDEX_SHIFT)
106*0e209d39SAndroid Build Coastguard Worker 
107*0e209d39SAndroid Build Coastguard Worker /**
108*0e209d39SAndroid Build Coastguard Worker  * Maximum length of the build-time data (stage 2) array.
109*0e209d39SAndroid Build Coastguard Worker  * The maximum length is 0x110000+UTRIE_DATA_BLOCK_LENGTH+0x400.
110*0e209d39SAndroid Build Coastguard Worker  * (Number of Unicode code points + one all-initial-value block +
111*0e209d39SAndroid Build Coastguard Worker  *  possible duplicate entries for 1024 lead surrogates.)
112*0e209d39SAndroid Build Coastguard Worker  */
113*0e209d39SAndroid Build Coastguard Worker #define UTRIE_MAX_BUILD_TIME_DATA_LENGTH (0x110000+UTRIE_DATA_BLOCK_LENGTH+0x400)
114*0e209d39SAndroid Build Coastguard Worker 
115*0e209d39SAndroid Build Coastguard Worker /**
116*0e209d39SAndroid Build Coastguard Worker  * Number of bytes for a dummy trie.
117*0e209d39SAndroid Build Coastguard Worker  * A dummy trie is an empty runtime trie, used when a real data trie cannot
118*0e209d39SAndroid Build Coastguard Worker  * be loaded.
119*0e209d39SAndroid Build Coastguard Worker  * The number of bytes works for Latin-1-linear tries with 32-bit data
120*0e209d39SAndroid Build Coastguard Worker  * (worst case).
121*0e209d39SAndroid Build Coastguard Worker  *
122*0e209d39SAndroid Build Coastguard Worker  * Calculation:
123*0e209d39SAndroid Build Coastguard Worker  *   BMP index + 1 index block for lead surrogate code points +
124*0e209d39SAndroid Build Coastguard Worker  *   Latin-1-linear array + 1 data block for lead surrogate code points
125*0e209d39SAndroid Build Coastguard Worker  *
126*0e209d39SAndroid Build Coastguard Worker  * Latin-1: if(UTRIE_SHIFT<=8) { 256 } else { included in first data block }
127*0e209d39SAndroid Build Coastguard Worker  *
128*0e209d39SAndroid Build Coastguard Worker  * @see utrie_unserializeDummy
129*0e209d39SAndroid Build Coastguard Worker  */
130*0e209d39SAndroid Build Coastguard Worker #define UTRIE_DUMMY_SIZE ((UTRIE_BMP_INDEX_LENGTH+UTRIE_SURROGATE_BLOCK_COUNT)*2+(UTRIE_SHIFT<=8?256:UTRIE_DATA_BLOCK_LENGTH)*4+UTRIE_DATA_BLOCK_LENGTH*4)
131*0e209d39SAndroid Build Coastguard Worker 
132*0e209d39SAndroid Build Coastguard Worker /**
133*0e209d39SAndroid Build Coastguard Worker  * Runtime UTrie callback function.
134*0e209d39SAndroid Build Coastguard Worker  * Extract from a lead surrogate's data the
135*0e209d39SAndroid Build Coastguard Worker  * index array offset of the indexes for that lead surrogate.
136*0e209d39SAndroid Build Coastguard Worker  *
137*0e209d39SAndroid Build Coastguard Worker  * @param data data value for a surrogate from the trie, including the folding offset
138*0e209d39SAndroid Build Coastguard Worker  * @return offset>=UTRIE_BMP_INDEX_LENGTH, or 0 if there is no data for the lead surrogate
139*0e209d39SAndroid Build Coastguard Worker  */
140*0e209d39SAndroid Build Coastguard Worker typedef int32_t U_CALLCONV
141*0e209d39SAndroid Build Coastguard Worker UTrieGetFoldingOffset(uint32_t data);
142*0e209d39SAndroid Build Coastguard Worker 
143*0e209d39SAndroid Build Coastguard Worker /**
144*0e209d39SAndroid Build Coastguard Worker  * Run-time Trie structure.
145*0e209d39SAndroid Build Coastguard Worker  *
146*0e209d39SAndroid Build Coastguard Worker  * Either the data table is 16 bits wide and accessed via the index
147*0e209d39SAndroid Build Coastguard Worker  * pointer, with each index item increased by indexLength;
148*0e209d39SAndroid Build Coastguard Worker  * in this case, data32==NULL.
149*0e209d39SAndroid Build Coastguard Worker  *
150*0e209d39SAndroid Build Coastguard Worker  * Or the data table is 32 bits wide and accessed via the data32 pointer.
151*0e209d39SAndroid Build Coastguard Worker  */
152*0e209d39SAndroid Build Coastguard Worker struct UTrie {
153*0e209d39SAndroid Build Coastguard Worker     const uint16_t *index;
154*0e209d39SAndroid Build Coastguard Worker     const uint32_t *data32; /* NULL if 16b data is used via index */
155*0e209d39SAndroid Build Coastguard Worker 
156*0e209d39SAndroid Build Coastguard Worker     /**
157*0e209d39SAndroid Build Coastguard Worker      * This function is not used in _FROM_LEAD, _FROM_BMP, and _FROM_OFFSET_TRAIL macros.
158*0e209d39SAndroid Build Coastguard Worker      * If convenience macros like _GET16 or _NEXT32 are used, this function must be set.
159*0e209d39SAndroid Build Coastguard Worker      *
160*0e209d39SAndroid Build Coastguard Worker      * utrie_unserialize() sets a default function which simply returns
161*0e209d39SAndroid Build Coastguard Worker      * the lead surrogate's value itself - which is the inverse of the default
162*0e209d39SAndroid Build Coastguard Worker      * folding function used by utrie_serialize().
163*0e209d39SAndroid Build Coastguard Worker      *
164*0e209d39SAndroid Build Coastguard Worker      * @see UTrieGetFoldingOffset
165*0e209d39SAndroid Build Coastguard Worker      */
166*0e209d39SAndroid Build Coastguard Worker     UTrieGetFoldingOffset *getFoldingOffset;
167*0e209d39SAndroid Build Coastguard Worker 
168*0e209d39SAndroid Build Coastguard Worker     int32_t indexLength, dataLength;
169*0e209d39SAndroid Build Coastguard Worker     uint32_t initialValue;
170*0e209d39SAndroid Build Coastguard Worker     UBool isLatin1Linear;
171*0e209d39SAndroid Build Coastguard Worker };
172*0e209d39SAndroid Build Coastguard Worker 
173*0e209d39SAndroid Build Coastguard Worker #ifndef __UTRIE2_H__
174*0e209d39SAndroid Build Coastguard Worker typedef struct UTrie UTrie;
175*0e209d39SAndroid Build Coastguard Worker #endif
176*0e209d39SAndroid Build Coastguard Worker 
177*0e209d39SAndroid Build Coastguard Worker /** Internal trie getter from an offset (0 if c16 is a BMP/lead units) and a 16-bit unit */
178*0e209d39SAndroid Build Coastguard Worker #define _UTRIE_GET_RAW(trie, data, offset, c16) \
179*0e209d39SAndroid Build Coastguard Worker     (trie)->data[ \
180*0e209d39SAndroid Build Coastguard Worker         ((int32_t)((trie)->index[(offset)+((c16)>>UTRIE_SHIFT)])<<UTRIE_INDEX_SHIFT)+ \
181*0e209d39SAndroid Build Coastguard Worker         ((c16)&UTRIE_MASK) \
182*0e209d39SAndroid Build Coastguard Worker     ]
183*0e209d39SAndroid Build Coastguard Worker 
184*0e209d39SAndroid Build Coastguard Worker /** Internal trie getter from a pair of surrogates */
185*0e209d39SAndroid Build Coastguard Worker #define _UTRIE_GET_FROM_PAIR(trie, data, c, c2, result, resultType) UPRV_BLOCK_MACRO_BEGIN { \
186*0e209d39SAndroid Build Coastguard Worker     int32_t __offset; \
187*0e209d39SAndroid Build Coastguard Worker \
188*0e209d39SAndroid Build Coastguard Worker     /* get data for lead surrogate */ \
189*0e209d39SAndroid Build Coastguard Worker     (result)=_UTRIE_GET_RAW((trie), data, 0, (c)); \
190*0e209d39SAndroid Build Coastguard Worker     __offset=(trie)->getFoldingOffset(result); \
191*0e209d39SAndroid Build Coastguard Worker \
192*0e209d39SAndroid Build Coastguard Worker     /* get the real data from the folded lead/trail units */ \
193*0e209d39SAndroid Build Coastguard Worker     if(__offset>0) { \
194*0e209d39SAndroid Build Coastguard Worker         (result)=_UTRIE_GET_RAW((trie), data, __offset, (c2)&0x3ff); \
195*0e209d39SAndroid Build Coastguard Worker     } else { \
196*0e209d39SAndroid Build Coastguard Worker         (result)=(resultType)((trie)->initialValue); \
197*0e209d39SAndroid Build Coastguard Worker     } \
198*0e209d39SAndroid Build Coastguard Worker } UPRV_BLOCK_MACRO_END
199*0e209d39SAndroid Build Coastguard Worker 
200*0e209d39SAndroid Build Coastguard Worker /** Internal trie getter from a BMP code point, treating a lead surrogate as a normal code point */
201*0e209d39SAndroid Build Coastguard Worker #define _UTRIE_GET_FROM_BMP(trie, data, c16) \
202*0e209d39SAndroid Build Coastguard Worker     _UTRIE_GET_RAW(trie, data, 0xd800<=(c16) && (c16)<=0xdbff ? UTRIE_LEAD_INDEX_DISP : 0, c16)
203*0e209d39SAndroid Build Coastguard Worker 
204*0e209d39SAndroid Build Coastguard Worker /**
205*0e209d39SAndroid Build Coastguard Worker  * Internal trie getter from a code point.
206*0e209d39SAndroid Build Coastguard Worker  * Could be faster(?) but longer with
207*0e209d39SAndroid Build Coastguard Worker  *   if((c32)<=0xd7ff) { (result)=_UTRIE_GET_RAW(trie, data, 0, c32); }
208*0e209d39SAndroid Build Coastguard Worker  */
209*0e209d39SAndroid Build Coastguard Worker #define _UTRIE_GET(trie, data, c32, result, resultType) UPRV_BLOCK_MACRO_BEGIN { \
210*0e209d39SAndroid Build Coastguard Worker     if((uint32_t)(c32)<=0xffff) { \
211*0e209d39SAndroid Build Coastguard Worker         /* BMP code points */ \
212*0e209d39SAndroid Build Coastguard Worker         (result)=_UTRIE_GET_FROM_BMP(trie, data, c32); \
213*0e209d39SAndroid Build Coastguard Worker     } else if((uint32_t)(c32)<=0x10ffff) { \
214*0e209d39SAndroid Build Coastguard Worker         /* supplementary code point */ \
215*0e209d39SAndroid Build Coastguard Worker         UChar __lead16=U16_LEAD(c32); \
216*0e209d39SAndroid Build Coastguard Worker         _UTRIE_GET_FROM_PAIR(trie, data, __lead16, c32, result, resultType); \
217*0e209d39SAndroid Build Coastguard Worker     } else { \
218*0e209d39SAndroid Build Coastguard Worker         /* out of range */ \
219*0e209d39SAndroid Build Coastguard Worker         (result)=(resultType)((trie)->initialValue); \
220*0e209d39SAndroid Build Coastguard Worker     } \
221*0e209d39SAndroid Build Coastguard Worker } UPRV_BLOCK_MACRO_END
222*0e209d39SAndroid Build Coastguard Worker 
223*0e209d39SAndroid Build Coastguard Worker /** Internal next-post-increment: get the next code point (c, c2) and its data */
224*0e209d39SAndroid Build Coastguard Worker #define _UTRIE_NEXT(trie, data, src, limit, c, c2, result, resultType) UPRV_BLOCK_MACRO_BEGIN { \
225*0e209d39SAndroid Build Coastguard Worker     (c)=*(src)++; \
226*0e209d39SAndroid Build Coastguard Worker     if(!U16_IS_LEAD(c)) { \
227*0e209d39SAndroid Build Coastguard Worker         (c2)=0; \
228*0e209d39SAndroid Build Coastguard Worker         (result)=_UTRIE_GET_RAW((trie), data, 0, (c)); \
229*0e209d39SAndroid Build Coastguard Worker     } else if((src)!=(limit) && U16_IS_TRAIL((c2)=*(src))) { \
230*0e209d39SAndroid Build Coastguard Worker         ++(src); \
231*0e209d39SAndroid Build Coastguard Worker         _UTRIE_GET_FROM_PAIR((trie), data, (c), (c2), (result), resultType); \
232*0e209d39SAndroid Build Coastguard Worker     } else { \
233*0e209d39SAndroid Build Coastguard Worker         /* unpaired lead surrogate code point */ \
234*0e209d39SAndroid Build Coastguard Worker         (c2)=0; \
235*0e209d39SAndroid Build Coastguard Worker         (result)=_UTRIE_GET_RAW((trie), data, UTRIE_LEAD_INDEX_DISP, (c)); \
236*0e209d39SAndroid Build Coastguard Worker     } \
237*0e209d39SAndroid Build Coastguard Worker } UPRV_BLOCK_MACRO_END
238*0e209d39SAndroid Build Coastguard Worker 
239*0e209d39SAndroid Build Coastguard Worker /** Internal previous: get the previous code point (c, c2) and its data */
240*0e209d39SAndroid Build Coastguard Worker #define _UTRIE_PREVIOUS(trie, data, start, src, c, c2, result, resultType) UPRV_BLOCK_MACRO_BEGIN { \
241*0e209d39SAndroid Build Coastguard Worker     (c)=*--(src); \
242*0e209d39SAndroid Build Coastguard Worker     if(!U16_IS_SURROGATE(c)) { \
243*0e209d39SAndroid Build Coastguard Worker         (c2)=0; \
244*0e209d39SAndroid Build Coastguard Worker         (result)=_UTRIE_GET_RAW((trie), data, 0, (c)); \
245*0e209d39SAndroid Build Coastguard Worker     } else if(!U16_IS_SURROGATE_LEAD(c)) { \
246*0e209d39SAndroid Build Coastguard Worker         /* trail surrogate */ \
247*0e209d39SAndroid Build Coastguard Worker         if((start)!=(src) && U16_IS_LEAD((c2)=*((src)-1))) { \
248*0e209d39SAndroid Build Coastguard Worker             --(src); \
249*0e209d39SAndroid Build Coastguard Worker             (result)=(c); (c)=(c2); (c2)=(UChar)(result); /* swap c, c2 */ \
250*0e209d39SAndroid Build Coastguard Worker             _UTRIE_GET_FROM_PAIR((trie), data, (c), (c2), (result), resultType); \
251*0e209d39SAndroid Build Coastguard Worker         } else { \
252*0e209d39SAndroid Build Coastguard Worker             /* unpaired trail surrogate code point */ \
253*0e209d39SAndroid Build Coastguard Worker             (c2)=0; \
254*0e209d39SAndroid Build Coastguard Worker             (result)=_UTRIE_GET_RAW((trie), data, 0, (c)); \
255*0e209d39SAndroid Build Coastguard Worker         } \
256*0e209d39SAndroid Build Coastguard Worker     } else { \
257*0e209d39SAndroid Build Coastguard Worker         /* unpaired lead surrogate code point */ \
258*0e209d39SAndroid Build Coastguard Worker         (c2)=0; \
259*0e209d39SAndroid Build Coastguard Worker         (result)=_UTRIE_GET_RAW((trie), data, UTRIE_LEAD_INDEX_DISP, (c)); \
260*0e209d39SAndroid Build Coastguard Worker     } \
261*0e209d39SAndroid Build Coastguard Worker } UPRV_BLOCK_MACRO_END
262*0e209d39SAndroid Build Coastguard Worker 
263*0e209d39SAndroid Build Coastguard Worker /* Public UTrie API ---------------------------------------------------------*/
264*0e209d39SAndroid Build Coastguard Worker 
265*0e209d39SAndroid Build Coastguard Worker /**
266*0e209d39SAndroid Build Coastguard Worker  * Get a pointer to the contiguous part of the data array
267*0e209d39SAndroid Build Coastguard Worker  * for the Latin-1 range (U+0000..U+00ff).
268*0e209d39SAndroid Build Coastguard Worker  * Must be used only if the Latin-1 range is in fact linear
269*0e209d39SAndroid Build Coastguard Worker  * (trie->isLatin1Linear).
270*0e209d39SAndroid Build Coastguard Worker  *
271*0e209d39SAndroid Build Coastguard Worker  * @param trie (const UTrie *, in) a pointer to the runtime trie structure
272*0e209d39SAndroid Build Coastguard Worker  * @return (const uint16_t *) pointer to values for Latin-1 code points
273*0e209d39SAndroid Build Coastguard Worker  */
274*0e209d39SAndroid Build Coastguard Worker #define UTRIE_GET16_LATIN1(trie) ((trie)->index+(trie)->indexLength+UTRIE_DATA_BLOCK_LENGTH)
275*0e209d39SAndroid Build Coastguard Worker 
276*0e209d39SAndroid Build Coastguard Worker /**
277*0e209d39SAndroid Build Coastguard Worker  * Get a pointer to the contiguous part of the data array
278*0e209d39SAndroid Build Coastguard Worker  * for the Latin-1 range (U+0000..U+00ff).
279*0e209d39SAndroid Build Coastguard Worker  * Must be used only if the Latin-1 range is in fact linear
280*0e209d39SAndroid Build Coastguard Worker  * (trie->isLatin1Linear).
281*0e209d39SAndroid Build Coastguard Worker  *
282*0e209d39SAndroid Build Coastguard Worker  * @param trie (const UTrie *, in) a pointer to the runtime trie structure
283*0e209d39SAndroid Build Coastguard Worker  * @return (const uint32_t *) pointer to values for Latin-1 code points
284*0e209d39SAndroid Build Coastguard Worker  */
285*0e209d39SAndroid Build Coastguard Worker #define UTRIE_GET32_LATIN1(trie) ((trie)->data32+UTRIE_DATA_BLOCK_LENGTH)
286*0e209d39SAndroid Build Coastguard Worker 
287*0e209d39SAndroid Build Coastguard Worker /**
288*0e209d39SAndroid Build Coastguard Worker  * Get a 16-bit trie value from a BMP code point (UChar, <=U+ffff).
289*0e209d39SAndroid Build Coastguard Worker  * c16 may be a lead surrogate, which may have a value including a folding offset.
290*0e209d39SAndroid Build Coastguard Worker  *
291*0e209d39SAndroid Build Coastguard Worker  * @param trie (const UTrie *, in) a pointer to the runtime trie structure
292*0e209d39SAndroid Build Coastguard Worker  * @param c16 (UChar, in) the input BMP code point
293*0e209d39SAndroid Build Coastguard Worker  * @return (uint16_t) trie lookup result
294*0e209d39SAndroid Build Coastguard Worker  */
295*0e209d39SAndroid Build Coastguard Worker #define UTRIE_GET16_FROM_LEAD(trie, c16) _UTRIE_GET_RAW(trie, index, 0, c16)
296*0e209d39SAndroid Build Coastguard Worker 
297*0e209d39SAndroid Build Coastguard Worker /**
298*0e209d39SAndroid Build Coastguard Worker  * Get a 32-bit trie value from a BMP code point (UChar, <=U+ffff).
299*0e209d39SAndroid Build Coastguard Worker  * c16 may be a lead surrogate, which may have a value including a folding offset.
300*0e209d39SAndroid Build Coastguard Worker  *
301*0e209d39SAndroid Build Coastguard Worker  * @param trie (const UTrie *, in) a pointer to the runtime trie structure
302*0e209d39SAndroid Build Coastguard Worker  * @param c16 (UChar, in) the input BMP code point
303*0e209d39SAndroid Build Coastguard Worker  * @return (uint32_t) trie lookup result
304*0e209d39SAndroid Build Coastguard Worker  */
305*0e209d39SAndroid Build Coastguard Worker #define UTRIE_GET32_FROM_LEAD(trie, c16) _UTRIE_GET_RAW(trie, data32, 0, c16)
306*0e209d39SAndroid Build Coastguard Worker 
307*0e209d39SAndroid Build Coastguard Worker /**
308*0e209d39SAndroid Build Coastguard Worker  * Get a 16-bit trie value from a BMP code point (UChar, <=U+ffff).
309*0e209d39SAndroid Build Coastguard Worker  * Even lead surrogate code points are treated as normal code points,
310*0e209d39SAndroid Build Coastguard Worker  * with unfolded values that may differ from _FROM_LEAD() macro results for them.
311*0e209d39SAndroid Build Coastguard Worker  *
312*0e209d39SAndroid Build Coastguard Worker  * @param trie (const UTrie *, in) a pointer to the runtime trie structure
313*0e209d39SAndroid Build Coastguard Worker  * @param c16 (UChar, in) the input BMP code point
314*0e209d39SAndroid Build Coastguard Worker  * @return (uint16_t) trie lookup result
315*0e209d39SAndroid Build Coastguard Worker  */
316*0e209d39SAndroid Build Coastguard Worker #define UTRIE_GET16_FROM_BMP(trie, c16) _UTRIE_GET_FROM_BMP(trie, index, c16)
317*0e209d39SAndroid Build Coastguard Worker 
318*0e209d39SAndroid Build Coastguard Worker /**
319*0e209d39SAndroid Build Coastguard Worker  * Get a 32-bit trie value from a BMP code point (UChar, <=U+ffff).
320*0e209d39SAndroid Build Coastguard Worker  * Even lead surrogate code points are treated as normal code points,
321*0e209d39SAndroid Build Coastguard Worker  * with unfolded values that may differ from _FROM_LEAD() macro results for them.
322*0e209d39SAndroid Build Coastguard Worker  *
323*0e209d39SAndroid Build Coastguard Worker  * @param trie (const UTrie *, in) a pointer to the runtime trie structure
324*0e209d39SAndroid Build Coastguard Worker  * @param c16 (UChar, in) the input BMP code point
325*0e209d39SAndroid Build Coastguard Worker  * @return (uint32_t) trie lookup result
326*0e209d39SAndroid Build Coastguard Worker  */
327*0e209d39SAndroid Build Coastguard Worker #define UTRIE_GET32_FROM_BMP(trie, c16) _UTRIE_GET_FROM_BMP(trie, data32, c16)
328*0e209d39SAndroid Build Coastguard Worker 
329*0e209d39SAndroid Build Coastguard Worker /**
330*0e209d39SAndroid Build Coastguard Worker  * Get a 16-bit trie value from a code point.
331*0e209d39SAndroid Build Coastguard Worker  * Even lead surrogate code points are treated as normal code points,
332*0e209d39SAndroid Build Coastguard Worker  * with unfolded values that may differ from _FROM_LEAD() macro results for them.
333*0e209d39SAndroid Build Coastguard Worker  *
334*0e209d39SAndroid Build Coastguard Worker  * @param trie (const UTrie *, in) a pointer to the runtime trie structure
335*0e209d39SAndroid Build Coastguard Worker  * @param c32 (UChar32, in) the input code point
336*0e209d39SAndroid Build Coastguard Worker  * @param result (uint16_t, out) uint16_t variable for the trie lookup result
337*0e209d39SAndroid Build Coastguard Worker  */
338*0e209d39SAndroid Build Coastguard Worker #define UTRIE_GET16(trie, c32, result) _UTRIE_GET(trie, index, c32, result, uint16_t)
339*0e209d39SAndroid Build Coastguard Worker 
340*0e209d39SAndroid Build Coastguard Worker /**
341*0e209d39SAndroid Build Coastguard Worker  * Get a 32-bit trie value from a code point.
342*0e209d39SAndroid Build Coastguard Worker  * Even lead surrogate code points are treated as normal code points,
343*0e209d39SAndroid Build Coastguard Worker  * with unfolded values that may differ from _FROM_LEAD() macro results for them.
344*0e209d39SAndroid Build Coastguard Worker  *
345*0e209d39SAndroid Build Coastguard Worker  * @param trie (const UTrie *, in) a pointer to the runtime trie structure
346*0e209d39SAndroid Build Coastguard Worker  * @param c32 (UChar32, in) the input code point
347*0e209d39SAndroid Build Coastguard Worker  * @param result (uint32_t, out) uint32_t variable for the trie lookup result
348*0e209d39SAndroid Build Coastguard Worker  */
349*0e209d39SAndroid Build Coastguard Worker #define UTRIE_GET32(trie, c32, result) _UTRIE_GET(trie, data32, c32, result, uint32_t)
350*0e209d39SAndroid Build Coastguard Worker 
351*0e209d39SAndroid Build Coastguard Worker /**
352*0e209d39SAndroid Build Coastguard Worker  * Get the next code point (c, c2), post-increment src,
353*0e209d39SAndroid Build Coastguard Worker  * and get a 16-bit value from the trie.
354*0e209d39SAndroid Build Coastguard Worker  *
355*0e209d39SAndroid Build Coastguard Worker  * @param trie (const UTrie *, in) a pointer to the runtime trie structure
356*0e209d39SAndroid Build Coastguard Worker  * @param src (const UChar *, in/out) the source text pointer
357*0e209d39SAndroid Build Coastguard Worker  * @param limit (const UChar *, in) the limit pointer for the text, or NULL
358*0e209d39SAndroid Build Coastguard Worker  * @param c (UChar, out) variable for the BMP or lead code unit
359*0e209d39SAndroid Build Coastguard Worker  * @param c2 (UChar, out) variable for 0 or the trail code unit
360*0e209d39SAndroid Build Coastguard Worker  * @param result (uint16_t, out) uint16_t variable for the trie lookup result
361*0e209d39SAndroid Build Coastguard Worker  */
362*0e209d39SAndroid Build Coastguard Worker #define UTRIE_NEXT16(trie, src, limit, c, c2, result) _UTRIE_NEXT(trie, index, src, limit, c, c2, result, uint16_t)
363*0e209d39SAndroid Build Coastguard Worker 
364*0e209d39SAndroid Build Coastguard Worker /**
365*0e209d39SAndroid Build Coastguard Worker  * Get the next code point (c, c2), post-increment src,
366*0e209d39SAndroid Build Coastguard Worker  * and get a 32-bit value from the trie.
367*0e209d39SAndroid Build Coastguard Worker  *
368*0e209d39SAndroid Build Coastguard Worker  * @param trie (const UTrie *, in) a pointer to the runtime trie structure
369*0e209d39SAndroid Build Coastguard Worker  * @param src (const UChar *, in/out) the source text pointer
370*0e209d39SAndroid Build Coastguard Worker  * @param limit (const UChar *, in) the limit pointer for the text, or NULL
371*0e209d39SAndroid Build Coastguard Worker  * @param c (UChar, out) variable for the BMP or lead code unit
372*0e209d39SAndroid Build Coastguard Worker  * @param c2 (UChar, out) variable for 0 or the trail code unit
373*0e209d39SAndroid Build Coastguard Worker  * @param result (uint32_t, out) uint32_t variable for the trie lookup result
374*0e209d39SAndroid Build Coastguard Worker  */
375*0e209d39SAndroid Build Coastguard Worker #define UTRIE_NEXT32(trie, src, limit, c, c2, result) _UTRIE_NEXT(trie, data32, src, limit, c, c2, result, uint32_t)
376*0e209d39SAndroid Build Coastguard Worker 
377*0e209d39SAndroid Build Coastguard Worker /**
378*0e209d39SAndroid Build Coastguard Worker  * Get the previous code point (c, c2), pre-decrement src,
379*0e209d39SAndroid Build Coastguard Worker  * and get a 16-bit value from the trie.
380*0e209d39SAndroid Build Coastguard Worker  *
381*0e209d39SAndroid Build Coastguard Worker  * @param trie (const UTrie *, in) a pointer to the runtime trie structure
382*0e209d39SAndroid Build Coastguard Worker  * @param start (const UChar *, in) the start pointer for the text, or NULL
383*0e209d39SAndroid Build Coastguard Worker  * @param src (const UChar *, in/out) the source text pointer
384*0e209d39SAndroid Build Coastguard Worker  * @param c (UChar, out) variable for the BMP or lead code unit
385*0e209d39SAndroid Build Coastguard Worker  * @param c2 (UChar, out) variable for 0 or the trail code unit
386*0e209d39SAndroid Build Coastguard Worker  * @param result (uint16_t, out) uint16_t variable for the trie lookup result
387*0e209d39SAndroid Build Coastguard Worker  */
388*0e209d39SAndroid Build Coastguard Worker #define UTRIE_PREVIOUS16(trie, start, src, c, c2, result) _UTRIE_PREVIOUS(trie, index, start, src, c, c2, result, uint16_t)
389*0e209d39SAndroid Build Coastguard Worker 
390*0e209d39SAndroid Build Coastguard Worker /**
391*0e209d39SAndroid Build Coastguard Worker  * Get the previous code point (c, c2), pre-decrement src,
392*0e209d39SAndroid Build Coastguard Worker  * and get a 32-bit value from the trie.
393*0e209d39SAndroid Build Coastguard Worker  *
394*0e209d39SAndroid Build Coastguard Worker  * @param trie (const UTrie *, in) a pointer to the runtime trie structure
395*0e209d39SAndroid Build Coastguard Worker  * @param start (const UChar *, in) the start pointer for the text, or NULL
396*0e209d39SAndroid Build Coastguard Worker  * @param src (const UChar *, in/out) the source text pointer
397*0e209d39SAndroid Build Coastguard Worker  * @param c (UChar, out) variable for the BMP or lead code unit
398*0e209d39SAndroid Build Coastguard Worker  * @param c2 (UChar, out) variable for 0 or the trail code unit
399*0e209d39SAndroid Build Coastguard Worker  * @param result (uint32_t, out) uint32_t variable for the trie lookup result
400*0e209d39SAndroid Build Coastguard Worker  */
401*0e209d39SAndroid Build Coastguard Worker #define UTRIE_PREVIOUS32(trie, start, src, c, c2, result) _UTRIE_PREVIOUS(trie, data32, start, src, c, c2, result, uint32_t)
402*0e209d39SAndroid Build Coastguard Worker 
403*0e209d39SAndroid Build Coastguard Worker /**
404*0e209d39SAndroid Build Coastguard Worker  * Get a 16-bit trie value from a pair of surrogates.
405*0e209d39SAndroid Build Coastguard Worker  *
406*0e209d39SAndroid Build Coastguard Worker  * @param trie (const UTrie *, in) a pointer to the runtime trie structure
407*0e209d39SAndroid Build Coastguard Worker  * @param c (UChar, in) a lead surrogate
408*0e209d39SAndroid Build Coastguard Worker  * @param c2 (UChar, in) a trail surrogate
409*0e209d39SAndroid Build Coastguard Worker  * @param result (uint16_t, out) uint16_t variable for the trie lookup result
410*0e209d39SAndroid Build Coastguard Worker  */
411*0e209d39SAndroid Build Coastguard Worker #define UTRIE_GET16_FROM_PAIR(trie, c, c2, result) _UTRIE_GET_FROM_PAIR(trie, index, c, c2, result, uint16_t)
412*0e209d39SAndroid Build Coastguard Worker 
413*0e209d39SAndroid Build Coastguard Worker /**
414*0e209d39SAndroid Build Coastguard Worker  * Get a 32-bit trie value from a pair of surrogates.
415*0e209d39SAndroid Build Coastguard Worker  *
416*0e209d39SAndroid Build Coastguard Worker  * @param trie (const UTrie *, in) a pointer to the runtime trie structure
417*0e209d39SAndroid Build Coastguard Worker  * @param c (UChar, in) a lead surrogate
418*0e209d39SAndroid Build Coastguard Worker  * @param c2 (UChar, in) a trail surrogate
419*0e209d39SAndroid Build Coastguard Worker  * @param result (uint32_t, out) uint32_t variable for the trie lookup result
420*0e209d39SAndroid Build Coastguard Worker  */
421*0e209d39SAndroid Build Coastguard Worker #define UTRIE_GET32_FROM_PAIR(trie, c, c2, result) _UTRIE_GET_FROM_PAIR(trie, data32, c, c2, result, uint32_t)
422*0e209d39SAndroid Build Coastguard Worker 
423*0e209d39SAndroid Build Coastguard Worker /**
424*0e209d39SAndroid Build Coastguard Worker  * Get a 16-bit trie value from a folding offset (from the value of a lead surrogate)
425*0e209d39SAndroid Build Coastguard Worker  * and a trail surrogate.
426*0e209d39SAndroid Build Coastguard Worker  *
427*0e209d39SAndroid Build Coastguard Worker  * @param trie (const UTrie *, in) a pointer to the runtime trie structure
428*0e209d39SAndroid Build Coastguard Worker  * @param offset (int32_t, in) the folding offset from the value of a lead surrogate
429*0e209d39SAndroid Build Coastguard Worker  * @param c2 (UChar, in) a trail surrogate (only the 10 low bits are significant)
430*0e209d39SAndroid Build Coastguard Worker  * @return (uint16_t) trie lookup result
431*0e209d39SAndroid Build Coastguard Worker  */
432*0e209d39SAndroid Build Coastguard Worker #define UTRIE_GET16_FROM_OFFSET_TRAIL(trie, offset, c2) _UTRIE_GET_RAW(trie, index, offset, (c2)&0x3ff)
433*0e209d39SAndroid Build Coastguard Worker 
434*0e209d39SAndroid Build Coastguard Worker /**
435*0e209d39SAndroid Build Coastguard Worker  * Get a 32-bit trie value from a folding offset (from the value of a lead surrogate)
436*0e209d39SAndroid Build Coastguard Worker  * and a trail surrogate.
437*0e209d39SAndroid Build Coastguard Worker  *
438*0e209d39SAndroid Build Coastguard Worker  * @param trie (const UTrie *, in) a pointer to the runtime trie structure
439*0e209d39SAndroid Build Coastguard Worker  * @param offset (int32_t, in) the folding offset from the value of a lead surrogate
440*0e209d39SAndroid Build Coastguard Worker  * @param c2 (UChar, in) a trail surrogate (only the 10 low bits are significant)
441*0e209d39SAndroid Build Coastguard Worker  * @return (uint32_t) trie lookup result
442*0e209d39SAndroid Build Coastguard Worker  */
443*0e209d39SAndroid Build Coastguard Worker #define UTRIE_GET32_FROM_OFFSET_TRAIL(trie, offset, c2) _UTRIE_GET_RAW(trie, data32, offset, (c2)&0x3ff)
444*0e209d39SAndroid Build Coastguard Worker 
445*0e209d39SAndroid Build Coastguard Worker /* enumeration callback types */
446*0e209d39SAndroid Build Coastguard Worker 
447*0e209d39SAndroid Build Coastguard Worker /**
448*0e209d39SAndroid Build Coastguard Worker  * Callback from utrie_enum(), extracts a uint32_t value from a
449*0e209d39SAndroid Build Coastguard Worker  * trie value. This value will be passed on to the UTrieEnumRange function.
450*0e209d39SAndroid Build Coastguard Worker  *
451*0e209d39SAndroid Build Coastguard Worker  * @param context an opaque pointer, as passed into utrie_enum()
452*0e209d39SAndroid Build Coastguard Worker  * @param value a value from the trie
453*0e209d39SAndroid Build Coastguard Worker  * @return the value that is to be passed on to the UTrieEnumRange function
454*0e209d39SAndroid Build Coastguard Worker  */
455*0e209d39SAndroid Build Coastguard Worker typedef uint32_t U_CALLCONV
456*0e209d39SAndroid Build Coastguard Worker UTrieEnumValue(const void *context, uint32_t value);
457*0e209d39SAndroid Build Coastguard Worker 
458*0e209d39SAndroid Build Coastguard Worker /**
459*0e209d39SAndroid Build Coastguard Worker  * Callback from utrie_enum(), is called for each contiguous range
460*0e209d39SAndroid Build Coastguard Worker  * of code points with the same value as retrieved from the trie and
461*0e209d39SAndroid Build Coastguard Worker  * transformed by the UTrieEnumValue function.
462*0e209d39SAndroid Build Coastguard Worker  *
463*0e209d39SAndroid Build Coastguard Worker  * The callback function can stop the enumeration by returning false.
464*0e209d39SAndroid Build Coastguard Worker  *
465*0e209d39SAndroid Build Coastguard Worker  * @param context an opaque pointer, as passed into utrie_enum()
466*0e209d39SAndroid Build Coastguard Worker  * @param start the first code point in a contiguous range with value
467*0e209d39SAndroid Build Coastguard Worker  * @param limit one past the last code point in a contiguous range with value
468*0e209d39SAndroid Build Coastguard Worker  * @param value the value that is set for all code points in [start..limit[
469*0e209d39SAndroid Build Coastguard Worker  * @return false to stop the enumeration
470*0e209d39SAndroid Build Coastguard Worker  */
471*0e209d39SAndroid Build Coastguard Worker typedef UBool U_CALLCONV
472*0e209d39SAndroid Build Coastguard Worker UTrieEnumRange(const void *context, UChar32 start, UChar32 limit, uint32_t value);
473*0e209d39SAndroid Build Coastguard Worker 
474*0e209d39SAndroid Build Coastguard Worker /**
475*0e209d39SAndroid Build Coastguard Worker  * Enumerate efficiently all values in a trie.
476*0e209d39SAndroid Build Coastguard Worker  * For each entry in the trie, the value to be delivered is passed through
477*0e209d39SAndroid Build Coastguard Worker  * the UTrieEnumValue function.
478*0e209d39SAndroid Build Coastguard Worker  * The value is unchanged if that function pointer is NULL.
479*0e209d39SAndroid Build Coastguard Worker  *
480*0e209d39SAndroid Build Coastguard Worker  * For each contiguous range of code points with a given value,
481*0e209d39SAndroid Build Coastguard Worker  * the UTrieEnumRange function is called.
482*0e209d39SAndroid Build Coastguard Worker  *
483*0e209d39SAndroid Build Coastguard Worker  * @param trie a pointer to the runtime trie structure
484*0e209d39SAndroid Build Coastguard Worker  * @param enumValue a pointer to a function that may transform the trie entry value,
485*0e209d39SAndroid Build Coastguard Worker  *                  or NULL if the values from the trie are to be used directly
486*0e209d39SAndroid Build Coastguard Worker  * @param enumRange a pointer to a function that is called for each contiguous range
487*0e209d39SAndroid Build Coastguard Worker  *                  of code points with the same value
488*0e209d39SAndroid Build Coastguard Worker  * @param context an opaque pointer that is passed on to the callback functions
489*0e209d39SAndroid Build Coastguard Worker  */
490*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
491*0e209d39SAndroid Build Coastguard Worker utrie_enum(const UTrie *trie,
492*0e209d39SAndroid Build Coastguard Worker            UTrieEnumValue *enumValue, UTrieEnumRange *enumRange, const void *context);
493*0e209d39SAndroid Build Coastguard Worker 
494*0e209d39SAndroid Build Coastguard Worker /**
495*0e209d39SAndroid Build Coastguard Worker  * Unserialize a trie from 32-bit-aligned memory.
496*0e209d39SAndroid Build Coastguard Worker  * Inverse of utrie_serialize().
497*0e209d39SAndroid Build Coastguard Worker  * Fills the UTrie runtime trie structure with the settings for the trie data.
498*0e209d39SAndroid Build Coastguard Worker  *
499*0e209d39SAndroid Build Coastguard Worker  * @param trie a pointer to the runtime trie structure
500*0e209d39SAndroid Build Coastguard Worker  * @param data a pointer to 32-bit-aligned memory containing trie data
501*0e209d39SAndroid Build Coastguard Worker  * @param length the number of bytes available at data
502*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode an in/out ICU UErrorCode
503*0e209d39SAndroid Build Coastguard Worker  * @return the number of bytes at data taken up by the trie data
504*0e209d39SAndroid Build Coastguard Worker  */
505*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
506*0e209d39SAndroid Build Coastguard Worker utrie_unserialize(UTrie *trie, const void *data, int32_t length, UErrorCode *pErrorCode);
507*0e209d39SAndroid Build Coastguard Worker 
508*0e209d39SAndroid Build Coastguard Worker /**
509*0e209d39SAndroid Build Coastguard Worker  * "Unserialize" a dummy trie.
510*0e209d39SAndroid Build Coastguard Worker  * A dummy trie is an empty runtime trie, used when a real data trie cannot
511*0e209d39SAndroid Build Coastguard Worker  * be loaded.
512*0e209d39SAndroid Build Coastguard Worker  *
513*0e209d39SAndroid Build Coastguard Worker  * The input memory is filled so that the trie always returns the initialValue,
514*0e209d39SAndroid Build Coastguard Worker  * or the leadUnitValue for lead surrogate code points.
515*0e209d39SAndroid Build Coastguard Worker  * The Latin-1 part is always set up to be linear.
516*0e209d39SAndroid Build Coastguard Worker  *
517*0e209d39SAndroid Build Coastguard Worker  * @param trie a pointer to the runtime trie structure
518*0e209d39SAndroid Build Coastguard Worker  * @param data a pointer to 32-bit-aligned memory to be filled with the dummy trie data
519*0e209d39SAndroid Build Coastguard Worker  * @param length the number of bytes available at data (recommended to use UTRIE_DUMMY_SIZE)
520*0e209d39SAndroid Build Coastguard Worker  * @param initialValue the initial value that is set for all code points
521*0e209d39SAndroid Build Coastguard Worker  * @param leadUnitValue the value for lead surrogate code _units_ that do not
522*0e209d39SAndroid Build Coastguard Worker  *                      have associated supplementary data
523*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode an in/out ICU UErrorCode
524*0e209d39SAndroid Build Coastguard Worker  *
525*0e209d39SAndroid Build Coastguard Worker  * @see UTRIE_DUMMY_SIZE
526*0e209d39SAndroid Build Coastguard Worker  * @see utrie_open
527*0e209d39SAndroid Build Coastguard Worker  */
528*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
529*0e209d39SAndroid Build Coastguard Worker utrie_unserializeDummy(UTrie *trie,
530*0e209d39SAndroid Build Coastguard Worker                        void *data, int32_t length,
531*0e209d39SAndroid Build Coastguard Worker                        uint32_t initialValue, uint32_t leadUnitValue,
532*0e209d39SAndroid Build Coastguard Worker                        UBool make16BitTrie,
533*0e209d39SAndroid Build Coastguard Worker                        UErrorCode *pErrorCode);
534*0e209d39SAndroid Build Coastguard Worker 
535*0e209d39SAndroid Build Coastguard Worker /**
536*0e209d39SAndroid Build Coastguard Worker  * Default implementation for UTrie.getFoldingOffset, set automatically by
537*0e209d39SAndroid Build Coastguard Worker  * utrie_unserialize().
538*0e209d39SAndroid Build Coastguard Worker  * Simply returns the lead surrogate's value itself - which is the inverse
539*0e209d39SAndroid Build Coastguard Worker  * of the default folding function used by utrie_serialize().
540*0e209d39SAndroid Build Coastguard Worker  * Exported for static const UTrie structures.
541*0e209d39SAndroid Build Coastguard Worker  *
542*0e209d39SAndroid Build Coastguard Worker  * @see UTrieGetFoldingOffset
543*0e209d39SAndroid Build Coastguard Worker  */
544*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
545*0e209d39SAndroid Build Coastguard Worker utrie_defaultGetFoldingOffset(uint32_t data);
546*0e209d39SAndroid Build Coastguard Worker 
547*0e209d39SAndroid Build Coastguard Worker /* Building a trie ----------------------------------------------------------*/
548*0e209d39SAndroid Build Coastguard Worker 
549*0e209d39SAndroid Build Coastguard Worker /**
550*0e209d39SAndroid Build Coastguard Worker  * Build-time trie structure.
551*0e209d39SAndroid Build Coastguard Worker  * Opaque definition, here only to make fillIn parameters possible
552*0e209d39SAndroid Build Coastguard Worker  * for utrie_open() and utrie_clone().
553*0e209d39SAndroid Build Coastguard Worker  */
554*0e209d39SAndroid Build Coastguard Worker struct UNewTrie {
555*0e209d39SAndroid Build Coastguard Worker     /**
556*0e209d39SAndroid Build Coastguard Worker      * Index values at build-time are 32 bits wide for easier processing.
557*0e209d39SAndroid Build Coastguard Worker      * Bit 31 is set if the data block is used by multiple index values (from utrie_setRange()).
558*0e209d39SAndroid Build Coastguard Worker      */
559*0e209d39SAndroid Build Coastguard Worker     int32_t index[UTRIE_MAX_INDEX_LENGTH+UTRIE_SURROGATE_BLOCK_COUNT];
560*0e209d39SAndroid Build Coastguard Worker     uint32_t *data;
561*0e209d39SAndroid Build Coastguard Worker 
562*0e209d39SAndroid Build Coastguard Worker     uint32_t leadUnitValue;
563*0e209d39SAndroid Build Coastguard Worker     int32_t indexLength, dataCapacity, dataLength;
564*0e209d39SAndroid Build Coastguard Worker     UBool isAllocated, isDataAllocated;
565*0e209d39SAndroid Build Coastguard Worker     UBool isLatin1Linear, isCompacted;
566*0e209d39SAndroid Build Coastguard Worker 
567*0e209d39SAndroid Build Coastguard Worker     /**
568*0e209d39SAndroid Build Coastguard Worker      * Map of adjusted indexes, used in utrie_compact().
569*0e209d39SAndroid Build Coastguard Worker      * Maps from original indexes to new ones.
570*0e209d39SAndroid Build Coastguard Worker      */
571*0e209d39SAndroid Build Coastguard Worker     int32_t map[UTRIE_MAX_BUILD_TIME_DATA_LENGTH>>UTRIE_SHIFT];
572*0e209d39SAndroid Build Coastguard Worker };
573*0e209d39SAndroid Build Coastguard Worker 
574*0e209d39SAndroid Build Coastguard Worker typedef struct UNewTrie UNewTrie;
575*0e209d39SAndroid Build Coastguard Worker 
576*0e209d39SAndroid Build Coastguard Worker /**
577*0e209d39SAndroid Build Coastguard Worker  * Build-time trie callback function, used with utrie_serialize().
578*0e209d39SAndroid Build Coastguard Worker  * This function calculates a lead surrogate's value including a folding offset
579*0e209d39SAndroid Build Coastguard Worker  * from the 1024 supplementary code points [start..start+1024[ .
580*0e209d39SAndroid Build Coastguard Worker  * It is U+10000 <= start <= U+10fc00 and (start&0x3ff)==0.
581*0e209d39SAndroid Build Coastguard Worker  *
582*0e209d39SAndroid Build Coastguard Worker  * The folding offset is provided by the caller.
583*0e209d39SAndroid Build Coastguard Worker  * It is offset=UTRIE_BMP_INDEX_LENGTH+n*UTRIE_SURROGATE_BLOCK_COUNT with n=0..1023.
584*0e209d39SAndroid Build Coastguard Worker  * Instead of the offset itself, n can be stored in 10 bits -
585*0e209d39SAndroid Build Coastguard Worker  * or fewer if it can be assumed that few lead surrogates have associated data.
586*0e209d39SAndroid Build Coastguard Worker  *
587*0e209d39SAndroid Build Coastguard Worker  * The returned value must be
588*0e209d39SAndroid Build Coastguard Worker  * - not zero if and only if there is relevant data
589*0e209d39SAndroid Build Coastguard Worker  *   for the corresponding 1024 supplementary code points
590*0e209d39SAndroid Build Coastguard Worker  * - such that UTrie.getFoldingOffset(UNewTrieGetFoldedValue(..., offset))==offset
591*0e209d39SAndroid Build Coastguard Worker  *
592*0e209d39SAndroid Build Coastguard Worker  * @return a folded value, or 0 if there is no relevant data for the lead surrogate.
593*0e209d39SAndroid Build Coastguard Worker  */
594*0e209d39SAndroid Build Coastguard Worker typedef uint32_t U_CALLCONV
595*0e209d39SAndroid Build Coastguard Worker UNewTrieGetFoldedValue(UNewTrie *trie, UChar32 start, int32_t offset);
596*0e209d39SAndroid Build Coastguard Worker 
597*0e209d39SAndroid Build Coastguard Worker /**
598*0e209d39SAndroid Build Coastguard Worker  * Open a build-time trie structure.
599*0e209d39SAndroid Build Coastguard Worker  * The size of the build-time data array is specified to avoid allocating a large
600*0e209d39SAndroid Build Coastguard Worker  * array in all cases. The array itself can also be passed in.
601*0e209d39SAndroid Build Coastguard Worker  *
602*0e209d39SAndroid Build Coastguard Worker  * Although the trie is never fully expanded to a linear array, especially when
603*0e209d39SAndroid Build Coastguard Worker  * utrie_setRange32() is used, the data array could be large during build time.
604*0e209d39SAndroid Build Coastguard Worker  * The maximum length is
605*0e209d39SAndroid Build Coastguard Worker  * UTRIE_MAX_BUILD_TIME_DATA_LENGTH=0x110000+UTRIE_DATA_BLOCK_LENGTH+0x400.
606*0e209d39SAndroid Build Coastguard Worker  * (Number of Unicode code points + one all-initial-value block +
607*0e209d39SAndroid Build Coastguard Worker  *  possible duplicate entries for 1024 lead surrogates.)
608*0e209d39SAndroid Build Coastguard Worker  * (UTRIE_DATA_BLOCK_LENGTH<=0x200 in all cases.)
609*0e209d39SAndroid Build Coastguard Worker  *
610*0e209d39SAndroid Build Coastguard Worker  * @param fillIn a pointer to a UNewTrie structure to be initialized (will not be released), or
611*0e209d39SAndroid Build Coastguard Worker  *               NULL if one is to be allocated
612*0e209d39SAndroid Build Coastguard Worker  * @param aliasData a pointer to a data array to be used (will not be released), or
613*0e209d39SAndroid Build Coastguard Worker  *                  NULL if one is to be allocated
614*0e209d39SAndroid Build Coastguard Worker  * @param maxDataLength the capacity of aliasData (if not NULL) or
615*0e209d39SAndroid Build Coastguard Worker  *                      the length of the data array to be allocated
616*0e209d39SAndroid Build Coastguard Worker  * @param initialValue the initial value that is set for all code points
617*0e209d39SAndroid Build Coastguard Worker  * @param leadUnitValue the value for lead surrogate code _units_ that do not
618*0e209d39SAndroid Build Coastguard Worker  *                      have associated supplementary data
619*0e209d39SAndroid Build Coastguard Worker  * @param latin1Linear a flag indicating whether the Latin-1 range is to be allocated and
620*0e209d39SAndroid Build Coastguard Worker  *                     kept in a linear, contiguous part of the data array
621*0e209d39SAndroid Build Coastguard Worker  * @return a pointer to the initialized fillIn or the allocated and initialized new UNewTrie
622*0e209d39SAndroid Build Coastguard Worker  */
623*0e209d39SAndroid Build Coastguard Worker U_CAPI UNewTrie * U_EXPORT2
624*0e209d39SAndroid Build Coastguard Worker utrie_open(UNewTrie *fillIn,
625*0e209d39SAndroid Build Coastguard Worker            uint32_t *aliasData, int32_t maxDataLength,
626*0e209d39SAndroid Build Coastguard Worker            uint32_t initialValue, uint32_t leadUnitValue,
627*0e209d39SAndroid Build Coastguard Worker            UBool latin1Linear);
628*0e209d39SAndroid Build Coastguard Worker 
629*0e209d39SAndroid Build Coastguard Worker /**
630*0e209d39SAndroid Build Coastguard Worker  * Clone a build-time trie structure with all entries.
631*0e209d39SAndroid Build Coastguard Worker  *
632*0e209d39SAndroid Build Coastguard Worker  * @param fillIn like in utrie_open()
633*0e209d39SAndroid Build Coastguard Worker  * @param other the build-time trie structure to clone
634*0e209d39SAndroid Build Coastguard Worker  * @param aliasData like in utrie_open(),
635*0e209d39SAndroid Build Coastguard Worker  *                  used if aliasDataLength>=(capacity of other's data array)
636*0e209d39SAndroid Build Coastguard Worker  * @param aliasDataLength the length of aliasData
637*0e209d39SAndroid Build Coastguard Worker  * @return a pointer to the initialized fillIn or the allocated and initialized new UNewTrie
638*0e209d39SAndroid Build Coastguard Worker  */
639*0e209d39SAndroid Build Coastguard Worker U_CAPI UNewTrie * U_EXPORT2
640*0e209d39SAndroid Build Coastguard Worker utrie_clone(UNewTrie *fillIn, const UNewTrie *other, uint32_t *aliasData, int32_t aliasDataLength);
641*0e209d39SAndroid Build Coastguard Worker 
642*0e209d39SAndroid Build Coastguard Worker /**
643*0e209d39SAndroid Build Coastguard Worker  * Close a build-time trie structure, and release memory
644*0e209d39SAndroid Build Coastguard Worker  * that was allocated by utrie_open() or utrie_clone().
645*0e209d39SAndroid Build Coastguard Worker  *
646*0e209d39SAndroid Build Coastguard Worker  * @param trie the build-time trie
647*0e209d39SAndroid Build Coastguard Worker  */
648*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
649*0e209d39SAndroid Build Coastguard Worker utrie_close(UNewTrie *trie);
650*0e209d39SAndroid Build Coastguard Worker 
651*0e209d39SAndroid Build Coastguard Worker /**
652*0e209d39SAndroid Build Coastguard Worker  * Get the data array of a build-time trie.
653*0e209d39SAndroid Build Coastguard Worker  * The data may be modified, but entries that are equal before
654*0e209d39SAndroid Build Coastguard Worker  * must still be equal after modification.
655*0e209d39SAndroid Build Coastguard Worker  *
656*0e209d39SAndroid Build Coastguard Worker  * @param trie the build-time trie
657*0e209d39SAndroid Build Coastguard Worker  * @param pLength (out) a pointer to a variable that receives the number
658*0e209d39SAndroid Build Coastguard Worker  *                of entries in the data array
659*0e209d39SAndroid Build Coastguard Worker  * @return the data array
660*0e209d39SAndroid Build Coastguard Worker  */
661*0e209d39SAndroid Build Coastguard Worker U_CAPI uint32_t * U_EXPORT2
662*0e209d39SAndroid Build Coastguard Worker utrie_getData(UNewTrie *trie, int32_t *pLength);
663*0e209d39SAndroid Build Coastguard Worker 
664*0e209d39SAndroid Build Coastguard Worker /**
665*0e209d39SAndroid Build Coastguard Worker  * Set a value for a code point.
666*0e209d39SAndroid Build Coastguard Worker  *
667*0e209d39SAndroid Build Coastguard Worker  * @param trie the build-time trie
668*0e209d39SAndroid Build Coastguard Worker  * @param c the code point
669*0e209d39SAndroid Build Coastguard Worker  * @param value the value
670*0e209d39SAndroid Build Coastguard Worker  * @return false if a failure occurred (illegal argument or data array overrun)
671*0e209d39SAndroid Build Coastguard Worker  */
672*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2
673*0e209d39SAndroid Build Coastguard Worker utrie_set32(UNewTrie *trie, UChar32 c, uint32_t value);
674*0e209d39SAndroid Build Coastguard Worker 
675*0e209d39SAndroid Build Coastguard Worker /**
676*0e209d39SAndroid Build Coastguard Worker  * Get a value from a code point as stored in the build-time trie.
677*0e209d39SAndroid Build Coastguard Worker  *
678*0e209d39SAndroid Build Coastguard Worker  * @param trie the build-time trie
679*0e209d39SAndroid Build Coastguard Worker  * @param c the code point
680*0e209d39SAndroid Build Coastguard Worker  * @param pInBlockZero if not NULL, then *pInBlockZero is set to true
681*0e209d39SAndroid Build Coastguard Worker  *                     iff the value is retrieved from block 0;
682*0e209d39SAndroid Build Coastguard Worker  *                     block 0 is the all-initial-value initial block
683*0e209d39SAndroid Build Coastguard Worker  * @return the value
684*0e209d39SAndroid Build Coastguard Worker  */
685*0e209d39SAndroid Build Coastguard Worker U_CAPI uint32_t U_EXPORT2
686*0e209d39SAndroid Build Coastguard Worker utrie_get32(UNewTrie *trie, UChar32 c, UBool *pInBlockZero);
687*0e209d39SAndroid Build Coastguard Worker 
688*0e209d39SAndroid Build Coastguard Worker /**
689*0e209d39SAndroid Build Coastguard Worker  * Set a value in a range of code points [start..limit[.
690*0e209d39SAndroid Build Coastguard Worker  * All code points c with start<=c<limit will get the value if
691*0e209d39SAndroid Build Coastguard Worker  * overwrite is true or if the old value is 0.
692*0e209d39SAndroid Build Coastguard Worker  *
693*0e209d39SAndroid Build Coastguard Worker  * @param trie the build-time trie
694*0e209d39SAndroid Build Coastguard Worker  * @param start the first code point to get the value
695*0e209d39SAndroid Build Coastguard Worker  * @param limit one past the last code point to get the value
696*0e209d39SAndroid Build Coastguard Worker  * @param value the value
697*0e209d39SAndroid Build Coastguard Worker  * @param overwrite flag for whether old non-initial values are to be overwritten
698*0e209d39SAndroid Build Coastguard Worker  * @return false if a failure occurred (illegal argument or data array overrun)
699*0e209d39SAndroid Build Coastguard Worker  */
700*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2
701*0e209d39SAndroid Build Coastguard Worker utrie_setRange32(UNewTrie *trie, UChar32 start, UChar32 limit, uint32_t value, UBool overwrite);
702*0e209d39SAndroid Build Coastguard Worker 
703*0e209d39SAndroid Build Coastguard Worker /**
704*0e209d39SAndroid Build Coastguard Worker  * Compact the build-time trie after all values are set, and then
705*0e209d39SAndroid Build Coastguard Worker  * serialize it into 32-bit aligned memory.
706*0e209d39SAndroid Build Coastguard Worker  *
707*0e209d39SAndroid Build Coastguard Worker  * After this, the trie can only be serizalized again and/or closed;
708*0e209d39SAndroid Build Coastguard Worker  * no further values can be added.
709*0e209d39SAndroid Build Coastguard Worker  *
710*0e209d39SAndroid Build Coastguard Worker  * @see utrie_unserialize()
711*0e209d39SAndroid Build Coastguard Worker  *
712*0e209d39SAndroid Build Coastguard Worker  * @param trie the build-time trie
713*0e209d39SAndroid Build Coastguard Worker  * @param data a pointer to 32-bit-aligned memory for the trie data
714*0e209d39SAndroid Build Coastguard Worker  * @param capacity the number of bytes available at data
715*0e209d39SAndroid Build Coastguard Worker  * @param getFoldedValue a callback function that calculates the value for
716*0e209d39SAndroid Build Coastguard Worker  *                       a lead surrogate from all of its supplementary code points
717*0e209d39SAndroid Build Coastguard Worker  *                       and the folding offset;
718*0e209d39SAndroid Build Coastguard Worker  *                       if NULL, then a default function is used which returns just
719*0e209d39SAndroid Build Coastguard Worker  *                       the input offset when there are any non-initial-value entries
720*0e209d39SAndroid Build Coastguard Worker  * @param reduceTo16Bits flag for whether the values are to be reduced to a
721*0e209d39SAndroid Build Coastguard Worker  *                       width of 16 bits for serialization and runtime
722*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode a UErrorCode argument; among other possible error codes:
723*0e209d39SAndroid Build Coastguard Worker  * - U_BUFFER_OVERFLOW_ERROR if the data storage block is too small for serialization
724*0e209d39SAndroid Build Coastguard Worker  * - U_MEMORY_ALLOCATION_ERROR if the trie data array is too small
725*0e209d39SAndroid Build Coastguard Worker  * - U_INDEX_OUTOFBOUNDS_ERROR if the index or data arrays are too long after compaction for serialization
726*0e209d39SAndroid Build Coastguard Worker  *
727*0e209d39SAndroid Build Coastguard Worker  * @return the number of bytes written for the trie
728*0e209d39SAndroid Build Coastguard Worker  */
729*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
730*0e209d39SAndroid Build Coastguard Worker utrie_serialize(UNewTrie *trie, void *data, int32_t capacity,
731*0e209d39SAndroid Build Coastguard Worker                 UNewTrieGetFoldedValue *getFoldedValue,
732*0e209d39SAndroid Build Coastguard Worker                 UBool reduceTo16Bits,
733*0e209d39SAndroid Build Coastguard Worker                 UErrorCode *pErrorCode);
734*0e209d39SAndroid Build Coastguard Worker 
735*0e209d39SAndroid Build Coastguard Worker /* serialization ------------------------------------------------------------ */
736*0e209d39SAndroid Build Coastguard Worker 
737*0e209d39SAndroid Build Coastguard Worker // UTrie signature values, in platform endianness and opposite endianness.
738*0e209d39SAndroid Build Coastguard Worker // The UTrie signature ASCII byte values spell "Trie".
739*0e209d39SAndroid Build Coastguard Worker #define UTRIE_SIG       0x54726965
740*0e209d39SAndroid Build Coastguard Worker #define UTRIE_OE_SIG    0x65697254
741*0e209d39SAndroid Build Coastguard Worker 
742*0e209d39SAndroid Build Coastguard Worker /**
743*0e209d39SAndroid Build Coastguard Worker  * Trie data structure in serialized form:
744*0e209d39SAndroid Build Coastguard Worker  *
745*0e209d39SAndroid Build Coastguard Worker  * UTrieHeader header;
746*0e209d39SAndroid Build Coastguard Worker  * uint16_t index[header.indexLength];
747*0e209d39SAndroid Build Coastguard Worker  * uint16_t data[header.dataLength];
748*0e209d39SAndroid Build Coastguard Worker  * @internal
749*0e209d39SAndroid Build Coastguard Worker  */
750*0e209d39SAndroid Build Coastguard Worker typedef struct UTrieHeader {
751*0e209d39SAndroid Build Coastguard Worker     /** "Trie" in big-endian US-ASCII (0x54726965) */
752*0e209d39SAndroid Build Coastguard Worker     uint32_t signature;
753*0e209d39SAndroid Build Coastguard Worker 
754*0e209d39SAndroid Build Coastguard Worker     /**
755*0e209d39SAndroid Build Coastguard Worker      * options bit field:
756*0e209d39SAndroid Build Coastguard Worker      *     9    1=Latin-1 data is stored linearly at data+UTRIE_DATA_BLOCK_LENGTH
757*0e209d39SAndroid Build Coastguard Worker      *     8    0=16-bit data, 1=32-bit data
758*0e209d39SAndroid Build Coastguard Worker      *  7..4    UTRIE_INDEX_SHIFT   // 0..UTRIE_SHIFT
759*0e209d39SAndroid Build Coastguard Worker      *  3..0    UTRIE_SHIFT         // 1..9
760*0e209d39SAndroid Build Coastguard Worker      */
761*0e209d39SAndroid Build Coastguard Worker     uint32_t options;
762*0e209d39SAndroid Build Coastguard Worker 
763*0e209d39SAndroid Build Coastguard Worker     /** indexLength is a multiple of UTRIE_SURROGATE_BLOCK_COUNT */
764*0e209d39SAndroid Build Coastguard Worker     int32_t indexLength;
765*0e209d39SAndroid Build Coastguard Worker 
766*0e209d39SAndroid Build Coastguard Worker     /** dataLength>=UTRIE_DATA_BLOCK_LENGTH */
767*0e209d39SAndroid Build Coastguard Worker     int32_t dataLength;
768*0e209d39SAndroid Build Coastguard Worker } UTrieHeader;
769*0e209d39SAndroid Build Coastguard Worker 
770*0e209d39SAndroid Build Coastguard Worker /**
771*0e209d39SAndroid Build Coastguard Worker  * Constants for use with UTrieHeader.options.
772*0e209d39SAndroid Build Coastguard Worker  * @internal
773*0e209d39SAndroid Build Coastguard Worker  */
774*0e209d39SAndroid Build Coastguard Worker enum {
775*0e209d39SAndroid Build Coastguard Worker     /** Mask to get the UTRIE_SHIFT value from options. */
776*0e209d39SAndroid Build Coastguard Worker     UTRIE_OPTIONS_SHIFT_MASK=0xf,
777*0e209d39SAndroid Build Coastguard Worker 
778*0e209d39SAndroid Build Coastguard Worker     /** Shift options right this much to get the UTRIE_INDEX_SHIFT value. */
779*0e209d39SAndroid Build Coastguard Worker     UTRIE_OPTIONS_INDEX_SHIFT=4,
780*0e209d39SAndroid Build Coastguard Worker 
781*0e209d39SAndroid Build Coastguard Worker     /** If set, then the data (stage 2) array is 32 bits wide. */
782*0e209d39SAndroid Build Coastguard Worker     UTRIE_OPTIONS_DATA_IS_32_BIT=0x100,
783*0e209d39SAndroid Build Coastguard Worker 
784*0e209d39SAndroid Build Coastguard Worker     /**
785*0e209d39SAndroid Build Coastguard Worker      * If set, then Latin-1 data (for U+0000..U+00ff) is stored in the data (stage 2) array
786*0e209d39SAndroid Build Coastguard Worker      * as a simple, linear array at data+UTRIE_DATA_BLOCK_LENGTH.
787*0e209d39SAndroid Build Coastguard Worker      */
788*0e209d39SAndroid Build Coastguard Worker     UTRIE_OPTIONS_LATIN1_IS_LINEAR=0x200
789*0e209d39SAndroid Build Coastguard Worker };
790*0e209d39SAndroid Build Coastguard Worker 
791*0e209d39SAndroid Build Coastguard Worker U_CDECL_END
792*0e209d39SAndroid Build Coastguard Worker 
793*0e209d39SAndroid Build Coastguard Worker #endif
794