intl/icu/source/i18n/ucol_imp.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial