1fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius/* 2fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius******************************************************************************* 31b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert* Copyright (C) 2013-2015, International Business Machines 4fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius* Corporation and others. All Rights Reserved. 5fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius******************************************************************************* 6fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius* collationfastlatinbuilder.h 7fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius* 8fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius* created on: 2013aug09 9fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius* created by: Markus W. Scherer 10fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius*/ 11fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 12fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius#ifndef __COLLATIONFASTLATINBUILDER_H__ 13fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius#define __COLLATIONFASTLATINBUILDER_H__ 14fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 15fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius#include "unicode/utypes.h" 16fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 17fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius#if !UCONFIG_NO_COLLATION 18fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 19fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius#include "unicode/unistr.h" 20fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius#include "unicode/uobject.h" 21fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius#include "collation.h" 22fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius#include "collationfastlatin.h" 23fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius#include "uvectr64.h" 24fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 25fceb39872958b9fa2505e63f8b8699a9e0f882f4ccorneliusU_NAMESPACE_BEGIN 26fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 27fceb39872958b9fa2505e63f8b8699a9e0f882f4ccorneliusstruct CollationData; 28fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 29fceb39872958b9fa2505e63f8b8699a9e0f882f4ccorneliusclass U_I18N_API CollationFastLatinBuilder : public UObject { 30fceb39872958b9fa2505e63f8b8699a9e0f882f4ccorneliuspublic: 31fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius CollationFastLatinBuilder(UErrorCode &errorCode); 32fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius ~CollationFastLatinBuilder(); 33fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 34fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius UBool forData(const CollationData &data, UErrorCode &errorCode); 35fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 36fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius const uint16_t *getTable() const { 37fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius return reinterpret_cast<const uint16_t *>(result.getBuffer()); 38fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius } 39fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius int32_t lengthOfTable() const { return result.length(); } 40fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 41fceb39872958b9fa2505e63f8b8699a9e0f882f4ccorneliusprivate: 421b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert // space, punct, symbol, currency (not digit) 431b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert enum { NUM_SPECIAL_GROUPS = UCOL_REORDER_CODE_CURRENCY - UCOL_REORDER_CODE_FIRST + 1 }; 441b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert 45fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius UBool loadGroups(const CollationData &data, UErrorCode &errorCode); 46fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius UBool inSameGroup(uint32_t p, uint32_t q) const; 47fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 48fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius void resetCEs(); 49fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius void getCEs(const CollationData &data, UErrorCode &errorCode); 50fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius UBool getCEsFromCE32(const CollationData &data, UChar32 c, uint32_t ce32, 51fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius UErrorCode &errorCode); 52fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius UBool getCEsFromContractionCE32(const CollationData &data, uint32_t ce32, 53fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius UErrorCode &errorCode); 54fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius void addContractionEntry(int32_t x, int64_t cce0, int64_t cce1, UErrorCode &errorCode); 55fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius void addUniqueCE(int64_t ce, UErrorCode &errorCode); 56fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius uint32_t getMiniCE(int64_t ce) const; 57fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius UBool encodeUniqueCEs(UErrorCode &errorCode); 58fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius UBool encodeCharCEs(UErrorCode &errorCode); 59fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius UBool encodeContractions(UErrorCode &errorCode); 60fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius uint32_t encodeTwoCEs(int64_t first, int64_t second) const; 61fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 62fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius static UBool isContractionCharCE(int64_t ce) { 63fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius return (uint32_t)(ce >> 32) == Collation::NO_CE_PRIMARY && ce != Collation::NO_CE; 64fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius } 65fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 66fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius static const uint32_t CONTRACTION_FLAG = 0x80000000; 67fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 68fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius // temporary "buffer" 69fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius int64_t ce0, ce1; 70fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 71fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius int64_t charCEs[CollationFastLatin::NUM_FAST_CHARS][2]; 72fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 73fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius UVector64 contractionCEs; 74fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius UVector64 uniqueCEs; 75fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 76fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius /** One 16-bit mini CE per unique CE. */ 77fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius uint16_t *miniCEs; 78fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 791b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert // These are constant for a given root collator. 801b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert uint32_t lastSpecialPrimaries[NUM_SPECIAL_GROUPS]; 81fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius uint32_t firstDigitPrimary; 82fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius uint32_t firstLatinPrimary; 83fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius uint32_t lastLatinPrimary; 84fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius // This determines the first normal primary weight which is mapped to 85fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius // a short mini primary. It must be >=firstDigitPrimary. 86fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius uint32_t firstShortPrimary; 87fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 88fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius UBool shortPrimaryOverflow; 89fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 90fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius UnicodeString result; 91fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius int32_t headerLength; 92fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius}; 93fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 94fceb39872958b9fa2505e63f8b8699a9e0f882f4ccorneliusU_NAMESPACE_END 95fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius 96fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius#endif // !UCONFIG_NO_COLLATION 97fceb39872958b9fa2505e63f8b8699a9e0f882f4ccornelius#endif // __COLLATIONFASTLATINBUILDER_H__ 98