2 *******************************************************************************
3 * Copyright (C) 2013-2015, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
6 * collationtailoring.cpp
8 * created on: 2013mar12
9 * created by: Markus W. Scherer
12 #include "unicode/utypes.h"
14 #if !UCONFIG_NO_COLLATION
16 #include "unicode/udata.h"
17 #include "unicode/unistr.h"
18 #include "unicode/ures.h"
19 #include "unicode/uversion.h"
20 #include "unicode/uvernum.h"
22 #include "collationdata.h"
23 #include "collationsettings.h"
24 #include "collationtailoring.h"
25 #include "normalizer2impl.h"
33 CollationTailoring::CollationTailoring(const CollationSettings
*baseSettings
)
34 : data(NULL
), settings(baseSettings
),
37 builder(NULL
), memory(NULL
), bundle(NULL
),
38 trie(NULL
), unsafeBackwardSet(NULL
),
40 if(baseSettings
!= NULL
) {
41 U_ASSERT(baseSettings
->reorderCodesLength
== 0);
42 U_ASSERT(baseSettings
->reorderTable
== NULL
);
43 U_ASSERT(baseSettings
->minHighNoReorder
== 0);
45 settings
= new CollationSettings();
47 if(settings
!= NULL
) {
50 rules
.getTerminatedBuffer(); // ensure NUL-termination
51 version
[0] = version
[1] = version
[2] = version
[3] = 0;
52 maxExpansionsInitOnce
.reset();
55 CollationTailoring::~CollationTailoring() {
56 SharedObject::clearPtr(settings
);
62 delete unsafeBackwardSet
;
63 uhash_close(maxExpansions
);
64 maxExpansionsInitOnce
.reset();
68 CollationTailoring::ensureOwnedData(UErrorCode
&errorCode
) {
69 if(U_FAILURE(errorCode
)) { return FALSE
; }
70 if(ownedData
== NULL
) {
71 const Normalizer2Impl
*nfcImpl
= Normalizer2Factory::getNFCImpl(errorCode
);
72 if(U_FAILURE(errorCode
)) { return FALSE
; }
73 ownedData
= new CollationData(*nfcImpl
);
74 if(ownedData
== NULL
) {
75 errorCode
= U_MEMORY_ALLOCATION_ERROR
;
84 CollationTailoring::makeBaseVersion(const UVersionInfo ucaVersion
, UVersionInfo version
) {
85 version
[0] = UCOL_BUILDER_VERSION
;
86 version
[1] = (ucaVersion
[0] << 3) + ucaVersion
[1];
87 version
[2] = ucaVersion
[2] << 6;
92 CollationTailoring::setVersion(const UVersionInfo baseVersion
, const UVersionInfo rulesVersion
) {
93 version
[0] = UCOL_BUILDER_VERSION
;
94 version
[1] = baseVersion
[1];
95 version
[2] = (baseVersion
[2] & 0xc0) + ((rulesVersion
[0] + (rulesVersion
[0] >> 6)) & 0x3f);
96 version
[3] = (rulesVersion
[1] << 3) + (rulesVersion
[1] >> 5) + rulesVersion
[2] +
97 (rulesVersion
[3] << 4) + (rulesVersion
[3] >> 4);
101 CollationTailoring::getUCAVersion() const {
102 return ((int32_t)version
[1] << 4) | (version
[2] >> 6);
105 CollationCacheEntry::~CollationCacheEntry() {
106 SharedObject::clearPtr(tailoring
);
111 #endif // !UCONFIG_NO_COLLATION