]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/normalizer2.cpp
ICU-64243.0.1.tar.gz
[apple/icu.git] / icuSources / common / normalizer2.cpp
index 0f12dfcff42fbdab0dcb7edc82b4d8691f3c3725..6be7e0b21a2bf9ec31cf3e2767e6d2511fc04292 100644 (file)
 
 using icu::Normalizer2Impl;
 
+#if NORM2_HARDCODE_NFC_DATA
 // NFC/NFD data machine-generated by gennorm2 --csource
 #define INCLUDED_FROM_NORMALIZER2_CPP
 #include "norm2_nfc_data.h"
+#endif
 
 U_NAMESPACE_BEGIN
 
@@ -176,6 +178,36 @@ FCDNormalizer2::~FCDNormalizer2() {}
 
 // instance cache ---------------------------------------------------------- ***
 
+U_CDECL_BEGIN
+static UBool U_CALLCONV uprv_normalizer2_cleanup();
+U_CDECL_END
+
+static Normalizer2   *noopSingleton;
+static icu::UInitOnce noopInitOnce = U_INITONCE_INITIALIZER;
+
+static void U_CALLCONV initNoopSingleton(UErrorCode &errorCode) {
+    if(U_FAILURE(errorCode)) {
+        return;
+    }
+    noopSingleton=new NoopNormalizer2;
+    if(noopSingleton==NULL) {
+        errorCode=U_MEMORY_ALLOCATION_ERROR;
+        return;
+    }
+    ucln_common_registerCleanup(UCLN_COMMON_NORMALIZER2, uprv_normalizer2_cleanup);
+}
+
+const Normalizer2 *Normalizer2Factory::getNoopInstance(UErrorCode &errorCode) {
+    if(U_FAILURE(errorCode)) { return NULL; }
+    umtx_initOnce(noopInitOnce, &initNoopSingleton, errorCode);
+    return noopSingleton;
+}
+
+const Normalizer2Impl *
+Normalizer2Factory::getImpl(const Normalizer2 *norm2) {
+    return &((Normalizer2WithImpl *)norm2)->impl;
+}
+
 Norm2AllModes::~Norm2AllModes() {
     delete impl;
 }
@@ -195,6 +227,7 @@ Norm2AllModes::createInstance(Normalizer2Impl *impl, UErrorCode &errorCode) {
     return allModes;
 }
 
+#if NORM2_HARDCODE_NFC_DATA
 Norm2AllModes *
 Norm2AllModes::createNFCInstance(UErrorCode &errorCode) {
     if(U_FAILURE(errorCode)) {
@@ -210,48 +243,15 @@ Norm2AllModes::createNFCInstance(UErrorCode &errorCode) {
     return createInstance(impl, errorCode);
 }
 
-U_CDECL_BEGIN
-static UBool U_CALLCONV uprv_normalizer2_cleanup();
-U_CDECL_END
-
 static Norm2AllModes *nfcSingleton;
-static Normalizer2   *noopSingleton;
 
 static icu::UInitOnce nfcInitOnce = U_INITONCE_INITIALIZER;
-static icu::UInitOnce noopInitOnce = U_INITONCE_INITIALIZER;
 
-// UInitOnce singleton initialization functions
 static void U_CALLCONV initNFCSingleton(UErrorCode &errorCode) {
     nfcSingleton=Norm2AllModes::createNFCInstance(errorCode);
     ucln_common_registerCleanup(UCLN_COMMON_NORMALIZER2, uprv_normalizer2_cleanup);
 }
 
-static void U_CALLCONV initNoopSingleton(UErrorCode &errorCode) {
-    if(U_FAILURE(errorCode)) {
-        return;
-    }
-    noopSingleton=new NoopNormalizer2;
-    if(noopSingleton==NULL) {
-        errorCode=U_MEMORY_ALLOCATION_ERROR;
-        return;
-    }
-    ucln_common_registerCleanup(UCLN_COMMON_NORMALIZER2, uprv_normalizer2_cleanup);
-}
-
-U_CDECL_BEGIN
-
-static UBool U_CALLCONV uprv_normalizer2_cleanup() {
-    delete nfcSingleton;
-    nfcSingleton = NULL;
-    delete noopSingleton;
-    noopSingleton = NULL;
-    nfcInitOnce.reset(); 
-    noopInitOnce.reset(); 
-    return TRUE;
-}
-
-U_CDECL_END
-
 const Norm2AllModes *
 Norm2AllModes::getNFCInstance(UErrorCode &errorCode) {
     if(U_FAILURE(errorCode)) { return NULL; }
@@ -281,23 +281,29 @@ const Normalizer2 *Normalizer2Factory::getFCCInstance(UErrorCode &errorCode) {
     return allModes!=NULL ? &allModes->fcc : NULL;
 }
 
-const Normalizer2 *Normalizer2Factory::getNoopInstance(UErrorCode &errorCode) {
-    if(U_FAILURE(errorCode)) { return NULL; }
-    umtx_initOnce(noopInitOnce, &initNoopSingleton, errorCode);
-    return noopSingleton;
-}
-
 const Normalizer2Impl *
 Normalizer2Factory::getNFCImpl(UErrorCode &errorCode) {
     const Norm2AllModes *allModes=Norm2AllModes::getNFCInstance(errorCode);
     return allModes!=NULL ? allModes->impl : NULL;
 }
+#endif  // NORM2_HARDCODE_NFC_DATA
 
-const Normalizer2Impl *
-Normalizer2Factory::getImpl(const Normalizer2 *norm2) {
-    return &((Normalizer2WithImpl *)norm2)->impl;
+U_CDECL_BEGIN
+
+static UBool U_CALLCONV uprv_normalizer2_cleanup() {
+    delete noopSingleton;
+    noopSingleton = NULL;
+    noopInitOnce.reset(); 
+#if NORM2_HARDCODE_NFC_DATA
+    delete nfcSingleton;
+    nfcSingleton = NULL;
+    nfcInitOnce.reset(); 
+#endif
+    return TRUE;
 }
 
+U_CDECL_END
+
 U_NAMESPACE_END
 
 // C API ------------------------------------------------------------------- ***