2
******************************************************************************
4
* Copyright (C) 2001, International Business Machines
5
* Corporation and others. All Rights Reserved.
7
******************************************************************************
10
* tab size: 8 (not used)
13
* created on: 2001nov08
14
* created by: Markus W. Scherer
20
#include "unicode/utypes.h"
27
* This is a common implementation of a "folded" trie.
28
* It is a kind of compressed, serializable table of 16- or 32-bit values associated with
29
* Unicode code points (0..0x10ffff).
31
* This implementation is optimized for getting values while walking forward
32
* through a UTF-16 string.
33
* Therefore, the simplest and fastest access macros are the
34
* _FROM_LEAD() and _FROM_OFFSET_TRAIL() macros.
36
* The _FROM_BMP() macros are a little more complicated; they get values
37
* even for lead surrogate code _points_, while the _FROM_LEAD() macros
38
* get special "folded" values for lead surrogate code _units_ if
39
* there is relevant data associated with them.
40
* From such a folded value, an offset needs to be extracted to supply
41
* to the _FROM_OFFSET_TRAIL() macros.
43
* Most of the more complex (and more convenient) functions/macros call a callback function
44
* to get that offset from the folded value for a lead surrogate unit.
48
* Trie constants, defining shift widths, index array lengths, etc.
51
/** Shift size for shifting right the input index. 1..9 */
54
/** Number of data values in a stage 2 (data array) block. 2, 4, 8, .., 0x200 */
55
UTRIE_DATA_BLOCK_LENGTH=1<<UTRIE_SHIFT,
57
/** Mask for getting the lower bits from the input index. */
58
UTRIE_MASK=UTRIE_DATA_BLOCK_LENGTH-1,
61
* Lead surrogate code points' index displacement in the index array.
62
* 0x10000-0xd800=0x2800
64
UTRIE_LEAD_INDEX_DISP=0x2800>>UTRIE_SHIFT,
67
* Shift size for shifting left the index array values.
68
* Increases possible data size with 16-bit index values at the cost
70
* This requires blocks of stage 2 data to be aligned by UTRIE_DATA_GRANULARITY.
75
/** The alignment size of a stage 2 data block. Also the granularity for compaction. */
76
UTRIE_DATA_GRANULARITY=1<<UTRIE_INDEX_SHIFT,
78
/** Number of bits of a trail surrogate that are used in index table lookups. */
79
UTRIE_SURROGATE_BLOCK_BITS=10-UTRIE_SHIFT,
82
* Number of index (stage 1) entries per lead surrogate.
83
* Same as number of indexe entries for 1024 trail surrogates,
84
* ==0x400>>UTRIE_SHIFT
86
UTRIE_SURROGATE_BLOCK_COUNT=(1<<UTRIE_SURROGATE_BLOCK_BITS),
88
/** Length of the BMP portion of the index (stage 1) array. */
89
UTRIE_BMP_INDEX_LENGTH=0x10000>>UTRIE_SHIFT
93
* Length of the index (stage 1) array before folding.
94
* Maximum number of Unicode code points (0x110000) shifted right by UTRIE_SHIFT.
96
#define UTRIE_MAX_INDEX_LENGTH (0x110000>>UTRIE_SHIFT)
99
* Maximum length of the runtime data (stage 2) array.
100
* Limited by 16-bit index values that are left-shifted by UTRIE_INDEX_SHIFT.
102
#define UTRIE_MAX_DATA_LENGTH (0x10000<<UTRIE_INDEX_SHIFT)
105
* Maximum length of the build-time data (stage 2) array.
106
* The maximum length is 0x110000+UTRIE_DATA_BLOCK_LENGTH+0x400.
107
* (Number of Unicode code points + one all-initial-value block +
108
* possible duplicate entries for 1024 lead surrogates.)
110
#define UTRIE_MAX_BUILD_TIME_DATA_LENGTH (0x110000+UTRIE_DATA_BLOCK_LENGTH+0x400)
113
* Runtime UTrie callback function.
114
* Extract from a lead surrogate's data the
115
* index array offset of the indexes for that lead surrogate.
117
* @param data data value for a surrogate from the trie, including the folding offset
118
* @return offset>=UTRIE_BMP_INDEX_LENGTH, or 0 if there is no data for the lead surrogate
120
typedef int32_t U_CALLCONV
121
UTrieGetFoldingOffset(uint32_t data);
124
* Run-time Trie structure.
126
* Either the data table is 16 bits wide and accessed via the index
127
* pointer, with each index item increased by indexLength;
128
* in this case, data32==NULL.
130
* Or the data table is 32 bits wide and accessed via the data32 pointer.
133
const uint16_t *index;
134
const uint32_t *data32; /* NULL if 16b data is used via index */
137
* This function is not used in _FROM_LEAD, _FROM_BMP, and _FROM_OFFSET_TRAIL macros.
138
* If convenience macros like _GET16 or _NEXT32 are used, this function must be set.
139
* @see UTrieGetFoldingOffset
141
UTrieGetFoldingOffset *getFoldingOffset;
143
int32_t indexLength, dataLength;
144
uint32_t initialValue;
145
UBool isLatin1Linear;
148
typedef struct UTrie UTrie;
150
/** Internal trie getter from an offset (0 if c16 is a BMP/lead units) and a 16-bit unit */
151
#define _UTRIE_GET_RAW(trie, data, offset, c16) \
153
((int32_t)((trie)->index[(offset)+((c16)>>UTRIE_SHIFT)])<<UTRIE_INDEX_SHIFT)+ \
157
/** Internal trie getter from a pair of surrogates */
158
#define _UTRIE_GET_FROM_PAIR(trie, data, c, c2, result, resultType) { \
161
/* get data for lead surrogate */ \
162
(result)=_UTRIE_GET_RAW((trie), data, 0, (c)); \
163
__offset=(trie)->getFoldingOffset(result); \
165
/* get the real data from the folded lead/trail units */ \
167
(result)=_UTRIE_GET_RAW((trie), data, __offset, (c2)&0x3ff); \
169
(result)=(resultType)((trie)->initialValue); \
173
/** Internal trie getter from a BMP code point, treating a lead surrogate as a normal code point */
174
#define _UTRIE_GET_FROM_BMP(trie, data, c16) \
175
_UTRIE_GET_RAW(trie, data, 0xd800<=(c16) && (c16)<=0xdbff ? UTRIE_LEAD_INDEX_DISP : 0, c16);
178
* Internal trie getter from a code point.
179
* Could be faster(?) but longer with
180
* if((c32)<=0xd7ff) { (result)=_UTRIE_GET_RAW(trie, data, 0, c32); }
182
#define _UTRIE_GET(trie, data, c32, result, resultType) \
183
if((uint32_t)(c32)<=0xffff) { \
184
/* BMP code points */ \
185
(result)=_UTRIE_GET_FROM_BMP(trie, data, c32); \
186
} else if((uint32_t)(c32)<=0x10ffff) { \
187
/* supplementary code point */ \
188
UChar __lead16=UTF16_LEAD(c32); \
189
_UTRIE_GET_FROM_PAIR(trie, data, __lead16, c32, result, resultType); \
192
(result)=(resultType)((trie)->initialValue); \
195
/** Internal next-post-increment: get the next code point (c, c2) and its data */
196
#define _UTRIE_NEXT(trie, data, src, limit, c, c2, result, resultType) { \
198
if(!UTF_IS_LEAD(c)) { \
200
(result)=_UTRIE_GET_RAW((trie), data, 0, (c)); \
201
} else if((src)!=(limit) && UTF_IS_TRAIL((c2)=*(src))) { \
203
_UTRIE_GET_FROM_PAIR((trie), data, (c), (c2), (result), resultType); \
205
/* unpaired lead surrogate code point */ \
207
(result)=_UTRIE_GET_RAW((trie), data, UTRIE_LEAD_INDEX_DISP, (c)); \
211
/** Internal previous: get the previous code point (c, c2) and its data */
212
#define _UTRIE_PREVIOUS(trie, data, start, src, c, c2, result, resultType) { \
214
if(!UTF_IS_SURROGATE(c)) { \
216
(result)=_UTRIE_GET_RAW((trie), data, 0, (c)); \
217
} else if(!UTF_IS_SURROGATE_FIRST(c)) { \
218
/* trail surrogate */ \
219
if((start)!=(src) && UTF_IS_LEAD((c2)=*((src)-1))) { \
221
(result)=(c); (c)=(c2); (c2)=(UChar)(result); /* swap c, c2 */ \
222
_UTRIE_GET_FROM_PAIR((trie), data, (c), (c2), (result), resultType); \
224
/* unpaired trail surrogate code point */ \
226
(result)=_UTRIE_GET_RAW((trie), data, 0, (c)); \
229
/* unpaired lead surrogate code point */ \
231
(result)=_UTRIE_GET_RAW((trie), data, UTRIE_LEAD_INDEX_DISP, (c)); \
235
/* Public UTrie API ---------------------------------------------------------*/
238
* Get a pointer to the contiguous part of the data array
239
* for the Latin-1 range (U+0000..U+00ff).
240
* Must be used only if the Latin-1 range is in fact linear
241
* (trie->isLatin1Linear).
243
* @param trie (const UTrie *, in) a pointer to the runtime trie structure
244
* @return (const uint16_t *) pointer to values for Latin-1 code points
246
#define UTRIE_GET16_LATIN1(trie) ((trie)->index+(trie)->indexLength+UTRIE_DATA_BLOCK_LENGTH)
249
* Get a pointer to the contiguous part of the data array
250
* for the Latin-1 range (U+0000..U+00ff).
251
* Must be used only if the Latin-1 range is in fact linear
252
* (trie->isLatin1Linear).
254
* @param trie (const UTrie *, in) a pointer to the runtime trie structure
255
* @return (const uint32_t *) pointer to values for Latin-1 code points
257
#define UTRIE_GET32_LATIN1(trie) ((trie)->data32+UTRIE_DATA_BLOCK_LENGTH)
260
* Get a 16-bit trie value from a BMP code point (UChar, <=U+ffff).
261
* c16 may be a lead surrogate, which may have a value including a folding offset.
263
* @param trie (const UTrie *, in) a pointer to the runtime trie structure
264
* @param c16 (UChar, in) the input BMP code point
265
* @return (uint16_t) trie lookup result
267
#define UTRIE_GET16_FROM_LEAD(trie, c16) _UTRIE_GET_RAW(trie, index, 0, c16)
270
* Get a 32-bit trie value from a BMP code point (UChar, <=U+ffff).
271
* c16 may be a lead surrogate, which may have a value including a folding offset.
273
* @param trie (const UTrie *, in) a pointer to the runtime trie structure
274
* @param c16 (UChar, in) the input BMP code point
275
* @return (uint32_t) trie lookup result
277
#define UTRIE_GET32_FROM_LEAD(trie, c16) _UTRIE_GET_RAW(trie, data32, 0, c16)
280
* Get a 16-bit trie value from a BMP code point (UChar, <=U+ffff).
281
* Even lead surrogate code points are treated as normal code points,
282
* with unfolded values that may differ from _FROM_LEAD() macro results for them.
284
* @param trie (const UTrie *, in) a pointer to the runtime trie structure
285
* @param c16 (UChar, in) the input BMP code point
286
* @return (uint16_t) trie lookup result
288
#define UTRIE_GET16_FROM_BMP(trie, c16) _UTRIE_GET_FROM_BMP(trie, index, c16)
291
* Get a 32-bit trie value from a BMP code point (UChar, <=U+ffff).
292
* Even lead surrogate code points are treated as normal code points,
293
* with unfolded values that may differ from _FROM_LEAD() macro results for them.
295
* @param trie (const UTrie *, in) a pointer to the runtime trie structure
296
* @param c16 (UChar, in) the input BMP code point
297
* @return (uint32_t) trie lookup result
299
#define UTRIE_GET32_FROM_BMP(trie, c16) _UTRIE_GET_FROM_BMP(trie, data32, c16)
302
* Get a 16-bit trie value from a code point.
303
* Even lead surrogate code points are treated as normal code points,
304
* with unfolded values that may differ from _FROM_LEAD() macro results for them.
306
* @param trie (const UTrie *, in) a pointer to the runtime trie structure
307
* @param c32 (UChar32, in) the input code point
308
* @param result (uint16_t, out) uint16_t variable for the trie lookup result
310
#define UTRIE_GET16(trie, c32, result) _UTRIE_GET(trie, index, c32, result, uint16_t)
313
* Get a 32-bit trie value from a code point.
314
* Even lead surrogate code points are treated as normal code points,
315
* with unfolded values that may differ from _FROM_LEAD() macro results for them.
317
* @param trie (const UTrie *, in) a pointer to the runtime trie structure
318
* @param c32 (UChar32, in) the input code point
319
* @param result (uint32_t, out) uint32_t variable for the trie lookup result
321
#define UTRIE_GET32(trie, c32, result) _UTRIE_GET(trie, data32, c32, result, uint32_t)
324
* Get the next code point (c, c2), post-increment src,
325
* and get a 16-bit value from the trie.
327
* @param trie (const UTrie *, in) a pointer to the runtime trie structure
328
* @param src (const UChar *, in/out) the source text pointer
329
* @param limit (const UChar *, in) the limit pointer for the text, or NULL
330
* @param c (UChar, out) variable for the BMP or lead code unit
331
* @param c2 (UChar, out) variable for 0 or the trail code unit
332
* @param result (uint16_t, out) uint16_t variable for the trie lookup result
334
#define UTRIE_NEXT16(trie, src, limit, c, c2, result) _UTRIE_NEXT(trie, index, src, limit, c, c2, result, uint16_t)
337
* Get the next code point (c, c2), post-increment src,
338
* and get a 32-bit value from the trie.
340
* @param trie (const UTrie *, in) a pointer to the runtime trie structure
341
* @param src (const UChar *, in/out) the source text pointer
342
* @param limit (const UChar *, in) the limit pointer for the text, or NULL
343
* @param c (UChar, out) variable for the BMP or lead code unit
344
* @param c2 (UChar, out) variable for 0 or the trail code unit
345
* @param result (uint32_t, out) uint32_t variable for the trie lookup result
347
#define UTRIE_NEXT32(trie, src, limit, c, c2, result) _UTRIE_NEXT(trie, data32, src, limit, c, c2, result, uint32_t)
350
* Get the previous code point (c, c2), pre-decrement src,
351
* and get a 16-bit value from the trie.
353
* @param trie (const UTrie *, in) a pointer to the runtime trie structure
354
* @param start (const UChar *, in) the start pointer for the text, or NULL
355
* @param src (const UChar *, in/out) the source text pointer
356
* @param c (UChar, out) variable for the BMP or lead code unit
357
* @param c2 (UChar, out) variable for 0 or the trail code unit
358
* @param result (uint16_t, out) uint16_t variable for the trie lookup result
360
#define UTRIE_PREVIOUS16(trie, start, src, c, c2, result) _UTRIE_PREVIOUS(trie, index, start, src, c, c2, result, uint16_t)
363
* Get the previous code point (c, c2), pre-decrement src,
364
* and get a 32-bit value from the trie.
366
* @param trie (const UTrie *, in) a pointer to the runtime trie structure
367
* @param start (const UChar *, in) the start pointer for the text, or NULL
368
* @param src (const UChar *, in/out) the source text pointer
369
* @param c (UChar, out) variable for the BMP or lead code unit
370
* @param c2 (UChar, out) variable for 0 or the trail code unit
371
* @param result (uint32_t, out) uint32_t variable for the trie lookup result
373
#define UTRIE_PREVIOUS32(trie, start, src, c, c2, result) _UTRIE_PREVIOUS(trie, data32, start, src, c, c2, result, uint32_t)
376
* Get a 16-bit trie value from a pair of surrogates.
378
* @param trie (const UTrie *, in) a pointer to the runtime trie structure
379
* @param c (UChar, in) a lead surrogate
380
* @param c2 (UChar, in) a trail surrogate
381
* @param result (uint16_t, out) uint16_t variable for the trie lookup result
383
#define UTRIE_GET16_FROM_PAIR(trie, c, c2, result) _UTRIE_GET_FROM_PAIR(trie, index, c, c2, result, uint16_t)
386
* Get a 32-bit trie value from a pair of surrogates.
388
* @param trie (const UTrie *, in) a pointer to the runtime trie structure
389
* @param c (UChar, in) a lead surrogate
390
* @param c2 (UChar, in) a trail surrogate
391
* @param result (uint32_t, out) uint32_t variable for the trie lookup result
393
#define UTRIE_GET32_FROM_PAIR(trie, c, c2, result) _UTRIE_GET_FROM_PAIR(trie, data32, c, c2, result, uint32_t)
396
* Get a 16-bit trie value from a folding offset (from the value of a lead surrogate)
397
* and a trail surrogate.
399
* @param trie (const UTrie *, in) a pointer to the runtime trie structure
400
* @param offset (int32_t, in) the folding offset from the value of a lead surrogate
401
* @param c2 (UChar, in) a trail surrogate (only the 10 low bits are significant)
402
* @return (uint16_t) trie lookup result
404
#define UTRIE_GET16_FROM_OFFSET_TRAIL(trie, offset, c2) _UTRIE_GET_RAW(trie, index, offset, (c2)&0x3ff)
407
* Get a 32-bit trie value from a folding offset (from the value of a lead surrogate)
408
* and a trail surrogate.
410
* @param trie (const UTrie *, in) a pointer to the runtime trie structure
411
* @param offset (int32_t, in) the folding offset from the value of a lead surrogate
412
* @param c2 (UChar, in) a trail surrogate (only the 10 low bits are significant)
413
* @return (uint32_t) trie lookup result
415
#define UTRIE_GET32_FROM_OFFSET_TRAIL(trie, offset, c2) _UTRIE_GET_RAW(trie, data32, offset, (c2)&0x3ff)
417
/* enumeration callback types */
420
* Callback from utrie_enum(), extracts a uint32_t value from a
421
* trie value. This value will be passed on to the UTrieEnumRange function.
423
* @param context an opaque pointer, as passed into utrie_enum()
424
* @param value a value from the trie
425
* @return the value that is to be passed on to the UTrieEnumRange function
427
typedef uint32_t U_CALLCONV
428
UTrieEnumValue(const void *context, uint32_t value);
431
* Callback from utrie_enum(), is called for each contiguous range
432
* of code points with the same value as retrieved from the trie and
433
* transformed by the UTrieEnumValue function.
435
* The callback function can stop the enumeration by returning FALSE.
437
* @param context an opaque pointer, as passed into utrie_enum()
438
* @param start the first code point in a contiguous range with value
439
* @param limit one past the last code point in a contiguous range with value
440
* @param value the value that is set for all code points in [start..limit[
441
* @return FALSE to stop the enumeration
443
typedef UBool U_CALLCONV
444
UTrieEnumRange(const void *context, UChar32 start, UChar32 limit, uint32_t value);
447
* Enumerate efficiently all values in a trie.
448
* For each entry in the trie, the value to be delivered is passed through
449
* the UTrieEnumValue function.
450
* The value is unchanged if that function pointer is NULL.
452
* For each contiguous range of code points with a given value,
453
* the UTrieEnumRange function is called.
455
* @param trie a pointer to the runtime trie structure
456
* @param enumValue a pointer to a function that may transform the trie entry value,
457
* or NULL if the values from the trie are to be used directly
458
* @param enumRange a pointer to a function that is called for each contiguous range
459
* of code points with the same value
460
* @param context an opaque pointer that is passed on to the callback functions
462
U_CAPI void U_EXPORT2
463
utrie_enum(UTrie *trie,
464
UTrieEnumValue *enumValue, UTrieEnumRange *enumRange, const void *context);
467
* Unserialize a trie from 32-bit-aligned memory.
468
* Inverse of utrie_serialize().
469
* Fills the UTrie runtime trie structure with the settings for the trie data.
471
* @param trie a pointer to the runtime trie structure
472
* @param data a pointer to 32-bit-aligned memory containing trie data
473
* @param length the number of bytes available at data
474
* @param pErrorCode an in/out ICU UErrorCode
475
* @return the number of bytes at data taken up by the trie data
477
U_CAPI int32_t U_EXPORT2
478
utrie_unserialize(UTrie *trie, const uint8_t *data, int32_t length, UErrorCode *pErrorCode);
480
/* Building a trie ----------------------------------------------------------*/
483
* Build-time trie structure.
484
* Opaque definition, here only to make fillIn parameters possible
485
* for utrie_open() and utrie_clone().
489
* Index values at build-time are 32 bits wide for easier processing.
490
* Bit 31 is set if the data block is used by multiple index values (from utrie_setRange()).
492
int32_t index[UTRIE_MAX_INDEX_LENGTH];
495
int32_t indexLength, dataCapacity, dataLength;
496
UBool isAllocated, isDataAllocated;
497
UBool isLatin1Linear, isCompacted;
500
* Map of adjusted indexes, used in utrie_compact().
501
* Maps from original indexes to new ones.
503
int32_t map[UTRIE_MAX_BUILD_TIME_DATA_LENGTH>>UTRIE_SHIFT];
506
typedef struct UNewTrie UNewTrie;
509
* Build-time trie callback function, used with utrie_serialize().
510
* This function calculates a lead surrogate's value including a folding offset
511
* from the 1024 supplementary code points [start..start+1024[ .
512
* It is U+10000 <= start <= U+10fc00 and (start&0x3ff)==0.
514
* The folding offset is provided by the caller.
515
* It is offset=UTRIE_BMP_INDEX_LENGTH+n*UTRIE_SURROGATE_BLOCK_COUNT with n=0..1023.
516
* Instead of the offset itself, n can be stored in 10 bits -
517
* or fewer if it can be assumed that few lead surrogates have associated data.
519
* The returned value must be
520
* - not zero if and only if there is relevant data
521
* for the corresponding 1024 supplementary code points
522
* - such that UTrie.getFoldingOffset(UNewTrieGetFoldedValue(..., offset))==offset
524
* @return a folded value, or 0 if there is no relevant data for the lead surrogate.
526
typedef uint32_t U_CALLCONV
527
UNewTrieGetFoldedValue(UNewTrie *trie, UChar32 start, int32_t offset);
530
* Open a build-time trie structure.
531
* The size of the build-time data array is specified to avoid allocating a large
532
* array in all cases. The array itself can also be passed in.
534
* Although the trie is never fully expanded to a linear array, especially when
535
* utrie_setRange32() is used, the data array could be large during build time.
536
* The maximum length is
537
* UTRIE_MAX_BUILD_TIME_DATA_LENGTH=0x110000+UTRIE_DATA_BLOCK_LENGTH+0x400.
538
* (Number of Unicode code points + one all-initial-value block +
539
* possible duplicate entries for 1024 lead surrogates.)
540
* (UTRIE_DATA_BLOCK_LENGTH<=0x200 in all cases.)
542
* @param fillIn a pointer to a UNewTrie structure to be initialized (will not be released), or
543
* NULL if one is to be allocated
544
* @param aliasData a pointer to a data array to be used (will not be released), or
545
* NULL if one is to be allocated
546
* @param maxDataLength the capacity of aliasData (if not NULL) or
547
* the length of the data array to be allocated
548
* @param initialValue the initial value that is set for all code points
549
* @param latin1Linear a flag indicating whether the Latin-1 range is to be allocated and
550
* kept in a linear, contiguous part of the data array
551
* @return a pointer to the initialized fillIn or the allocated and initialized new UNewTrie
553
U_CAPI UNewTrie * U_EXPORT2
554
utrie_open(UNewTrie *fillIn,
555
uint32_t *aliasData, int32_t maxDataLength,
556
uint32_t initialValue, UBool latin1Linear);
559
* Clone a build-time trie structure with all entries.
561
* @param fillIn like in utrie_open()
562
* @param other the build-time trie structure to clone
563
* @param aliasData like in utrie_open(),
564
* used if aliasDataLength>=(capacity of other's data array)
565
* @param aliasDataLength the length of aliasData
566
* @return a pointer to the initialized fillIn or the allocated and initialized new UNewTrie
568
U_CAPI UNewTrie * U_EXPORT2
569
utrie_clone(UNewTrie *fillIn, const UNewTrie *other, uint32_t *aliasData, int32_t aliasDataLength);
572
* Close a build-time trie structure, and release memory
573
* that was allocated by utrie_open() or utrie_clone().
575
* @param trie the build-time trie
577
U_CAPI void U_EXPORT2
578
utrie_close(UNewTrie *trie);
581
* Get the data array of a build-time trie.
582
* The data may be modified, but entries that are equal before
583
* must still be equal after modification.
585
* @param trie the build-time trie
586
* @param pLength (out) a pointer to a variable that receives the number
587
* of entries in the data array
588
* @return the data array
590
U_CAPI uint32_t * U_EXPORT2
591
utrie_getData(UNewTrie *trie, int32_t *pLength);
594
* Set a value for a code point.
596
* @param trie the build-time trie
597
* @param c the code point
598
* @param value the value
599
* @return FALSE if a failure occurred (illegal argument or data array overrun)
601
U_CAPI UBool U_EXPORT2
602
utrie_set32(UNewTrie *trie, UChar32 c, uint32_t value);
605
* Get a value from a code point as stored in the build-time trie.
607
* @param trie the build-time trie
608
* @param c the code point
609
* @param pInBlockZero if not NULL, then *pInBlockZero is set to TRUE
610
* iff the value is retrieved from block 0;
611
* block 0 is the all-initial-value initial block
614
U_CAPI uint32_t U_EXPORT2
615
utrie_get32(UNewTrie *trie, UChar32 c, UBool *pInBlockZero);
618
* Set a value in a range of code points [start..limit[.
619
* All code points c with start<=c<limit will get the value if
620
* overwrite is TRUE or if the old value is 0.
622
* @param trie the build-time trie
623
* @param start the first code point to get the value
624
* @param limit one past the last code point to get the value
625
* @param value the value
626
* @param overwrite flag for whether old non-initial values are to be overwritten
627
* @return FALSE if a failure occurred (illegal argument or data array overrun)
629
U_CAPI UBool U_EXPORT2
630
utrie_setRange32(UNewTrie *trie, UChar32 start, UChar32 limit, uint32_t value, UBool overwrite);
633
* Compact the build-time trie after all values are set, and then
634
* serialize it into 32-bit aligned memory.
636
* After this, the trie can only be serizalized again and/or closed;
637
* no further values can be added.
639
* @see utrie_unserialize()
641
* @param trie the build-time trie
642
* @param data a pointer to 32-bit-aligned memory for the trie data
643
* @param capacity the number of bytes available at data
644
* @param getFoldedValue a callback function that calculates the value for
645
* a lead surrogate from all of its supplementary code points
646
* and the folding offset
647
* @param reduceTo16Bits flag for whether the values are to be reduced to a
648
* width of 16 bits for serialization and runtime
649
* @param pErrorCode a UErrorCode argument; among other possible error codes:
650
* - U_BUFFER_OVERFLOW_ERROR if the data storage block is too small for serialization
651
* - U_MEMORY_ALLOCATION_ERROR if the trie data array is too small
652
* - U_INDEX_OUTOFBOUNDS_ERROR if the index or data arrays are too long after compaction for serialization
654
* @return the number of bytes written for the trie
656
U_CAPI int32_t U_EXPORT2
657
utrie_serialize(UNewTrie *trie, uint8_t *data, int32_t capacity,
658
UNewTrieGetFoldedValue *getFoldedValue,
659
UBool reduceTo16Bits,
660
UErrorCode *pErrorCode);