]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/coll.cpp
ICU-511.34.tar.gz
[apple/icu.git] / icuSources / i18n / coll.cpp
index 83c7565af003df0ac36f23c1f1e34b7cf94ccc84..9e9ca0239d0a269641120420a7f0e68512b793e1 100644 (file)
@@ -1,6 +1,6 @@
 /*
  ******************************************************************************
- * Copyright (C) 1996-2010, International Business Machines Corporation and
+ * Copyright (C) 1996-2012, International Business Machines Corporation and
  * others. All Rights Reserved.
  ******************************************************************************
  */
@@ -37,6 +37,8 @@
  * 01/29/01     synwee      Modified into a C++ wrapper calling C APIs (ucol.h)
  */
 
+#include "utypeinfo.h"  // for 'typeid' to work
+
 #include "unicode/utypes.h"
 
 #if !UCONFIG_NO_COLLATION
@@ -52,9 +54,9 @@
 #include "uresimp.h"
 #include "ucln_in.h"
 
-static U_NAMESPACE_QUALIFIER Locale* availableLocaleList = NULL;
+static icu::Locale* availableLocaleList = NULL;
 static int32_t  availableLocaleListCount;
-static U_NAMESPACE_QUALIFIER ICULocaleService* gService = NULL;
+static icu::ICULocaleService* gService = NULL;
 
 /**
  * Release all static memory held by collator.
@@ -112,11 +114,14 @@ CollatorFactory::getDisplayName(const Locale& objectLocale,
 
 class ICUCollatorFactory : public ICUResourceBundleFactory {
  public:
-    ICUCollatorFactory():  ICUResourceBundleFactory(UnicodeString(U_ICUDATA_COLL, -1, US_INV)) { } 
+    ICUCollatorFactory() : ICUResourceBundleFactory(UnicodeString(U_ICUDATA_COLL, -1, US_INV)) { }
+    virtual ~ICUCollatorFactory();
  protected:
     virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const;
 };
 
+ICUCollatorFactory::~ICUCollatorFactory() {}
+
 UObject*
 ICUCollatorFactory::create(const ICUServiceKey& key, const ICUService* /* service */, UErrorCode& status) const {
     if (handlesKey(key, status)) {
@@ -142,7 +147,9 @@ public:
         UErrorCode status = U_ZERO_ERROR;
         registerFactory(new ICUCollatorFactory(), status);
     }
-    
+
+    virtual ~ICUCollatorService();
+
     virtual UObject* cloneInstance(UObject* instance) const {
         return ((Collator*)instance)->clone();
     }
@@ -188,6 +195,8 @@ public:
     }
 };
 
+ICUCollatorService::~ICUCollatorService() {}
+
 // -------------------------------------
 
 static ICULocaleService* 
@@ -243,6 +252,17 @@ Collator::createUCollator(const char *loc,
                 result = rbc->ucollator;
                 rbc->ucollator = NULL; // to prevent free on delete
             }
+        } else {
+          // should go in a function- ucol_initDelegate(delegate)
+          result = (UCollator *)uprv_malloc(sizeof(UCollator));
+          if(result == NULL) {
+            *status = U_MEMORY_ALLOCATION_ERROR;
+          } else {
+            uprv_memset(result, 0, sizeof(UCollator));
+            result->delegate = col;
+            result->freeOnClose = TRUE; // do free on close.
+            col = NULL; // to prevent free on delete.
+          }
         }
         delete col;
     }
@@ -319,6 +339,7 @@ Collator* U_EXPORT2 Collator::createInstance(const Locale& desiredLocale,
         Locale actualLoc;
         Collator *result =
             (Collator*)gService->get(desiredLocale, &actualLoc, status);
+
         // Ugly Hack Alert! If the returned locale is empty (not root,
         // but empty -- getName() == "") then that means the service
         // returned a default object, not a "real" service object.  In
@@ -404,12 +425,17 @@ Collator::createInstance(const Locale &loc,
 }
 #endif
 
+Collator *
+Collator::safeClone() const {
+    return clone();
+}
+
 // implement deprecated, previously abstract method
 Collator::EComparisonResult Collator::compare(const UnicodeString& source, 
                                     const UnicodeString& target) const
 {
     UErrorCode ec = U_ZERO_ERROR;
-    return (Collator::EComparisonResult)compare(source, target, ec);
+    return (EComparisonResult)compare(source, target, ec);
 }
 
 // implement deprecated, previously abstract method
@@ -418,7 +444,7 @@ Collator::EComparisonResult Collator::compare(const UnicodeString& source,
                                     int32_t length) const
 {
     UErrorCode ec = U_ZERO_ERROR;
-    return (Collator::EComparisonResult)compare(source, target, length, ec);
+    return (EComparisonResult)compare(source, target, length, ec);
 }
 
 // implement deprecated, previously abstract method
@@ -427,7 +453,7 @@ Collator::EComparisonResult Collator::compare(const UChar* source, int32_t sourc
                                     const
 {
     UErrorCode ec = U_ZERO_ERROR;
-    return (Collator::EComparisonResult)compare(source, sourceLength, target, targetLength, ec);
+    return (EComparisonResult)compare(source, sourceLength, target, targetLength, ec);
 }
 
 UCollationResult Collator::compare(UCharIterator &/*sIter*/,
@@ -555,7 +581,8 @@ Collator::Collator(const Collator &other)
 
 UBool Collator::operator==(const Collator& other) const
 {
-    return (UBool)(this == &other);
+    // Subclasses: Call this method and then add more specific checks.
+    return typeid(*this) == typeid(other);
 }
 
 UBool Collator::operator!=(const Collator& other) const
@@ -630,13 +657,9 @@ public:
             }
         }
     }
-    
-    virtual ~CFactory()
-    {
-        delete _delegate;
-        delete _ids;
-    }
-    
+
+    virtual ~CFactory();
+
     virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const;
     
 protected:
@@ -652,6 +675,12 @@ protected:
         getDisplayName(const UnicodeString& id, const Locale& locale, UnicodeString& result) const;
 };
 
+CFactory::~CFactory()
+{
+    delete _delegate;
+    delete _ids;
+}
+
 UObject* 
 CFactory::create(const ICUServiceKey& key, const ICUService* /* service */, UErrorCode& status) const
 {
@@ -722,8 +751,7 @@ public:
         //isAvailableLocaleListInitialized(status);
     }
 
-    virtual ~CollationLocaleListEnumeration() {
-    }
+    virtual ~CollationLocaleListEnumeration();
 
     virtual StringEnumeration * clone() const
     {
@@ -765,6 +793,8 @@ public:
     }
 };
 
+CollationLocaleListEnumeration::~CollationLocaleListEnumeration() {}
+
 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(CollationLocaleListEnumeration)
 
 
@@ -833,9 +863,22 @@ Collator::getFunctionalEquivalent(const char* keyword, const Locale& locale,
     return Locale::createFromName(loc);
 }
 
-int32_t Collator::getReorderCodes(int32_t *dest,
-                                 int32_t destCapacity,
-                                 UErrorCode& status) const
+Collator::ECollationStrength
+Collator::getStrength(void) const {
+    UErrorCode intStatus = U_ZERO_ERROR;
+    return (ECollationStrength)getAttribute(UCOL_STRENGTH, intStatus);
+}
+
+void
+Collator::setStrength(ECollationStrength newStrength) {
+    UErrorCode intStatus = U_ZERO_ERROR;
+    setAttribute(UCOL_STRENGTH, (UColAttributeValue)newStrength, intStatus);
+}
+
+int32_t
+Collator::getReorderCodes(int32_t* /* dest*/,
+                          int32_t /* destCapacity*/,
+                          UErrorCode& status) const
 {
     if (U_SUCCESS(status)) {
         status = U_UNSUPPORTED_ERROR;
@@ -843,13 +886,37 @@ int32_t Collator::getReorderCodes(int32_t *dest,
     return 0;
 }
 
-void Collator::setReorderCodes(const int32_t *reorderCodes,
-                              int32_t reorderCodesLength,
-                              UErrorCode& status)
+void
+Collator::setReorderCodes(const int32_t* /* reorderCodes */,
+                          int32_t /* reorderCodesLength */,
+                          UErrorCode& status)
+{
+    if (U_SUCCESS(status)) {
+        status = U_UNSUPPORTED_ERROR;
+    }
+}
+
+int32_t U_EXPORT2
+Collator::getEquivalentReorderCodes(int32_t /* reorderCode */,
+                                    int32_t* /* dest */,
+                                    int32_t /* destCapacity */,
+                                    UErrorCode& status)
 {
     if (U_SUCCESS(status)) {
         status = U_UNSUPPORTED_ERROR;
     }
+    return 0;
+}
+
+int32_t
+Collator::internalGetShortDefinitionString(const char * /*locale*/,
+                                                             char * /*buffer*/,
+                                                             int32_t /*capacity*/,
+                                                             UErrorCode &status) const {
+  if(U_SUCCESS(status)) {
+    status = U_UNSUPPORTED_ERROR; /* Shouldn't happen, internal function */
+  }
+  return 0;
 }
 
 // UCollator private data members ----------------------------------------