]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/ucol_imp.h
ICU-461.18.tar.gz
[apple/icu.git] / icuSources / i18n / ucol_imp.h
CommitLineData
b75a7d8f
A
1/*
2*******************************************************************************
3*
48b980fe 4* Copyright (C) 1998-2008,2011, International Business Machines
b75a7d8f
A
5* Corporation and others. All Rights Reserved.
6*
7*******************************************************************************
8*
9* Private implementation header for C collation
10* file name: ucol_imp.h
11* encoding: US-ASCII
12* tab size: 8 (not used)
13* indentation:4
14*
15* created on: 2000dec11
16* created by: Vladimir Weinstein
17*
18* Modification history
19* Date Name Comments
20* 02/16/2001 synwee Added UCOL_GETPREVCE for the use in ucoleitr
21* 02/27/2001 synwee Added getMaxExpansion data structure in UCollator
22* 03/02/2001 synwee Added UCOL_IMPLICIT_CE
23* 03/12/2001 synwee Added pointer start to collIterate.
24*/
25
26#ifndef UCOL_IMP_H
27#define UCOL_IMP_H
28
29#include "unicode/utypes.h"
30
31#define UCA_DATA_TYPE "icu"
32#define UCA_DATA_NAME "ucadata"
33#define INVC_DATA_TYPE "icu"
34#define INVC_DATA_NAME "invuca"
35
374ca955
A
36/**
37 * Convenience string denoting the Collation data tree
38 * @internal ICU 3.0
39 */
40#define U_ICUDATA_COLL U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "coll"
41
b75a7d8f
A
42#if !UCONFIG_NO_COLLATION
43
729e4ab9
A
44#ifdef XP_CPLUSPLUS
45#include "unicode/normalizer2.h"
46#include "unicode/unistr.h"
47#endif
b75a7d8f
A
48#include "unicode/ucol.h"
49#include "utrie.h"
46f4442e 50#include "cmemory.h"
b75a7d8f
A
51
52/* This is the internal header file which contains important declarations for
53 * the collation framework.
54 * Ready to use collators are stored as binary images. Both UCA and tailorings
55 * share the same binary format. Individual files (currently only UCA) have a
56 * udata header in front of the image and should be opened using udata_open.
57 * Tailoring images are currently stored inside resource bundles and are intialized
58 * through ucol_open API.
59 *
60 * The following describes the formats for collation binaries
61 * (UCA & tailorings) and for the inverse UCA table.
62 * Substructures are described in the collation design document at
46f4442e 63 * http://source.icu-project.org/repos/icu/icuhtml/trunk/design/collation/ICU_collation_design.htm
b75a7d8f 64 *
374ca955
A
65 * -------------------------------------------------------------
66 *
b75a7d8f
A
67 * Here is the format of binary collation image.
68 *
374ca955
A
69 * Physical order of structures:
70 * - header (UCATableHeader)
71 * - options (UColOptionSet)
72 * - expansions (CE[])
73 * - contractions (UChar[contractionSize] + CE[contractionSize])
74 * - serialized UTrie with mappings of code points to CEs
75 * - max expansion tables (CE[endExpansionCECount] + uint8_t[endExpansionCECount])
76 * - two bit sets for backward processing in strcoll (identical prefixes)
77 * and for backward CE iteration (each set is uint8_t[UCOL_UNSAFECP_TABLE_SIZE])
78 * - UCA constants (UCAConstants)
79 * - UCA contractions (UChar[contractionUCACombosSize][contractionUCACombosWidth])
80 *
81 * UCATableHeader fields:
82 *
b75a7d8f
A
83 * int32_t size; - image size in bytes
84 *
85 * Offsets to interesting data. All offsets are in bytes.
86 * to get the address add to the header address and cast properly.
374ca955 87 * Some offsets are zero if the corresponding structures are empty.
b75a7d8f 88 *
374ca955
A
89 * Tailoring binaries that only set options and contain no mappings etc.
90 * will have all offsets 0 except for the options and expansion offsets,
91 * which give the position and length of the options array.
b75a7d8f 92 *
374ca955
A
93 * uint32_t options; - offset to default collator options (UColOptionSet *),
94 * a set of 32-bit values. See declaration of UColOptionSet for more details
95 *
96 * uint32_t UCAConsts; - only used (!=0) in UCA image - structure which holds values for indirect positioning and implicit ranges
97 * See declaration of UCAConstants structure. This is a set of unsigned 32-bit values used to store
b75a7d8f
A
98 * important constant values that are defined in the UCA and used for building and runtime.
99 *
374ca955 100 * uint32_t contractionUCACombos; - only used (!=0) in UCA image - list of UCA contractions. This is a zero terminated array of UChar[contractionUCACombosWidth],
b75a7d8f
A
101 * containing contractions from the UCA. These are needed in the build process to copy UCA contractions
102 * in case the base contraction symbol is tailored.
103 *
374ca955 104 * uint32_t magic; - must contain UCOL_HEADER_MAGIC (formatVersion 2.3)
b75a7d8f
A
105 *
106 * uint32_t mappingPosition; - offset to UTrie (const uint8_t *mappingPosition). This is a serialized UTrie and should be treated as such.
107 * Used as a primary lookup table for collation elements.
108 *
374ca955 109 * uint32_t expansion; - offset to expansion table (uint32_t *expansion). This is an array of expansion CEs. Never 0.
b75a7d8f
A
110 *
111 * uint32_t contractionIndex; - offset to contraction table (UChar *contractionIndex). Used to look up contraction sequences. Contents
374ca955 112 * are aligned with the contents of contractionCEs table. 0 if no contractions.
b75a7d8f
A
113 *
114 * uint32_t contractionCEs; - offset to resulting contraction CEs (uint32_t *contractionCEs). When a contraction is resolved in the
115 * in the contractionIndex table, the resulting index is used to look up corresponding CE in this table.
374ca955 116 * 0 if no contractions.
b75a7d8f
A
117 * uint32_t contractionSize; - size of contraction table in elements (both Index and CEs).
118 *
119 * Tables described below are used for Boyer-Moore searching algorithm - they define the size of longest expansion
120 * and last CEs in expansions.
374ca955
A
121 * uint32_t endExpansionCE; - offset to array of last collation element in expansion (uint32_t *).
122 * Never 0.
b75a7d8f
A
123 * uint32_t expansionCESize; - array of maximum expansion sizes (uint8_t *)
124 * int32_t endExpansionCECount; - size of endExpansionCE. See UCOL_GETMAXEXPANSION
125 * for the usage model
126 *
127 * These two offsets point to byte tables that are used in the backup heuristics.
128 * uint32_t unsafeCP; - hash table of unsafe code points (uint8_t *). See ucol_unsafeCP function.
129 * uint32_t contrEndCP; - hash table of final code points in contractions (uint8_t *). See ucol_contractionEndCP.
130 *
374ca955
A
131 * int32_t contractionUCACombosSize; - number of UChar[contractionUCACombosWidth] in contractionUCACombos
132 * (formatVersion 2.3)
b75a7d8f 133 * UBool jamoSpecial; - Jamo special indicator (uint8_t). If TRUE, Jamos are special, so we cannot use simple Hangul decomposition.
374ca955
A
134 * UBool isBigEndian; - endianness of this collation binary (formatVersion 2.3)
135 * uint8_t charSetFamily; - charset family of this collation binary (formatVersion 2.3)
136 * uint8_t contractionUCACombosWidth; - number of UChars per UCA contraction in contractionUCACombos (formatVersion 2.3)
b75a7d8f
A
137 *
138 * Various version fields
139 * UVersionInfo version; - version 4 uint8_t
140 * UVersionInfo UCAVersion; - version 4 uint8_t
141 * UVersionInfo UCDVersion; - version 4 uint8_t
374ca955
A
142 * UVersionInfo formatVersion; - version of the format of the collation binary
143 * same formatVersion as in ucadata.icu's UDataInfo header
144 * (formatVersion 2.3)
b75a7d8f 145 *
729e4ab9
A
146 * uint32_t offset to the reordering code to lead CE byte remapping table
147 * uint32_t offset to the lead CE byte to reordering code mapping table
148 *
149 * uint8_t reserved[76]; - currently unused
b75a7d8f 150 *
374ca955 151 * -------------------------------------------------------------
b75a7d8f
A
152 *
153 * Inverse UCA is used for constructing collators from rules. It is always an individual file
154 * and always has a UDataInfo header.
155 * here is the structure:
156 *
157 * uint32_t byteSize; - size of inverse UCA image in bytes
374ca955 158 * uint32_t tableSize; - length of inverse table (number of uint32_t[3] rows)
b75a7d8f
A
159 * uint32_t contsSize; - size of continuation table (number of UChars in table)
160 *
161 * uint32_t table; - offset to inverse table (uint32_t *)
162 * Inverse table contains of rows of 3 uint32_t values. First two values are CE and a possible continuation
163 * the third value is either a code unit (if there is only one code unit for element) or an index to continuation
164 * (number of code units combined with an index).
165 * table. If more than one codepoint have the same CE, continuation table contains code units separated by FFFF and final
166 * code unit sequence for a CE is terminated by FFFE.
167 * uint32_t conts; - offset to continuation table (uint16_t *). Contains code units that transform to a same CE.
168 *
169 * UVersionInfo UCAVersion; - version of the UCA, read from file 4 uint8_t
170 * uint8_t padding[8]; - padding 8 uint8_t
171 * Header is followed by the table and continuation table.
172*/
173
374ca955
A
174/* let us know whether reserved fields are reset to zero or junked */
175#define UCOL_HEADER_MAGIC 0x20030618
176
b75a7d8f 177/* UDataInfo for UCA mapping table */
374ca955
A
178/* dataFormat="UCol" */
179#define UCA_DATA_FORMAT_0 ((uint8_t)0x55)
180#define UCA_DATA_FORMAT_1 ((uint8_t)0x43)
181#define UCA_DATA_FORMAT_2 ((uint8_t)0x6f)
182#define UCA_DATA_FORMAT_3 ((uint8_t)0x6c)
183
729e4ab9
A
184#define UCA_FORMAT_VERSION_0 ((uint8_t)3)
185#define UCA_FORMAT_VERSION_1 ((uint8_t)0)
374ca955
A
186#define UCA_FORMAT_VERSION_2 ((uint8_t)0)
187#define UCA_FORMAT_VERSION_3 ((uint8_t)0)
b75a7d8f
A
188
189/* UDataInfo for inverse UCA table */
374ca955
A
190/* dataFormat="InvC" */
191#define INVUCA_DATA_FORMAT_0 ((uint8_t)0x49)
192#define INVUCA_DATA_FORMAT_1 ((uint8_t)0x6E)
193#define INVUCA_DATA_FORMAT_2 ((uint8_t)0x76)
194#define INVUCA_DATA_FORMAT_3 ((uint8_t)0x43)
195
196#define INVUCA_FORMAT_VERSION_0 ((uint8_t)2)
197#define INVUCA_FORMAT_VERSION_1 ((uint8_t)1)
198#define INVUCA_FORMAT_VERSION_2 ((uint8_t)0)
199#define INVUCA_FORMAT_VERSION_3 ((uint8_t)0)
b75a7d8f
A
200
201/* This is the size of the stack allocated buffer for sortkey generation and similar operations */
202/* if it is too small, heap allocation will occur.*/
203/* you can change this value if you need memory - it will affect the performance, though, since we're going to malloc */
204#define UCOL_MAX_BUFFER 128
205#define UCOL_PRIMARY_MAX_BUFFER 8*UCOL_MAX_BUFFER
206#define UCOL_SECONDARY_MAX_BUFFER UCOL_MAX_BUFFER
207#define UCOL_TERTIARY_MAX_BUFFER UCOL_MAX_BUFFER
48b980fe 208/*
b75a7d8f 209#define UCOL_CASE_MAX_BUFFER UCOL_MAX_BUFFER/4
48b980fe
A
210
211UCOL_CASE_MAX_BUFFER as previously defined above was too small. A single collation element can
212generate two caseShift values, and UCOL_CASE_SHIFT_START (=7) caseShift values are compressed into
213one byte. UCOL_MAX_BUFFER should effectively be multipled by 2/UCOL_CASE_SHIFT_START (2/7), not 1/4.
214Perhaps UCOL_CASE_SHIFT_START used to be 8; then this would have been correct. We should dynamically
215define UCOL_CASE_MAX_BUFFER in terms of both UCOL_MAX_BUFFER and UCOL_CASE_SHIFT_START. Since
216UCOL_CASE_SHIFT_START is defined lower down, we move the real definition of UCOL_CASE_MAX_BUFFER
217after it, further down.
218*/
b75a7d8f
A
219#define UCOL_QUAD_MAX_BUFFER 2*UCOL_MAX_BUFFER
220
221#define UCOL_NORMALIZATION_GROWTH 2
222#define UCOL_NORMALIZATION_MAX_BUFFER UCOL_MAX_BUFFER*UCOL_NORMALIZATION_GROWTH
223
224/* This writable buffer is used if we encounter Thai and need to reorder the string on the fly */
225/* Sometimes we already have a writable buffer (like in case of normalized strings). */
226/*
227you can change this value to any value >= 4 if you need memory -
228it will affect the performance, though, since we're going to malloc.
229Note 3 is the minimum value for Thai collation and 4 is the
230minimum number for special Jamo
231*/
232#define UCOL_WRITABLE_BUFFER_SIZE 256
233
234/* This is the size of the buffer for expansion CE's */
235/* In reality we should not have to deal with expm sequences longer then 16 */
236/* you can change this value if you need memory */
46f4442e 237/* WARNING THIS BUFFER DOES HAVE MALLOC FALLBACK. If you make it too small, you'll get into performance trouble */
b75a7d8f
A
238/* Reasonable small value is around 10, if you don't do Arabic or other funky collations that have long expansion sequence */
239/* This is the longest expansion sequence we can handle without bombing out */
46f4442e
A
240#define UCOL_EXPAND_CE_BUFFER_SIZE 64
241
242/* This is the size to increase the buffer for expansion CE's */
243#define UCOL_EXPAND_CE_BUFFER_EXTEND_SIZE 64
b75a7d8f
A
244
245
246/* Unsafe UChar hash table table size. */
247/* size is 32 bytes for 1 bit for each latin 1 char + some power of two for */
248/* hashing the rest of the chars. Size in bytes */
249#define UCOL_UNSAFECP_TABLE_SIZE 1056
250 /* mask value down to "some power of two"-1 */
251 /* number of bits, not num of bytes. */
252#define UCOL_UNSAFECP_TABLE_MASK 0x1fff
253
254
255/* flags bits for collIterate.flags */
256/* */
257/* NORM - set for incremental normalize of source string */
258#define UCOL_ITER_NORM 1
259
260#define UCOL_ITER_HASLEN 2
261
262 /* UCOL_ITER_INNORMBUF - set if the "pos" is in */
263 /* the writable side buffer, handling */
264 /* incrementally normalized characters. */
265#define UCOL_ITER_INNORMBUF 4
266
267 /* UCOL_ITER_ALLOCATED - set if this iterator has */
268 /* malloced storage to expand a buffer. */
269#define UCOL_ITER_ALLOCATED 8
270 /* UCOL_HIRAGANA_Q - note if the codepoint was hiragana */
271#define UCOL_HIRAGANA_Q 16
272 /* UCOL_WAS_HIRAGANA - set to TRUE if there was a Hiragana */
273 /* otherwise set to false */
274#define UCOL_WAS_HIRAGANA 32
275 /* UCOL_USE_ITERATOR - set this if collIterate uses a */
276 /* character iterator instead of simply accessing string */
277 /* by index */
278#define UCOL_USE_ITERATOR 64
279
729e4ab9
A
280#define UCOL_FORCE_HAN_IMPLICIT 128
281
b75a7d8f
A
282#define NFC_ZERO_CC_BLOCK_LIMIT_ 0x300
283
729e4ab9
A
284#ifdef XP_CPLUSPLUS
285
286U_NAMESPACE_BEGIN
287
288typedef struct collIterate : public UMemory {
289 const UChar *string; /* Original string */
b75a7d8f
A
290 /* UChar *start; Pointer to the start of the source string. Either points to string
291 or to writableBuffer */
729e4ab9
A
292 const UChar *endp; /* string end ptr. Is undefined for null terminated strings */
293 const UChar *pos; /* This is position in the string. Can be to original or writable buf */
b75a7d8f
A
294
295 uint32_t *toReturn; /* This is the CE from CEs buffer that should be returned */
296 uint32_t *CEpos; /* This is the position to which we have stored processed CEs */
46f4442e
A
297
298 int32_t *offsetReturn; /* This is the offset to return, if non-NULL */
299 int32_t *offsetStore; /* This is the pointer for storing offsets */
300 int32_t offsetRepeatCount; /* Repeat stored offset if non-zero */
301 int32_t offsetRepeatValue; /* offset value to repeat */
302
729e4ab9
A
303 UnicodeString writableBuffer;
304 const UChar *fcdPosition; /* Position in the original string to continue FCD check from. */
b75a7d8f 305 const UCollator *coll;
729e4ab9 306 const Normalizer2 *nfd;
b75a7d8f
A
307 uint8_t flags;
308 uint8_t origFlags;
46f4442e
A
309 uint32_t *extendCEs; /* This is use if CEs is not big enough */
310 int32_t extendCEsSize; /* Holds the size of the dynamic CEs buffer */
b75a7d8f 311 uint32_t CEs[UCOL_EXPAND_CE_BUFFER_SIZE]; /* This is where we store CEs */
46f4442e
A
312
313 int32_t *offsetBuffer; /* A dynamic buffer to hold offsets */
314 int32_t offsetBufferSize; /* The size of the offset buffer */
315
b75a7d8f
A
316 UCharIterator *iterator;
317 /*int32_t iteratorIndex;*/
729e4ab9
A
318
319 // The offsetBuffer should probably be a UVector32, but helper functions
320 // are an improvement over duplicated code.
321 void appendOffset(int32_t offset, UErrorCode &errorCode);
73c04bcf 322} collIterate;
b75a7d8f 323
729e4ab9
A
324U_NAMESPACE_END
325
326#else
327
328typedef struct collIterate collIterate;
329
330#endif
331
46f4442e
A
332#define paddedsize(something) ((something)+((((something)%4)!=0)?(4-(something)%4):0))
333#define headersize (paddedsize(sizeof(UCATableHeader))+paddedsize(sizeof(UColOptionSet)))
334
b75a7d8f
A
335/*
336struct used internally in getSpecial*CE.
337data similar to collIterate.
338*/
339struct collIterateState {
729e4ab9
A
340 const UChar *pos; /* This is position in the string. Can be to original or writable buf */
341 const UChar *returnPos;
342 const UChar *fcdPosition; /* Position in the original string to continue FCD check from. */
343 const UChar *bufferaddress; /* address of the normalization buffer */
344 int32_t buffersize;
b75a7d8f
A
345 uint8_t flags;
346 uint8_t origFlags;
347 uint32_t iteratorIndex;
348 int32_t iteratorMove;
349};
350
729e4ab9
A
351U_CAPI void U_EXPORT2
352uprv_init_collIterate(const UCollator *collator,
353 const UChar *sourceString, int32_t sourceLen,
354 U_NAMESPACE_QUALIFIER collIterate *s, UErrorCode *status);
355
356/* Internal functions for C test code. */
357U_CAPI U_NAMESPACE_QUALIFIER collIterate * U_EXPORT2
358uprv_new_collIterate(UErrorCode *status);
359
360U_CAPI void U_EXPORT2
361uprv_delete_collIterate(U_NAMESPACE_QUALIFIER collIterate *s);
362
363/* @return s->pos == s->endp */
364U_CAPI UBool U_EXPORT2
365uprv_collIterateAtEnd(U_NAMESPACE_QUALIFIER collIterate *s);
366
367#ifdef XP_CPLUSPLUS
b75a7d8f 368
46f4442e
A
369U_NAMESPACE_BEGIN
370
371struct UCollationPCE;
372typedef struct UCollationPCE UCollationPCE;
373
374U_NAMESPACE_END
b75a7d8f 375
729e4ab9 376struct UCollationElements : public U_NAMESPACE_QUALIFIER UMemory
b75a7d8f
A
377{
378 /**
379 * Struct wrapper for source data
380 */
729e4ab9 381 U_NAMESPACE_QUALIFIER collIterate iteratordata_;
b75a7d8f
A
382 /**
383 * Indicates if this data has been reset.
384 */
385 UBool reset_;
386 /**
387 * Indicates if the data should be deleted.
388 */
389 UBool isWritable;
46f4442e
A
390
391/**
392 * Data for getNextProcessed, getPreviousProcessed.
393 */
394 U_NAMESPACE_QUALIFIER UCollationPCE *pce;
b75a7d8f
A
395};
396
729e4ab9
A
397#else
398/*opaque type*/
399struct UCollationElements;
400#endif
b75a7d8f 401
46f4442e
A
402U_CAPI void U_EXPORT2
403uprv_init_pce(const struct UCollationElements *elems);
404
b75a7d8f
A
405#define UCOL_LEVELTERMINATOR 1
406
407/* mask off anything but primary order */
408#define UCOL_PRIMARYORDERMASK 0xffff0000
409/* mask off anything but secondary order */
410#define UCOL_SECONDARYORDERMASK 0x0000ff00
411/* mask off anything but tertiary order */
412#define UCOL_TERTIARYORDERMASK 0x000000ff
413/* primary order shift */
414#define UCOL_PRIMARYORDERSHIFT 16
415/* secondary order shift */
416#define UCOL_SECONDARYORDERSHIFT 8
417
418#define UCOL_BYTE_SIZE_MASK 0xFF
419
420#define UCOL_CASE_BYTE_START 0x80
421#define UCOL_CASE_SHIFT_START 7
422
48b980fe
A
423/*
424The definition of UCOL_CASE_MAX_BUFFER is moved down here so it can use UCOL_CASE_SHIFT_START.
425
426A single collation element can generate two caseShift values, and UCOL_CASE_SHIFT_START caseShift
427values are compressed into one byte. The UCOL_CASE_MAX_BUFFER should effectively be UCOL_MAX_BUFFER
428multipled by 2/UCOL_CASE_SHIFT_START, with suitable rounding up.
429*/
430#define UCOL_CASE_MAX_BUFFER (((2*UCOL_MAX_BUFFER) + UCOL_CASE_SHIFT_START - 1)/UCOL_CASE_SHIFT_START)
431
b75a7d8f
A
432#define UCOL_IGNORABLE 0
433
434/* get weights from a CE */
435#define UCOL_PRIMARYORDER(order) (((order) & UCOL_PRIMARYORDERMASK)>> UCOL_PRIMARYORDERSHIFT)
436#define UCOL_SECONDARYORDER(order) (((order) & UCOL_SECONDARYORDERMASK)>> UCOL_SECONDARYORDERSHIFT)
437#define UCOL_TERTIARYORDER(order) ((order) & UCOL_TERTIARYORDERMASK)
438
439/**
440 * Determine if a character is a Thai vowel (which sorts after
441 * its base consonant).
442 */
443#define UCOL_ISTHAIPREVOWEL(ch) ((((uint32_t)(ch) - 0xe40) <= (0xe44 - 0xe40)) || \
444 (((uint32_t)(ch) - 0xec0) <= (0xec4 - 0xec0)))
445
446/**
447 * Determine if a character is a Thai base consonant
448 */
449#define UCOL_ISTHAIBASECONSONANT(ch) ((uint32_t)(ch) - 0xe01) <= (0xe2e - 0xe01)
450
451#define UCOL_ISJAMO(ch) ((((uint32_t)(ch) - 0x1100) <= (0x1112 - 0x1100)) || \
452 (((uint32_t)(ch) - 0x1161) <= (0x1175 - 0x1161)) || \
453 (((uint32_t)(ch) - 0x11A8) <= (0x11C2 - 0x11A8)))
454
729e4ab9
A
455/* Han character ranges */
456#define UCOL_FIRST_HAN 0x4E00
457#define UCOL_LAST_HAN 0x9FFF
458#define UCOL_FIRST_HAN_A 0x3400
459#define UCOL_LAST_HAN_A 0x4DBF
460#define UCOL_FIRST_HAN_COMPAT 0xFAE0
461#define UCOL_LAST_HAN_COMPAT 0xFA2F
462
463/* Han extension B is in plane 2 */
464#define UCOL_FIRST_HAN_B 0x20000
465#define UCOL_LAST_HAN_B 0x2A6DF
466
467/* Hangul range */
468#define UCOL_FIRST_HANGUL 0xAC00
469#define UCOL_LAST_HANGUL 0xD7AF
470
471/* Jamo ranges */
472#define UCOL_FIRST_L_JAMO 0x1100
473#define UCOL_FIRST_V_JAMO 0x1161
474#define UCOL_FIRST_T_JAMO 0x11A8
475#define UCOL_LAST_T_JAMO 0x11F9
b75a7d8f
A
476
477
478#if 0
479/* initializes collIterate structure */
480/* made as macro to speed up things */
481#define init_collIterate(collator, sourceString, sourceLen, s) { \
482 (s)->start = (s)->string = (s)->pos = (UChar *)(sourceString); \
483 (s)->endp = (sourceLen) == -1 ? NULL :(UChar *)(sourceString)+(sourceLen); \
484 (s)->CEpos = (s)->toReturn = (s)->CEs; \
485 (s)->isThai = TRUE; \
486 (s)->writableBuffer = (s)->stackWritableBuffer; \
487 (s)->writableBufSize = UCOL_WRITABLE_BUFFER_SIZE; \
488 (s)->coll = (collator); \
489 (s)->fcdPosition = 0; \
490 (s)->flags = 0; \
491 if(((collator)->normalizationMode == UCOL_ON)) (s)->flags |= UCOL_ITER_NORM; \
492}
493#endif
494
495
496
497/*
498* Macro to get the maximum size of an expansion ending with the argument ce.
499* Used in the Boyer Moore algorithm.
500* Note for tailoring, the UCA maxexpansion table has been merged.
501* Hence we only have to search the tailored collator only.
502* @param coll const UCollator pointer
503* @param order last collation element of the expansion sequence
504* @param result size of the longest expansion with argument collation element
505* as the last element
506*/
507#define UCOL_GETMAXEXPANSION(coll, order, result) { \
508 const uint32_t *start; \
509 const uint32_t *limit; \
510 const uint32_t *mid; \
511 start = (coll)->endExpansionCE; \
512 limit = (coll)->lastEndExpansionCE; \
513 while (start < limit - 1) { \
514 mid = start + ((limit - start) >> 1); \
515 if ((order) <= *mid) { \
516 limit = mid; \
517 } \
518 else { \
519 start = mid; \
520 } \
521 } \
522 if (*start == order) { \
523 result = *((coll)->expansionCESize + (start - (coll)->endExpansionCE)); \
524 } \
525 else if (*limit == order) { \
526 result = *(coll->expansionCESize + (limit - coll->endExpansionCE)); \
527 } \
528 else if ((order & 0xFFFF) == 0x00C0) { \
529 result = 2; \
530 } \
531 else { \
532 result = 1; \
533 } \
534}
535
536U_CFUNC
729e4ab9
A
537uint32_t ucol_prv_getSpecialCE(const UCollator *coll, UChar ch, uint32_t CE,
538 U_NAMESPACE_QUALIFIER collIterate *source, UErrorCode *status);
b75a7d8f
A
539
540U_CFUNC
541uint32_t ucol_prv_getSpecialPrevCE(const UCollator *coll, UChar ch, uint32_t CE,
729e4ab9
A
542 U_NAMESPACE_QUALIFIER collIterate *source, UErrorCode *status);
543U_CAPI uint32_t U_EXPORT2 ucol_getNextCE(const UCollator *coll,
544 U_NAMESPACE_QUALIFIER collIterate *collationSource, UErrorCode *status);
46f4442e 545U_CFUNC uint32_t U_EXPORT2 ucol_getPrevCE(const UCollator *coll,
729e4ab9
A
546 U_NAMESPACE_QUALIFIER collIterate *collationSource,
547 UErrorCode *status);
b75a7d8f
A
548/* function used by C++ getCollationKey to prevent restarting the calculation */
549U_CFUNC int32_t
550ucol_getSortKeyWithAllocation(const UCollator *coll,
551 const UChar *source, int32_t sourceLength,
552 uint8_t **pResult,
553 UErrorCode *pErrorCode);
554
555/* get some memory */
556void *ucol_getABuffer(const UCollator *coll, uint32_t size);
557
558/* worker function for generating sortkeys */
559U_CFUNC
560int32_t U_CALLCONV
561ucol_calcSortKey(const UCollator *coll,
562 const UChar *source,
563 int32_t sourceLength,
564 uint8_t **result,
565 uint32_t resultLength,
566 UBool allocatePrimary,
567 UErrorCode *status);
568
569U_CFUNC
570int32_t U_CALLCONV
571ucol_calcSortKeySimpleTertiary(const UCollator *coll,
572 const UChar *source,
573 int32_t sourceLength,
574 uint8_t **result,
575 uint32_t resultLength,
576 UBool allocatePrimary,
577 UErrorCode *status);
578
579U_CFUNC
580int32_t
729e4ab9 581ucol_getSortKeySize(const UCollator *coll, U_NAMESPACE_QUALIFIER collIterate *s,
b75a7d8f
A
582 int32_t currentSize, UColAttributeValue strength,
583 int32_t len);
584/**
585 * Makes a copy of the Collator's rule data. The format is
586 * that of .col files.
587 *
588 * @param length returns the length of the data, in bytes.
589 * @param status the error status
590 * @return memory, owned by the caller, of size 'length' bytes.
591 * @internal INTERNAL USE ONLY
592 */
46f4442e 593U_CFUNC uint8_t* U_EXPORT2
b75a7d8f
A
594ucol_cloneRuleData(const UCollator *coll, int32_t *length, UErrorCode *status);
595
596/**
597 * Used to set requested and valid locales on a collator returned by the collator
598 * service.
599 */
46f4442e
A
600U_CFUNC void U_EXPORT2
601ucol_setReqValidLocales(UCollator *coll, char *requestedLocaleToAdopt, char *validLocaleToAdopt, char *actualLocaleToAdopt);
b75a7d8f
A
602
603#define UCOL_SPECIAL_FLAG 0xF0000000
604#define UCOL_TAG_SHIFT 24
605#define UCOL_TAG_MASK 0x0F000000
606#define INIT_EXP_TABLE_SIZE 1024
607#define UCOL_NOT_FOUND 0xF0000000
608#define UCOL_EXPANSION 0xF1000000
609#define UCOL_CONTRACTION 0xF2000000
610#define UCOL_THAI 0xF3000000
611#define UCOL_UNMARKED 0x03
612#define UCOL_NEW_TERTIARYORDERMASK 0x0000003f
613
614/* Bit mask for primary collation strength. */
615#define UCOL_PRIMARYMASK 0xFFFF0000
616
617/* Bit mask for secondary collation strength. */
618#define UCOL_SECONDARYMASK 0x0000FF00
619
620/* Bit mask for tertiary collation strength. */
621#define UCOL_TERTIARYMASK 0x000000FF
622
623/**
624 * Internal.
625 * This indicates the last element in a UCollationElements has been consumed.
626 * Compare with the UCOL_NULLORDER, UCOL_NULLORDER is returned if error occurs.
627 */
628#define UCOL_NO_MORE_CES 0x00010101
629#define UCOL_NO_MORE_CES_PRIMARY 0x00010000
630#define UCOL_NO_MORE_CES_SECONDARY 0x00000100
631#define UCOL_NO_MORE_CES_TERTIARY 0x00000001
632
633#define isSpecial(CE) ((((CE)&UCOL_SPECIAL_FLAG)>>28)==0xF)
634
635#define UCOL_UPPER_CASE 0x80
636#define UCOL_MIXED_CASE 0x40
637#define UCOL_LOWER_CASE 0x00
638
639#define UCOL_CONTINUATION_MARKER 0xC0
640#define UCOL_REMOVE_CONTINUATION 0xFFFFFF3F
641
642#define isContinuation(CE) (((CE) & UCOL_CONTINUATION_MARKER) == UCOL_CONTINUATION_MARKER)
643#define isFlagged(CE) (((CE) & 0x80) == 0x80)
644#define isLongPrimary(CE) (((CE) & 0xC0) == 0xC0)
645
646#define getCETag(CE) (((CE)&UCOL_TAG_MASK)>>UCOL_TAG_SHIFT)
647#define isContraction(CE) (isSpecial((CE)) && (getCETag((CE)) == CONTRACTION_TAG))
648#define isPrefix(CE) (isSpecial((CE)) && (getCETag((CE)) == SPEC_PROC_TAG))
729e4ab9
A
649#define constructContractCE(tag, CE) (UCOL_SPECIAL_FLAG | ((tag)<<UCOL_TAG_SHIFT) | ((CE)&0xFFFFFF))
650#define constructSpecProcCE(CE) (UCOL_SPECIAL_FLAG | (SPEC_PROC_TAG<<UCOL_TAG_SHIFT) | ((CE)&0xFFFFFF))
b75a7d8f
A
651#define getContractOffset(CE) ((CE)&0xFFFFFF)
652#define getExpansionOffset(CE) (((CE)&0x00FFFFF0)>>4)
653#define getExpansionCount(CE) ((CE)&0xF)
654#define isCEIgnorable(CE) (((CE) & 0xFFFFFFBF) == 0)
655
656/* StringSearch internal use */
657#define inNormBuf(coleiter) ((coleiter)->iteratordata_.flags & UCOL_ITER_INNORMBUF)
658#define isFCDPointerNull(coleiter) ((coleiter)->iteratordata_.fcdPosition == NULL)
659#define hasExpansion(coleiter) ((coleiter)->iteratordata_.CEpos != (coleiter)->iteratordata_.CEs)
660#define getExpansionPrefix(coleiter) ((coleiter)->iteratordata_.toReturn - (coleiter)->iteratordata_.CEs)
661#define setExpansionPrefix(coleiter, offset) ((coleiter)->iteratordata_.CEs + offset)
662#define getExpansionSuffix(coleiter) ((coleiter)->iteratordata_.CEpos - (coleiter)->iteratordata_.toReturn)
663#define setExpansionSuffix(coleiter, offset) ((coleiter)->iteratordata_.toReturn = (coleiter)->iteratordata_.CEpos - leftoverces)
664
729e4ab9
A
665/* This is an enum that lists magic special byte values from the fractional UCA.
666 * See also http://site.icu-project.org/design/collation/bytes */
b75a7d8f
A
667/* TODO: all the #defines that refer to special byte values from the UCA should be changed to point here */
668
669enum {
670 UCOL_BYTE_ZERO = 0x00,
671 UCOL_BYTE_LEVEL_SEPARATOR = 0x01,
672 UCOL_BYTE_SORTKEY_GLUE = 0x02,
673 UCOL_BYTE_SHIFT_PREFIX = 0x03,
674 UCOL_BYTE_UNSHIFTED_MIN = UCOL_BYTE_SHIFT_PREFIX,
675 UCOL_BYTE_FIRST_TAILORED = 0x04,
676 UCOL_BYTE_COMMON = 0x05,
677 UCOL_BYTE_FIRST_UCA = UCOL_BYTE_COMMON,
729e4ab9
A
678 /* TODO: Make the following values dynamic since they change with almost every UCA version. */
679 UCOL_CODAN_PLACEHOLDER = 0x12,
680 UCOL_BYTE_FIRST_NON_LATIN_PRIMARY = 0x5B,
b75a7d8f
A
681 UCOL_BYTE_UNSHIFTED_MAX = 0xFF
682};
683
684#if 0
685#define UCOL_RESET_TOP_VALUE 0x9F000303
686#define UCOL_FIRST_PRIMARY_IGNORABLE 0x00008705
687#define UCOL_LAST_PRIMARY_IGNORABLE 0x0000DD05
688#define UCOL_LAST_PRIMARY_IGNORABLE_CONT 0x000051C0
689#define UCOL_FIRST_SECONDARY_IGNORABLE 0x00000000
690#define UCOL_LAST_SECONDARY_IGNORABLE 0x00000500
691#define UCOL_FIRST_TERTIARY_IGNORABLE 0x00000000
692#define UCOL_LAST_TERTIARY_IGNORABLE 0x00000000
693#define UCOL_FIRST_VARIABLE 0x05070505
694#define UCOL_LAST_VARIABLE 0x179B0505
695#define UCOL_FIRST_NON_VARIABLE 0x1A200505
696#define UCOL_LAST_NON_VARIABLE 0x7B41058F
697
698#define UCOL_NEXT_TOP_VALUE 0xE8960303
699#define UCOL_NEXT_FIRST_PRIMARY_IGNORABLE 0x00008905
700#define UCOL_NEXT_LAST_PRIMARY_IGNORABLE 0x03000303
701#define UCOL_NEXT_FIRST_SECONDARY_IGNORABLE 0x00008705
702#define UCOL_NEXT_LAST_SECONDARY_IGNORABLE 0x00000500
703#define UCOL_NEXT_FIRST_TERTIARY_IGNORABLE 0x00000000
704#define UCOL_NEXT_LAST_TERTIARY_IGNORABLE 0x00000000
705#define UCOL_NEXT_FIRST_VARIABLE 0x05090505
706#define UCOL_NEXT_LAST_VARIABLE 0x1A200505
707
708#define PRIMARY_IMPLICIT_MIN 0xE8000000
709#define PRIMARY_IMPLICIT_MAX 0xF0000000
710#endif
711
712/* These constants can be changed - sortkey size is affected by them */
713#define UCOL_PROPORTION2 0.5
714#define UCOL_PROPORTION3 0.667
715
716/* These values come from the UCA */
717#define UCOL_COMMON_BOT2 UCOL_BYTE_COMMON
718#define UCOL_COMMON_TOP2 0x86u
719#define UCOL_TOTAL2 (UCOL_COMMON_TOP2-UCOL_COMMON_BOT2-1)
720
721#define UCOL_FLAG_BIT_MASK_CASE_SW_OFF 0x80
722#define UCOL_FLAG_BIT_MASK_CASE_SW_ON 0x40
723#define UCOL_COMMON_TOP3_CASE_SW_OFF 0x85
724#define UCOL_COMMON_TOP3_CASE_SW_LOWER 0x45
725#define UCOL_COMMON_TOP3_CASE_SW_UPPER 0xC5
726
727/* These values come from the UCA */
728#define UCOL_COMMON_BOT3 0x05
729
730#define UCOL_COMMON_BOTTOM3_CASE_SW_UPPER 0x86;
731#define UCOL_COMMON_BOTTOM3_CASE_SW_LOWER UCOL_COMMON_BOT3;
732
733#define UCOL_TOP_COUNT2 (UCOL_PROPORTION2*UCOL_TOTAL2)
734#define UCOL_BOT_COUNT2 (UCOL_TOTAL2-UCOL_TOP_COUNT2)
735
736
737#define UCOL_COMMON2 UCOL_COMMON_BOT2
738#define UCOL_COMMON3_UPPERFIRST 0xC5
739#define UCOL_COMMON3_NORMAL UCOL_COMMON_BOT3
740
741#define UCOL_COMMON4 0xFF
742
743/* constants for case level/case first handling */
744/* used to instantiate UCollators fields in ucol_updateInternalState */
745#define UCOL_CASE_SWITCH 0xC0
746#define UCOL_NO_CASE_SWITCH 0x00
747
748#define UCOL_REMOVE_CASE 0x3F
749#define UCOL_KEEP_CASE 0xFF
750
751#define UCOL_CASE_BIT_MASK 0xC0
752
753#define UCOL_TERT_CASE_MASK 0xFF
754
755#define UCOL_ENDOFLATINONERANGE 0xFF
756#define UCOL_LATINONETABLELEN (UCOL_ENDOFLATINONERANGE+50)
757#define UCOL_BAIL_OUT_CE 0xFF000000
758
759
760typedef enum {
761 NOT_FOUND_TAG = 0,
762 EXPANSION_TAG = 1, /* This code point results in an expansion */
763 CONTRACTION_TAG = 2, /* Start of a contraction */
764 THAI_TAG = 3, /* Thai character - do the reordering */
765 CHARSET_TAG = 4, /* Charset processing, not yet implemented */
766 SURROGATE_TAG = 5, /* Lead surrogate that is tailored and doesn't start a contraction */
767 HANGUL_SYLLABLE_TAG = 6, /* AC00-D7AF*/
768 LEAD_SURROGATE_TAG = 7, /* D800-DBFF*/
769 TRAIL_SURROGATE_TAG = 8, /* DC00-DFFF*/
770 CJK_IMPLICIT_TAG = 9, /* 0x3400-0x4DB5, 0x4E00-0x9FA5, 0xF900-0xFA2D*/
771 IMPLICIT_TAG = 10,
772 SPEC_PROC_TAG = 11,
773 /* ICU 2.1 */
774 LONG_PRIMARY_TAG = 12, /* This is a three byte primary with starting secondaries and tertiaries */
775 /* It fits in a single 32 bit CE and is used instead of expansion to save */
776 /* space without affecting the performance (hopefully) */
777
374ca955
A
778 DIGIT_TAG = 13, /* COllate Digits As Numbers (CODAN) implementation */
779
b75a7d8f
A
780 CE_TAGS_COUNT
781} UColCETags;
782
783/*
784 *****************************************************************************************
785 * set to zero
786 * NON_CHARACTER FDD0 - FDEF, FFFE, FFFF, 1FFFE, 1FFFF, 2FFFE, 2FFFF,...e.g. **FFFE, **FFFF
787 ******************************************************************************************
788 */
789
790typedef struct {
791 uint32_t variableTopValue;
792 /*UColAttributeValue*/ int32_t frenchCollation;
793 /*UColAttributeValue*/ int32_t alternateHandling; /* attribute for handling variable elements*/
794 /*UColAttributeValue*/ int32_t caseFirst; /* who goes first, lower case or uppercase */
795 /*UColAttributeValue*/ int32_t caseLevel; /* do we have an extra case level */
796 /*UColAttributeValue*/ int32_t normalizationMode; /* attribute for normalization */
797 /*UColAttributeValue*/ int32_t strength; /* attribute for strength */
798 /*UColAttributeValue*/ int32_t hiraganaQ; /* attribute for special Hiragana */
374ca955
A
799 /*UColAttributeValue*/ int32_t numericCollation; /* attribute for numeric collation */
800 uint32_t reserved[15]; /* for future use */
b75a7d8f
A
801} UColOptionSet;
802
803typedef struct {
804 uint32_t UCA_FIRST_TERTIARY_IGNORABLE[2]; /*0x00000000*/
805 uint32_t UCA_LAST_TERTIARY_IGNORABLE[2]; /*0x00000000*/
806 uint32_t UCA_FIRST_PRIMARY_IGNORABLE[2]; /*0x00008705*/
807 uint32_t UCA_FIRST_SECONDARY_IGNORABLE[2]; /*0x00000000*/
808 uint32_t UCA_LAST_SECONDARY_IGNORABLE[2]; /*0x00000500*/
809 uint32_t UCA_LAST_PRIMARY_IGNORABLE[2]; /*0x0000DD05*/
810 uint32_t UCA_FIRST_VARIABLE[2]; /*0x05070505*/
811 uint32_t UCA_LAST_VARIABLE[2]; /*0x13CF0505*/
812 uint32_t UCA_FIRST_NON_VARIABLE[2]; /*0x16200505*/
813 uint32_t UCA_LAST_NON_VARIABLE[2]; /*0x767C0505*/
814 uint32_t UCA_RESET_TOP_VALUE[2]; /*0x9F000303*/
815 uint32_t UCA_FIRST_IMPLICIT[2];
816 uint32_t UCA_LAST_IMPLICIT[2];
817 uint32_t UCA_FIRST_TRAILING[2];
818 uint32_t UCA_LAST_TRAILING[2];
819
820#if 0
821 uint32_t UCA_NEXT_TOP_VALUE[2]; /*0xE8960303*/
822 uint32_t UCA_NEXT_FIRST_PRIMARY_IGNORABLE; /*0x00008905*/
823 uint32_t UCA_NEXT_LAST_PRIMARY_IGNORABLE; /*0x03000303*/
824 uint32_t UCA_NEXT_FIRST_SECONDARY_IGNORABLE; /*0x00008705*/
825 uint32_t UCA_NEXT_LAST_SECONDARY_IGNORABLE; /*0x00000500*/
826 uint32_t UCA_NEXT_FIRST_TERTIARY_IGNORABLE; /*0x00000000*/
827 uint32_t UCA_NEXT_LAST_TERTIARY_IGNORABLE; /*0x00000000*/
828 uint32_t UCA_NEXT_FIRST_VARIABLE; /*0x05090505*/
829 uint32_t UCA_NEXT_LAST_VARIABLE; /*0x16200505*/
830#endif
831
832 uint32_t UCA_PRIMARY_TOP_MIN;
833 uint32_t UCA_PRIMARY_IMPLICIT_MIN; /*0xE8000000*/
834 uint32_t UCA_PRIMARY_IMPLICIT_MAX; /*0xF0000000*/
835 uint32_t UCA_PRIMARY_TRAILING_MIN; /*0xE8000000*/
836 uint32_t UCA_PRIMARY_TRAILING_MAX; /*0xF0000000*/
837 uint32_t UCA_PRIMARY_SPECIAL_MIN; /*0xE8000000*/
838 uint32_t UCA_PRIMARY_SPECIAL_MAX; /*0xF0000000*/
839} UCAConstants;
840
841typedef struct {
842 int32_t size;
843 /* all the offsets are in bytes */
844 /* to get the address add to the header address and cast properly */
845 uint32_t options; /* these are the default options for the collator */
846 uint32_t UCAConsts; /* structure which holds values for indirect positioning and implicit ranges */
847 uint32_t contractionUCACombos; /* this one is needed only for UCA, to copy the appropriate contractions */
374ca955 848 uint32_t magic; /* magic number - lets us know whether reserved data is reset or junked */
b75a7d8f
A
849 uint32_t mappingPosition; /* const uint8_t *mappingPosition; */
850 uint32_t expansion; /* uint32_t *expansion; */
851 uint32_t contractionIndex; /* UChar *contractionIndex; */
852 uint32_t contractionCEs; /* uint32_t *contractionCEs; */
853 uint32_t contractionSize; /* needed for various closures */
854 /*int32_t latinOneMapping;*/ /* this is now handled in the trie itself *//* fast track to latin1 chars */
855
856 uint32_t endExpansionCE; /* array of last collation element in
857 expansion */
858 uint32_t expansionCESize; /* array of maximum expansion size
859 corresponding to the expansion
860 collation elements with last element
861 in endExpansionCE*/
862 int32_t endExpansionCECount; /* size of endExpansionCE */
863 uint32_t unsafeCP; /* hash table of unsafe code points */
864 uint32_t contrEndCP; /* hash table of final code points */
865 /* in contractions. */
866
374ca955
A
867 int32_t contractionUCACombosSize; /* number of UCA contraction items. */
868 /*Length is contractionUCACombosSize*contractionUCACombosWidth*sizeof(UChar) */
b75a7d8f 869 UBool jamoSpecial; /* is jamoSpecial */
374ca955
A
870 UBool isBigEndian; /* is this data big endian? from the UDataInfo header*/
871 uint8_t charSetFamily; /* what is the charset family of this data from the UDataInfo header*/
872 uint8_t contractionUCACombosWidth; /* width of UCA combos field */
b75a7d8f
A
873 UVersionInfo version;
874 UVersionInfo UCAVersion; /* version of the UCA, read from file */
875 UVersionInfo UCDVersion; /* UCD version, obtained by u_getUnicodeVersion */
374ca955 876 UVersionInfo formatVersion; /* format version from the UDataInfo header */
729e4ab9
A
877 uint32_t scriptToLeadByte; /* offset to script to lead collation byte mapping data */
878 uint32_t leadByteToScript; /* offset to lead collation byte to script mapping data */
879 uint8_t reserved[76]; /* for future use */
b75a7d8f
A
880} UCATableHeader;
881
882#define U_UNKNOWN_STATE 0
883#define U_COLLATOR_STATE 0x01
884#define U_STATE_LIMIT 0x02
885
886/* This is the first structure in a state */
887/* it should be machine independent */
888typedef struct {
889 /* this structure is supposed to be readable on all the platforms.*/
890 /* first 2 fields hold the size of the structure in a platform independent way */
891 uint8_t sizeLo;
892 uint8_t sizeHi;
893 /* identifying the writing platform */
894 uint8_t isBigEndian;
895 /* see U_CHARSET_FAMILY values in utypes.h */
896 uint8_t charsetFamily;
897 /* version of ICU this state structure comes from */
898 uint8_t icuVersion[4];
899 /* What is the data following this state */
900 uint8_t type;
901 /* more stuff to come, keep it on 16 byte boundary */
902 uint8_t reserved[7];
903} UStateStruct;
904
905/* This structure follows UStatusStruct */
906/* and contains data specific for the collators */
907/* Endianess needs to be decided before accessing this structure */
908/* However, it's size IS endianess independent */
909typedef struct {
910 /* size of this structure */
911 uint8_t sizeLo;
912 uint8_t sizeHi;
913 /* This state is followed by the frozen tailoring */
914 uint8_t containsTailoring;
915 /* This state is followed by the frozen UCA */
916 uint8_t containsUCA;
917 /* Version info - the same one */
918 uint8_t versionInfo[4];
919
920 /* for charset CEs */
921 uint8_t charsetName[32];
922 /* this is the resolved locale name*/
923 uint8_t locale[32];
924
925 /* Attributes. Open ended */
926 /* all the following will be moved to uint32_t because of portability */
927 /* variable top value */
928 uint32_t variableTopValue;
929 /* attribute for handling variable elements*/
930 uint32_t /*UColAttributeValue*/ alternateHandling;
931 /* how to handle secondary weights */
932 uint32_t /*UColAttributeValue*/ frenchCollation;
933 /* who goes first, lower case or uppercase */
934 uint32_t /*UColAttributeValue*/ caseFirst;
935 /* do we have an extra case level */
936 uint32_t /*UColAttributeValue*/ caseLevel;
937 /* attribute for normalization */
938 uint32_t /*UColAttributeValue*/ normalizationMode;
939 /* attribute for strength */
940 uint32_t /*UColAttributeValue*/ strength;
941 /* to be immediately 16 byte aligned */
942 uint8_t reserved[12];
943} UColStateStruct;
944
945#define UCOL_INV_SIZEMASK 0xFFF00000
946#define UCOL_INV_OFFSETMASK 0x000FFFFF
947#define UCOL_INV_SHIFTVALUE 20
948
949U_CDECL_BEGIN
950
951typedef struct {
952 uint32_t byteSize;
953 uint32_t tableSize;
954 uint32_t contsSize;
955 uint32_t table;
956 uint32_t conts;
957 UVersionInfo UCAVersion; /* version of the UCA, read from file */
958 uint8_t padding[8];
959} InverseUCATableHeader;
960
961typedef int32_t U_CALLCONV
962SortKeyGenerator(const UCollator *coll,
963 const UChar *source,
964 int32_t sourceLength,
965 uint8_t **result,
966 uint32_t resultLength,
967 UBool allocatePrimary,
968 UErrorCode *status);
969
73c04bcf
A
970typedef void U_CALLCONV
971ResourceCleaner(UCollator *coll);
972
973
b75a7d8f
A
974struct UCollator {
975 UColOptionSet *options;
976 SortKeyGenerator *sortKeyGen;
977 uint32_t *latinOneCEs;
46f4442e 978 char* actualLocale;
b75a7d8f
A
979 char* validLocale;
980 char* requestedLocale;
73c04bcf 981 const UChar *rules;
46f4442e 982 const UChar *ucaRules;
73c04bcf 983 const UCollator *UCA;
b75a7d8f 984 const UCATableHeader *image;
73c04bcf 985 UTrie mapping;
b75a7d8f
A
986 const uint32_t *latinOneMapping;
987 const uint32_t *expansion;
988 const UChar *contractionIndex;
989 const uint32_t *contractionCEs;
b75a7d8f
A
990
991 const uint32_t *endExpansionCE; /* array of last ces in an expansion ce.
992 corresponds to expansionCESize */
993 const uint32_t *lastEndExpansionCE;/* pointer to the last element in endExpansionCE */
994 const uint8_t *expansionCESize; /* array of the maximum size of a
995 expansion ce with the last ce
996 corresponding to endExpansionCE,
997 terminated with a null */
998 const uint8_t *unsafeCP; /* unsafe code points hashtable */
999 const uint8_t *contrEndCP; /* Contraction ending chars hash table */
1000 UChar minUnsafeCP; /* Smallest unsafe Code Point. */
1001 UChar minContrEndCP; /* Smallest code point at end of a contraction */
1002
b75a7d8f
A
1003 int32_t rulesLength;
1004 int32_t latinOneTableLen;
1005
b75a7d8f
A
1006 uint32_t variableTopValue;
1007 UColAttributeValue frenchCollation;
1008 UColAttributeValue alternateHandling; /* attribute for handling variable elements*/
1009 UColAttributeValue caseFirst; /* who goes first, lower case or uppercase */
1010 UColAttributeValue caseLevel; /* do we have an extra case level */
1011 UColAttributeValue normalizationMode; /* attribute for normalization */
1012 UColAttributeValue strength; /* attribute for strength */
1013 UColAttributeValue hiraganaQ; /* attribute for Hiragana */
1014 UColAttributeValue numericCollation;
1015 UBool variableTopValueisDefault;
1016 UBool frenchCollationisDefault;
1017 UBool alternateHandlingisDefault; /* attribute for handling variable elements*/
1018 UBool caseFirstisDefault; /* who goes first, lower case or uppercase */
1019 UBool caseLevelisDefault; /* do we have an extra case level */
1020 UBool normalizationModeisDefault; /* attribute for normalization */
1021 UBool strengthisDefault; /* attribute for strength */
1022 UBool hiraganaQisDefault; /* attribute for Hiragana */
1023 UBool numericCollationisDefault;
1024 UBool hasRealData; /* some collators have only options, like French, no rules */
1025 /* to speed up things, we use the UCA image, but we don't want it */
1026 /* to run around */
1027
1028 UBool freeOnClose;
1029 UBool freeOptionsOnClose;
1030 UBool freeRulesOnClose;
1031 UBool freeImageOnClose;
1032
1033 UBool latinOneUse;
1034 UBool latinOneRegenTable;
1035 UBool latinOneFailed;
1036
46f4442e 1037 int8_t tertiaryAddition; /* when switching case, we need to add or subtract different values */
b75a7d8f
A
1038 uint8_t caseSwitch;
1039 uint8_t tertiaryCommon;
1040 uint8_t tertiaryMask;
1041 uint8_t tertiaryTop; /* Upper range when compressing */
1042 uint8_t tertiaryBottom; /* Upper range when compressing */
1043 uint8_t tertiaryTopCount;
1044 uint8_t tertiaryBottomCount;
1045
73c04bcf 1046 UVersionInfo dataVersion; /* Data info of UCA table */
729e4ab9
A
1047 int32_t* reorderCodes;
1048 int32_t reorderCodesLength;
1049 uint8_t* leadBytePermutationTable;
b75a7d8f
A
1050};
1051
1052U_CDECL_END
1053
1054/* various internal functions */
1055
1056/* do not close UCA returned by ucol_initUCA! */
1057U_CFUNC
1058UCollator* ucol_initUCA(UErrorCode *status);
1059
1060U_CFUNC
374ca955 1061UCollator* ucol_initCollator(const UCATableHeader *image, UCollator *fillIn, const UCollator *UCA, UErrorCode *status);
b75a7d8f
A
1062
1063U_CFUNC
1064void ucol_setOptionsFromHeader(UCollator* result, UColOptionSet * opts, UErrorCode *status);
1065
1066U_CFUNC
1067UCollator* ucol_open_internal(const char* loc, UErrorCode* status);
1068
1069#if 0
1070U_CFUNC
1071void ucol_putOptionsToHeader(UCollator* result, UColOptionSet * opts, UErrorCode *status);
1072#endif
1073
1074U_CFUNC
1075void ucol_updateInternalState(UCollator *coll, UErrorCode *status);
1076
46f4442e 1077U_CFUNC uint32_t U_EXPORT2 ucol_getFirstCE(const UCollator *coll, UChar u, UErrorCode *status);
b75a7d8f
A
1078U_CAPI UBool U_EXPORT2 ucol_isTailored(const UCollator *coll, const UChar u, UErrorCode *status);
1079
1080U_CAPI const InverseUCATableHeader* U_EXPORT2 ucol_initInverseUCA(UErrorCode *status);
374ca955 1081
b75a7d8f 1082U_CAPI void U_EXPORT2
46f4442e 1083uprv_uca_initImplicitConstants(UErrorCode *status);
374ca955
A
1084
1085U_CAPI uint32_t U_EXPORT2
1086uprv_uca_getImplicitFromRaw(UChar32 cp);
1087
46f4442e
A
1088/*U_CFUNC uint32_t U_EXPORT2
1089uprv_uca_getImplicitPrimary(UChar32 cp);*/
374ca955
A
1090
1091U_CAPI UChar32 U_EXPORT2
1092uprv_uca_getRawFromImplicit(uint32_t implicit);
1093
1094U_CAPI UChar32 U_EXPORT2
1095uprv_uca_getRawFromCodePoint(UChar32 i);
1096
1097U_CAPI UChar32 U_EXPORT2
1098uprv_uca_getCodePointFromRaw(UChar32 i);
1099
729e4ab9
A
1100typedef const UChar* GetCollationRulesFunction(void* context, const char* locale, const char* type, int32_t* pLength, UErrorCode* status);
1101
1102U_CAPI UCollator* U_EXPORT2
1103ucol_openRulesForImport( const UChar *rules,
1104 int32_t rulesLength,
1105 UColAttributeValue normalizationMode,
1106 UCollationStrength strength,
1107 UParseError *parseError,
1108 GetCollationRulesFunction importFunc,
1109 void* context,
1110 UErrorCode *status);
1111
1112
1113U_CAPI void U_EXPORT2 ucol_buildPermutationTable(UCollator *coll, UErrorCode *status);
374ca955 1114
b75a7d8f
A
1115
1116#ifdef XP_CPLUSPLUS
1117/*
1118 * Test whether a character is potentially "unsafe" for use as a collation
1119 * starting point. Unsafe chars are those with combining class != 0 plus
1120 * those that are the 2nd thru nth character in a contraction sequence.
1121 *
1122 * Function is in header file because it's used in both collation and string search,
1123 * and needs to be inline for performance.
1124 */
1125static inline UBool ucol_unsafeCP(UChar c, const UCollator *coll) {
1126 int32_t hash;
1127 uint8_t htbyte;
1128
1129 if (c < coll->minUnsafeCP) {
1130 return FALSE;
1131 }
1132
1133 hash = c;
1134 if (hash >= UCOL_UNSAFECP_TABLE_SIZE*8) {
46f4442e
A
1135 if(UTF_IS_SURROGATE(c)) {
1136 /* Lead or trail surrogate */
b75a7d8f
A
1137 /* These are always considered unsafe. */
1138 return TRUE;
1139 }
1140 hash = (hash & UCOL_UNSAFECP_TABLE_MASK) + 256;
1141 }
1142 htbyte = coll->unsafeCP[hash>>3];
46f4442e 1143 return ((htbyte >> (hash & 7)) & 1);
b75a7d8f
A
1144}
1145#endif /* XP_CPLUSPLUS */
1146
46f4442e 1147/* The offsetBuffer in collIterate might need to be freed to avoid memory leaks. */
729e4ab9 1148void ucol_freeOffsetBuffer(U_NAMESPACE_QUALIFIER collIterate *s);
b75a7d8f
A
1149
1150#endif /* #if !UCONFIG_NO_COLLATION */
1151
1152#endif