2 *******************************************************************************
3 * Copyright (C) 2013-2014, 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
);
44 settings
= new CollationSettings();
46 if(settings
!= NULL
) {
49 rules
.getTerminatedBuffer(); // ensure NUL-termination
50 version
[0] = version
[1] = version
[2] = version
[3] = 0;
51 maxExpansionsInitOnce
.reset();
54 CollationTailoring::~CollationTailoring() {
55 SharedObject::clearPtr(settings
);
61 delete unsafeBackwardSet
;
62 uhash_close(maxExpansions
);
63 maxExpansionsInitOnce
.reset();
67 CollationTailoring::ensureOwnedData(UErrorCode
&errorCode
) {
68 if(U_FAILURE(errorCode
)) { return FALSE
; }
69 if(ownedData
== NULL
) {
70 const Normalizer2Impl
*nfcImpl
= Normalizer2Factory::getNFCImpl(errorCode
);
71 if(U_FAILURE(errorCode
)) { return FALSE
; }
72 ownedData
= new CollationData(*nfcImpl
);
73 if(ownedData
== NULL
) {
74 errorCode
= U_MEMORY_ALLOCATION_ERROR
;
83 CollationTailoring::makeBaseVersion(const UVersionInfo ucaVersion
, UVersionInfo version
) {
84 version
[0] = UCOL_BUILDER_VERSION
;
85 version
[1] = (ucaVersion
[0] << 3) + ucaVersion
[1];
86 version
[2] = ucaVersion
[2] << 6;
91 CollationTailoring::setVersion(const UVersionInfo baseVersion
, const UVersionInfo rulesVersion
) {
92 version
[0] = UCOL_BUILDER_VERSION
;
93 version
[1] = baseVersion
[1];
94 version
[2] = (baseVersion
[2] & 0xc0) + ((rulesVersion
[0] + (rulesVersion
[0] >> 6)) & 0x3f);
95 version
[3] = (rulesVersion
[1] << 3) + (rulesVersion
[1] >> 5) + rulesVersion
[2] +
96 (rulesVersion
[3] << 4) + (rulesVersion
[3] >> 4);
100 CollationTailoring::getUCAVersion() const {
101 return ((int32_t)version
[1] << 4) | (version
[2] >> 6);
106 #endif // !UCONFIG_NO_COLLATION