Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: source/i18n/collationroot.cpp

Issue 845603002: Update ICU to 54.1 step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: remove unusued directories Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « source/i18n/collationroot.h ('k') | source/i18n/collationrootelements.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: source/i18n/collationroot.cpp
diff --git a/source/i18n/collationroot.cpp b/source/i18n/collationroot.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..749f05c51c3a2f2d51f029ffc547dbbc6f893657
--- /dev/null
+++ b/source/i18n/collationroot.cpp
@@ -0,0 +1,102 @@
+/*
+*******************************************************************************
+* Copyright (C) 2012-2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* collationroot.cpp
+*
+* created on: 2012dec17
+* created by: Markus W. Scherer
+*/
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_COLLATION
+
+#include "unicode/coll.h"
+#include "unicode/udata.h"
+#include "collation.h"
+#include "collationdata.h"
+#include "collationdatareader.h"
+#include "collationroot.h"
+#include "collationsettings.h"
+#include "collationtailoring.h"
+#include "normalizer2impl.h"
+#include "ucln_in.h"
+#include "udatamem.h"
+#include "umutex.h"
+
+U_NAMESPACE_BEGIN
+
+namespace {
+
+static const CollationCacheEntry *rootSingleton = NULL;
+static UInitOnce initOnce = U_INITONCE_INITIALIZER;
+
+} // namespace
+
+U_CDECL_BEGIN
+
+static UBool U_CALLCONV uprv_collation_root_cleanup() {
+ SharedObject::clearPtr(rootSingleton);
+ initOnce.reset();
+ return TRUE;
+}
+
+U_CDECL_END
+
+void
+CollationRoot::load(UErrorCode &errorCode) {
+ if(U_FAILURE(errorCode)) { return; }
+ LocalPointer<CollationTailoring> t(new CollationTailoring(NULL));
+ if(t.isNull() || t->isBogus()) {
+ errorCode = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
+ t->memory = udata_openChoice(U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "coll",
+ "icu", "ucadata",
+ CollationDataReader::isAcceptable, t->version, &errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ const uint8_t *inBytes = static_cast<const uint8_t *>(udata_getMemory(t->memory));
+ CollationDataReader::read(NULL, inBytes, udata_getLength(t->memory), *t, errorCode);
+ if(U_FAILURE(errorCode)) { return; }
+ ucln_i18n_registerCleanup(UCLN_I18N_COLLATION_ROOT, uprv_collation_root_cleanup);
+ CollationCacheEntry *entry = new CollationCacheEntry(Locale::getRoot(), t.getAlias());
+ if(entry != NULL) {
+ t.orphan(); // The rootSingleton took ownership of the tailoring.
+ entry->addRef();
+ rootSingleton = entry;
+ }
+}
+
+const CollationCacheEntry *
+CollationRoot::getRootCacheEntry(UErrorCode &errorCode) {
+ umtx_initOnce(initOnce, CollationRoot::load, errorCode);
+ if(U_FAILURE(errorCode)) { return NULL; }
+ return rootSingleton;
+}
+
+const CollationTailoring *
+CollationRoot::getRoot(UErrorCode &errorCode) {
+ umtx_initOnce(initOnce, CollationRoot::load, errorCode);
+ if(U_FAILURE(errorCode)) { return NULL; }
+ return rootSingleton->tailoring;
+}
+
+const CollationData *
+CollationRoot::getData(UErrorCode &errorCode) {
+ const CollationTailoring *root = getRoot(errorCode);
+ if(U_FAILURE(errorCode)) { return NULL; }
+ return root->data;
+}
+
+const CollationSettings *
+CollationRoot::getSettings(UErrorCode &errorCode) {
+ const CollationTailoring *root = getRoot(errorCode);
+ if(U_FAILURE(errorCode)) { return NULL; }
+ return root->settings;
+}
+
+U_NAMESPACE_END
+
+#endif // !UCONFIG_NO_COLLATION
« no previous file with comments | « source/i18n/collationroot.h ('k') | source/i18n/collationrootelements.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698