2 *******************************************************************************
3 * Copyright (C) 2012-2014, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
8 * created on: 2012dec17
9 * created by: Markus W. Scherer
12 #include "unicode/utypes.h"
14 #if !UCONFIG_NO_COLLATION
16 #include "unicode/coll.h"
17 #include "unicode/udata.h"
18 #include "collation.h"
19 #include "collationdata.h"
20 #include "collationdatareader.h"
21 #include "collationroot.h"
22 #include "collationsettings.h"
23 #include "collationtailoring.h"
24 #include "normalizer2impl.h"
33 static const CollationTailoring
*rootSingleton
= NULL
;
34 static UInitOnce initOnce
= U_INITONCE_INITIALIZER
;
40 static UBool U_CALLCONV
uprv_collation_root_cleanup() {
41 SharedObject::clearPtr(rootSingleton
);
49 CollationRoot::load(UErrorCode
&errorCode
) {
50 if(U_FAILURE(errorCode
)) { return; }
51 LocalPointer
<CollationTailoring
> t(new CollationTailoring(NULL
));
52 if(t
.isNull() || t
->isBogus()) {
53 errorCode
= U_MEMORY_ALLOCATION_ERROR
;
56 t
->memory
= udata_openChoice(U_ICUDATA_NAME U_TREE_SEPARATOR_STRING
"coll",
58 CollationDataReader::isAcceptable
, t
->version
, &errorCode
);
59 if(U_FAILURE(errorCode
)) { return; }
60 const uint8_t *inBytes
= static_cast<const uint8_t *>(udata_getMemory(t
->memory
));
61 CollationDataReader::read(NULL
, inBytes
, udata_getLength(t
->memory
), *t
, errorCode
);
62 if(U_FAILURE(errorCode
)) { return; }
63 ucln_i18n_registerCleanup(UCLN_I18N_COLLATION_ROOT
, uprv_collation_root_cleanup
);
64 t
->addRef(); // The rootSingleton takes ownership.
65 rootSingleton
= t
.orphan();
68 const CollationTailoring
*
69 CollationRoot::getRoot(UErrorCode
&errorCode
) {
70 umtx_initOnce(initOnce
, CollationRoot::load
, errorCode
);
71 if(U_FAILURE(errorCode
)) { return NULL
; }
76 CollationRoot::getData(UErrorCode
&errorCode
) {
77 const CollationTailoring
*root
= getRoot(errorCode
);
78 if(U_FAILURE(errorCode
)) { return NULL
; }
82 const CollationSettings
*
83 CollationRoot::getSettings(UErrorCode
&errorCode
) {
84 const CollationTailoring
*root
= getRoot(errorCode
);
85 if(U_FAILURE(errorCode
)) { return NULL
; }
86 return root
->settings
;
91 #endif // !UCONFIG_NO_COLLATION