1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2013-2015, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * collationtailoring.cpp
10 * created on: 2013mar12
11 * created by: Markus W. Scherer
14 #include "unicode/utypes.h"
16 #if !UCONFIG_NO_COLLATION
18 #include "unicode/udata.h"
19 #include "unicode/unistr.h"
20 #include "unicode/ures.h"
21 #include "unicode/uversion.h"
22 #include "unicode/uvernum.h"
24 #include "collationdata.h"
25 #include "collationsettings.h"
26 #include "collationtailoring.h"
27 #include "normalizer2impl.h"
35 CollationTailoring::CollationTailoring(const CollationSettings
*baseSettings
)
36 : data(NULL
), settings(baseSettings
),
39 builder(NULL
), memory(NULL
), bundle(NULL
),
40 trie(NULL
), unsafeBackwardSet(NULL
),
42 if(baseSettings
!= NULL
) {
43 U_ASSERT(baseSettings
->reorderCodesLength
== 0);
44 U_ASSERT(baseSettings
->reorderTable
== NULL
);
45 U_ASSERT(baseSettings
->minHighNoReorder
== 0);
47 settings
= new CollationSettings();
49 if(settings
!= NULL
) {
52 rules
.getTerminatedBuffer(); // ensure NUL-termination
53 version
[0] = version
[1] = version
[2] = version
[3] = 0;
54 maxExpansionsInitOnce
.reset();
57 CollationTailoring::~CollationTailoring() {
58 SharedObject::clearPtr(settings
);
64 delete unsafeBackwardSet
;
65 uhash_close(maxExpansions
);
66 maxExpansionsInitOnce
.reset();
70 CollationTailoring::ensureOwnedData(UErrorCode
&errorCode
) {
71 if(U_FAILURE(errorCode
)) { return FALSE
; }
72 if(ownedData
== NULL
) {
73 const Normalizer2Impl
*nfcImpl
= Normalizer2Factory::getNFCImpl(errorCode
);
74 if(U_FAILURE(errorCode
)) { return FALSE
; }
75 ownedData
= new CollationData(*nfcImpl
);
76 if(ownedData
== NULL
) {
77 errorCode
= U_MEMORY_ALLOCATION_ERROR
;
86 CollationTailoring::makeBaseVersion(const UVersionInfo ucaVersion
, UVersionInfo version
) {
87 version
[0] = UCOL_BUILDER_VERSION
;
88 version
[1] = (ucaVersion
[0] << 3) + ucaVersion
[1];
89 version
[2] = ucaVersion
[2] << 6;
94 CollationTailoring::setVersion(const UVersionInfo baseVersion
, const UVersionInfo rulesVersion
) {
95 version
[0] = UCOL_BUILDER_VERSION
;
96 version
[1] = baseVersion
[1];
97 version
[2] = (baseVersion
[2] & 0xc0) + ((rulesVersion
[0] + (rulesVersion
[0] >> 6)) & 0x3f);
98 version
[3] = (rulesVersion
[1] << 3) + (rulesVersion
[1] >> 5) + rulesVersion
[2] +
99 (rulesVersion
[3] << 4) + (rulesVersion
[3] >> 4);
103 CollationTailoring::getUCAVersion() const {
104 return ((int32_t)version
[1] << 4) | (version
[2] >> 6);
107 CollationCacheEntry::~CollationCacheEntry() {
108 SharedObject::clearPtr(tailoring
);
113 #endif // !UCONFIG_NO_COLLATION