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