]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/transreg.cpp
ICU-551.24.tar.gz
[apple/icu.git] / icuSources / i18n / transreg.cpp
index 834e4ce80772f36f8166be5e7a8a73bbcb8ca0f0..445a26ac670bfd262572521ef6fa8e985829cb6b 100644 (file)
@@ -1,6 +1,6 @@
 /*
 **********************************************************************
-*   Copyright (c) 2001-2006, International Business Machines
+*   Copyright (c) 2001-2014, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 **********************************************************************
 *   Date        Name        Description
@@ -44,9 +44,11 @@ static const UChar LOCALE_SEP  = 95; // '_'
 //static const UChar VARIANT_SEP = 0x002F; // '/'
 
 // String constants
-static const UChar NO_VARIANT[] = { 0 }; // empty string
 static const UChar ANY[] = { 65, 110, 121, 0 }; // Any
 
+// empty string
+#define NO_VARIANT UnicodeString()
+
 /**
  * Resource bundle key for the RuleBasedTransliterator rule.
  */
@@ -185,11 +187,11 @@ void TransliteratorAlias::parse(TransliteratorParser& parser,
 }
 
 //----------------------------------------------------------------------
-// class Spec
+// class TransliteratorSpec
 //----------------------------------------------------------------------
 
 /**
- * A Spec is a string specifying either a source or a target.  In more
+ * A TransliteratorSpec is a string specifying either a source or a target.  In more
  * general terms, it may also specify a variant, but we only use the
  * Spec class for sources and targets.
  *
@@ -203,10 +205,10 @@ void TransliteratorAlias::parse(TransliteratorParser& parser,
  * canonical form, or the script is transformed from an abbreviation
  * to a full name.
  */
-class Spec : public UMemory {
+class TransliteratorSpec : public UMemory {
  public:
-    Spec(const UnicodeString& spec);
-    ~Spec();
+    TransliteratorSpec(const UnicodeString& spec);
+    ~TransliteratorSpec();
 
     const UnicodeString& get() const;
     UBool hasFallback() const;
@@ -230,16 +232,15 @@ class Spec : public UMemory {
     UBool isNextLocale; // TRUE if nextSpec is a locale
     ResourceBundle* res;
 
-    Spec(const Spec &other); // forbid copying of this class
-    Spec &operator=(const Spec &other); // forbid copying of this class
+    TransliteratorSpec(const TransliteratorSpec &other); // forbid copying of this class
+    TransliteratorSpec &operator=(const TransliteratorSpec &other); // forbid copying of this class
 };
 
-Spec::Spec(const UnicodeString& theSpec)
+TransliteratorSpec::TransliteratorSpec(const UnicodeString& theSpec)
 : top(theSpec),
   res(0)
 {
     UErrorCode status = U_ZERO_ERROR;
-    CharString topch(theSpec);
     Locale topLoc("");
     LocaleUtility::initLocaleFromName(theSpec, topLoc);
     if (!topLoc.isBogus()) {
@@ -258,7 +259,8 @@ Spec::Spec(const UnicodeString& theSpec)
     status = U_ZERO_ERROR;
     static const int32_t capacity = 10;
     UScriptCode script[capacity]={USCRIPT_INVALID_CODE};
-    int32_t num = uscript_getCode(topch,script,capacity, &status);
+    int32_t num = uscript_getCode(CharString().appendInvariantChars(theSpec, status).data(),
+                                  script, capacity, &status);
     if (num > 0 && script[0] != USCRIPT_INVALID_CODE) {
         scriptName = UnicodeString(uscript_getName(script[0]), -1, US_INV);
     }
@@ -280,15 +282,15 @@ Spec::Spec(const UnicodeString& theSpec)
     reset();
 }
 
-Spec::~Spec() {
+TransliteratorSpec::~TransliteratorSpec() {
     delete res;
 }
 
-UBool Spec::hasFallback() const {
+UBool TransliteratorSpec::hasFallback() const {
     return nextSpec.length() != 0;
 }
 
-void Spec::reset() {
+void TransliteratorSpec::reset() {
     if (spec != top) {
         spec = top;
         isSpecLocale = (res != 0);
@@ -296,7 +298,7 @@ void Spec::reset() {
     }
 }
 
-void Spec::setupNext() {
+void TransliteratorSpec::setupNext() {
     isNextLocale = FALSE;
     if (isSpecLocale) {
         nextSpec = spec;
@@ -319,22 +321,22 @@ void Spec::setupNext() {
 // for(const UnicodeString& s(spec.get());
 //     spec.hasFallback(); s(spec.next())) { ...
 
-const UnicodeString& Spec::next() {
+const UnicodeString& TransliteratorSpec::next() {
     spec = nextSpec;
     isSpecLocale = isNextLocale;
     setupNext();
     return spec;
 }
 
-const UnicodeString& Spec::get() const {
+const UnicodeString& TransliteratorSpec::get() const {
     return spec;
 }
 
-UBool Spec::isLocale() const {
+UBool TransliteratorSpec::isLocale() const {
     return isSpecLocale;
 }
 
-ResourceBundle& Spec::getBundle() const {
+ResourceBundle& TransliteratorSpec::getBundle() const {
     return *res;
 }
 
@@ -354,9 +356,9 @@ static void DEBUG_setup() {
 
 // Caller must call DEBUG_setup first.  Return index of given Entry,
 // if it is in use (not deleted yet), or -1 if not found.
-static int DEBUG_findEntry(Entry* e) {
+static int DEBUG_findEntry(TransliteratorEntry* e) {
     for (int i=0; i<DEBUG_entries->size(); ++i) {
-        if (e == (Entry*) DEBUG_entries->elementAt(i)) {
+        if (e == (TransliteratorEntry*) DEBUG_entries->elementAt(i)) {
             return i;
         }
     }
@@ -364,7 +366,7 @@ static int DEBUG_findEntry(Entry* e) {
 }
 
 // Track object creation
-static void DEBUG_newEntry(Entry* e) {
+static void DEBUG_newEntry(TransliteratorEntry* e) {
     DEBUG_setup();
     if (DEBUG_findEntry(e) >= 0) {
         // This should really never happen unless the heap is broken
@@ -376,7 +378,7 @@ static void DEBUG_newEntry(Entry* e) {
 }
 
 // Track object deletion
-static void DEBUG_delEntry(Entry* e) {
+static void DEBUG_delEntry(TransliteratorEntry* e) {
     DEBUG_setup();
     int i = DEBUG_findEntry(e);
     if (i < 0) {
@@ -387,7 +389,7 @@ static void DEBUG_delEntry(Entry* e) {
 }
 
 // Track object usage
-static void DEBUG_useEntry(Entry* e) {
+static void DEBUG_useEntry(TransliteratorEntry* e) {
     if (e == NULL) return;
     DEBUG_setup();
     int i = DEBUG_findEntry(e);
@@ -417,7 +419,7 @@ static void DEBUG_useEntry(Entry* e) {
  * for it.  We could easily add this if there is a need for it in the
  * future.
  */
-class Entry : public UMemory {
+class TransliteratorEntry : public UMemory {
 public:
     enum Type {
         RULES_FORWARD,
@@ -444,26 +446,26 @@ public:
             Transliterator::Token   context;
         } factory; // For FACTORY
     } u;
-    Entry();
-    ~Entry();
+    TransliteratorEntry();
+    ~TransliteratorEntry();
     void adoptPrototype(Transliterator* adopted);
     void setFactory(Transliterator::Factory factory,
                     Transliterator::Token context);
 
 private:
 
-    Entry(const Entry &other); // forbid copying of this class
-    Entry &operator=(const Entry &other); // forbid copying of this class
+    TransliteratorEntry(const TransliteratorEntry &other); // forbid copying of this class
+    TransliteratorEntry &operator=(const TransliteratorEntry &other); // forbid copying of this class
 };
 
-Entry::Entry() {
+TransliteratorEntry::TransliteratorEntry() {
     u.prototype = 0;
     compoundFilter = NULL;
     entryType = NONE;
     DEBUG_newEntry(this);
 }
 
-Entry::~Entry() {
+TransliteratorEntry::~TransliteratorEntry() {
     DEBUG_delEntry(this);
     if (entryType == PROTOTYPE) {
         delete u.prototype;
@@ -481,7 +483,7 @@ Entry::~Entry() {
     delete compoundFilter;
 }
 
-void Entry::adoptPrototype(Transliterator* adopted) {
+void TransliteratorEntry::adoptPrototype(Transliterator* adopted) {
     if (entryType == PROTOTYPE) {
         delete u.prototype;
     }
@@ -489,7 +491,7 @@ void Entry::adoptPrototype(Transliterator* adopted) {
     u.prototype = adopted;
 }
 
-void Entry::setFactory(Transliterator::Factory factory,
+void TransliteratorEntry::setFactory(Transliterator::Factory factory,
                        Transliterator::Token context) {
     if (entryType == PROTOTYPE) {
         delete u.prototype;
@@ -503,7 +505,7 @@ void Entry::setFactory(Transliterator::Factory factory,
 U_CDECL_BEGIN
 static void U_CALLCONV
 deleteEntry(void* obj) {
-    delete (Entry*) obj;
+    delete (TransliteratorEntry*) obj;
 }
 U_CDECL_END
 
@@ -517,7 +519,7 @@ TransliteratorRegistry::TransliteratorRegistry(UErrorCode& status) :
     availableIDs(status)
 {
     registry.setValueDeleter(deleteEntry);
-    availableIDs.setDeleter(uhash_deleteUnicodeString);
+    availableIDs.setDeleter(uprv_deleteUObject);
     availableIDs.setComparer(uhash_compareCaselessUnicodeString);
     specDAG.setValueDeleter(uhash_deleteHashtable);
 }
@@ -530,7 +532,7 @@ Transliterator* TransliteratorRegistry::get(const UnicodeString& ID,
                                             TransliteratorAlias*& aliasReturn,
                                             UErrorCode& status) {
     U_ASSERT(aliasReturn == NULL);
-    Entry *entry = find(ID);
+    TransliteratorEntry *entry = find(ID);
     return (entry == 0) ? 0
         : instantiateEntry(ID, entry, aliasReturn, status);
 }
@@ -540,7 +542,7 @@ Transliterator* TransliteratorRegistry::reget(const UnicodeString& ID,
                                               TransliteratorAlias*& aliasReturn,
                                               UErrorCode& status) {
     U_ASSERT(aliasReturn == NULL);
-    Entry *entry = find(ID);
+    TransliteratorEntry *entry = find(ID);
 
     if (entry == 0) {
         // We get to this point if there are two threads, one of which
@@ -561,26 +563,26 @@ Transliterator* TransliteratorRegistry::reget(const UnicodeString& ID,
     // We have to detect this so we don't stomp over existing entry
     // data members and potentially leak memory (u.data and compoundFilter).
 
-    if (entry->entryType == Entry::RULES_FORWARD ||
-        entry->entryType == Entry::RULES_REVERSE ||
-        entry->entryType == Entry::LOCALE_RULES) {
+    if (entry->entryType == TransliteratorEntry::RULES_FORWARD ||
+        entry->entryType == TransliteratorEntry::RULES_REVERSE ||
+        entry->entryType == TransliteratorEntry::LOCALE_RULES) {
         
         if (parser.idBlockVector.isEmpty() && parser.dataVector.isEmpty()) {
             entry->u.data = 0;
-            entry->entryType = Entry::ALIAS;
+            entry->entryType = TransliteratorEntry::ALIAS;
             entry->stringArg = UNICODE_STRING_SIMPLE("Any-NULL");
         }
         else if (parser.idBlockVector.isEmpty() && parser.dataVector.size() == 1) {
             entry->u.data = (TransliterationRuleData*)parser.dataVector.orphanElementAt(0);
-            entry->entryType = Entry::RBT_DATA;
+            entry->entryType = TransliteratorEntry::RBT_DATA;
         }
         else if (parser.idBlockVector.size() == 1 && parser.dataVector.isEmpty()) {
             entry->stringArg = *(UnicodeString*)(parser.idBlockVector.elementAt(0));
             entry->compoundFilter = parser.orphanCompoundFilter();
-            entry->entryType = Entry::ALIAS;
+            entry->entryType = TransliteratorEntry::ALIAS;
         }
         else {
-            entry->entryType = Entry::COMPOUND_RBT;
+            entry->entryType = TransliteratorEntry::COMPOUND_RBT;
             entry->compoundFilter = parser.orphanCompoundFilter();
             entry->u.dataVector = new UVector(status);
             entry->stringArg.remove();
@@ -610,8 +612,14 @@ Transliterator* TransliteratorRegistry::reget(const UnicodeString& ID,
 }
 
 void TransliteratorRegistry::put(Transliterator* adoptedProto,
-                                 UBool visible) {
-    Entry *entry = new Entry();
+                                 UBool visible,
+                                 UErrorCode& ec)
+{
+    TransliteratorEntry *entry = new TransliteratorEntry();
+    if (entry == NULL) {
+        ec = U_MEMORY_ALLOCATION_ERROR;
+        return;
+    }
     entry->adoptPrototype(adoptedProto);
     registerEntry(adoptedProto->getID(), entry, visible);
 }
@@ -619,8 +627,13 @@ void TransliteratorRegistry::put(Transliterator* adoptedProto,
 void TransliteratorRegistry::put(const UnicodeString& ID,
                                  Transliterator::Factory factory,
                                  Transliterator::Token context,
-                                 UBool visible) {
-    Entry *entry = new Entry();
+                                 UBool visible,
+                                 UErrorCode& ec) {
+    TransliteratorEntry *entry = new TransliteratorEntry();
+    if (entry == NULL) {
+        ec = U_MEMORY_ALLOCATION_ERROR;
+        return;
+    }
     entry->setFactory(factory, context);
     registerEntry(ID, entry, visible);
 }
@@ -629,10 +642,15 @@ void TransliteratorRegistry::put(const UnicodeString& ID,
                                  const UnicodeString& resourceName,
                                  UTransDirection dir,
                                  UBool readonlyResourceAlias,
-                                 UBool visible) {
-    Entry *entry = new Entry();
-    entry->entryType = (dir == UTRANS_FORWARD) ? Entry::RULES_FORWARD
-        : Entry::RULES_REVERSE;
+                                 UBool visible,
+                                 UErrorCode& ec) {
+    TransliteratorEntry *entry = new TransliteratorEntry();
+    if (entry == NULL) {
+        ec = U_MEMORY_ALLOCATION_ERROR;
+        return;
+    }
+    entry->entryType = (dir == UTRANS_FORWARD) ? TransliteratorEntry::RULES_FORWARD
+        : TransliteratorEntry::RULES_REVERSE;
     if (readonlyResourceAlias) {
         entry->stringArg.setTo(TRUE, resourceName.getBuffer(), -1);
     }
@@ -645,16 +663,20 @@ void TransliteratorRegistry::put(const UnicodeString& ID,
 void TransliteratorRegistry::put(const UnicodeString& ID,
                                  const UnicodeString& alias,
                                  UBool readonlyAliasAlias,
-                                 UBool visible) {
-    Entry *entry = new Entry();
-    entry->entryType = Entry::ALIAS;
-    if (readonlyAliasAlias) {
-        entry->stringArg.setTo(TRUE, alias.getBuffer(), -1);
-    }
-    else {
-        entry->stringArg = alias;
+                                 UBool visible,
+                                 UErrorCode& /*ec*/) {
+    TransliteratorEntry *entry = new TransliteratorEntry();
+    // Null pointer check
+    if (entry != NULL) {
+        entry->entryType = TransliteratorEntry::ALIAS;
+        if (readonlyAliasAlias) {
+            entry->stringArg.setTo(TRUE, alias.getBuffer(), -1);
+        }
+        else {
+            entry->stringArg = alias;
+        }
+        registerEntry(ID, entry, visible);
     }
-    registerEntry(ID, entry, visible);
 }
 
 void TransliteratorRegistry::remove(const UnicodeString& ID) {
@@ -706,7 +728,7 @@ int32_t TransliteratorRegistry::countAvailableSources(void) const {
 
 UnicodeString& TransliteratorRegistry::getAvailableSource(int32_t index,
                                                           UnicodeString& result) const {
-    int32_t pos = -1;
+    int32_t pos = UHASH_FIRST;
     const UHashElement *e = 0;
     while (index-- >= 0) {
         e = specDAG.nextElement(pos);
@@ -735,7 +757,7 @@ UnicodeString& TransliteratorRegistry::getAvailableTarget(int32_t index,
         result.truncate(0); // invalid source
         return result;
     }
-    int32_t pos = -1;
+    int32_t pos = UHASH_FIRST;
     const UHashElement *e = 0;
     while (index-- >= 0) {
         e = targets->nextElement(pos);
@@ -843,12 +865,12 @@ UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TransliteratorRegistry::Enumeration)
 void TransliteratorRegistry::registerEntry(const UnicodeString& source,
                                            const UnicodeString& target,
                                            const UnicodeString& variant,
-                                           Entry* adopted,
+                                           TransliteratorEntry* adopted,
                                            UBool visible) {
     UnicodeString ID;
     UnicodeString s(source);
     if (s.length() == 0) {
-        s = ANY;
+        s.setTo(TRUE, ANY, 3);
     }
     TransliteratorIDParser::STVtoID(source, target, variant, ID);
     registerEntry(ID, s, target, variant, adopted, visible);
@@ -858,7 +880,7 @@ void TransliteratorRegistry::registerEntry(const UnicodeString& source,
  * Convenience method.  Calls 6-arg registerEntry().
  */
 void TransliteratorRegistry::registerEntry(const UnicodeString& ID,
-                                           Entry* adopted,
+                                           TransliteratorEntry* adopted,
                                            UBool visible) {
     UnicodeString source, target, variant;
     UBool sawSource;
@@ -877,7 +899,7 @@ void TransliteratorRegistry::registerEntry(const UnicodeString& ID,
                                            const UnicodeString& source,
                                            const UnicodeString& target,
                                            const UnicodeString& variant,
-                                           Entry* adopted,
+                                           TransliteratorEntry* adopted,
                                            UBool visible) {
     UErrorCode status = U_ZERO_ERROR;
     registry.put(ID, adopted, status);
@@ -885,9 +907,12 @@ void TransliteratorRegistry::registerEntry(const UnicodeString& ID,
         registerSTV(source, target, variant);
         if (!availableIDs.contains((void*) &ID)) {
             UnicodeString *newID = (UnicodeString *)ID.clone();
-            // NUL-terminate the ID string
-            newID->getTerminatedBuffer();
-            availableIDs.addElement(newID, status);
+            // Check to make sure newID was created.
+            if (newID != NULL) {
+                   // NUL-terminate the ID string
+                   newID->getTerminatedBuffer();
+                   availableIDs.addElement(newID, status);
+            }
         }
     } else {
         removeSTV(source, target, variant);
@@ -913,12 +938,12 @@ void TransliteratorRegistry::registerSTV(const UnicodeString& source,
         if (U_FAILURE(status) || targets == 0) {
             return;
         }
-        targets->setValueDeleter(uhash_deleteUVector);
+        targets->setValueDeleter(uprv_deleteUObject);
         specDAG.put(source, targets, status);
     }
     UVector *variants = (UVector*) targets->get(target);
     if (variants == 0) {
-        variants = new UVector(uhash_deleteUnicodeString,
+        variants = new UVector(uprv_deleteUObject,
                                uhash_compareCaselessUnicodeString, status);
         if (variants == 0) {
             return;
@@ -929,10 +954,17 @@ void TransliteratorRegistry::registerSTV(const UnicodeString& source,
     // We add the variant string.  If it is the special "no variant"
     // string, that is, the empty string, we add it at position zero.
     if (!variants->contains((void*) &variant)) {
+       UnicodeString *tempus; // Used for null pointer check.
         if (variant.length() > 0) {
-            variants->addElement(new UnicodeString(variant), status);
+               tempus = new UnicodeString(variant);
+               if (tempus != NULL) {
+                       variants->addElement(tempus, status);
+               }
         } else {
-            variants->insertElementAt(new UnicodeString(NO_VARIANT), 0, status);
+               tempus = new UnicodeString();  // = NO_VARIANT
+               if (tempus != NULL) {
+                       variants->insertElementAt(tempus, 0, status);
+               }
         }
     }
 }
@@ -969,12 +1001,12 @@ void TransliteratorRegistry::removeSTV(const UnicodeString& source,
  *
  * Caller does NOT own returned object.
  */
-Entry* TransliteratorRegistry::findInDynamicStore(const Spec& src,
-                                                  const Spec& trg,
+TransliteratorEntry* TransliteratorRegistry::findInDynamicStore(const TransliteratorSpec& src,
+                                                  const TransliteratorSpec& trg,
                                                   const UnicodeString& variant) const {
     UnicodeString ID;
     TransliteratorIDParser::STVtoID(src, trg, variant, ID);
-    Entry *e = (Entry*) registry.get(ID);
+    TransliteratorEntry *e = (TransliteratorEntry*) registry.get(ID);
     DEBUG_useEntry(e);
     return e;
 }
@@ -990,10 +1022,10 @@ Entry* TransliteratorRegistry::findInDynamicStore(const Spec& src,
  *
  * Caller does NOT own returned object.
  */
-Entry* TransliteratorRegistry::findInStaticStore(const Spec& src,
-                                                 const Spec& trg,
+TransliteratorEntry* TransliteratorRegistry::findInStaticStore(const TransliteratorSpec& src,
+                                                 const TransliteratorSpec& trg,
                                                  const UnicodeString& variant) {
-    Entry* entry = 0;
+    TransliteratorEntry* entry = 0;
     if (src.isLocale()) {
         entry = findInBundle(src, trg, variant, UTRANS_FORWARD);
     } else if (trg.isLocale()) {
@@ -1026,8 +1058,8 @@ static const UChar TRANSLITERATE[] = {84,114,97,110,115,108,105,116,101,114,97,1
  * On success, create a new Entry object, populate it, and return it.
  * The caller owns the returned object.
  */
-Entry* TransliteratorRegistry::findInBundle(const Spec& specToOpen,
-                                            const Spec& specToFind,
+TransliteratorEntry* TransliteratorRegistry::findInBundle(const TransliteratorSpec& specToOpen,
+                                            const TransliteratorSpec& specToFind,
                                             const UnicodeString& variant,
                                             UTransDirection direction)
 {
@@ -1043,36 +1075,33 @@ Entry* TransliteratorRegistry::findInBundle(const Spec& specToOpen,
         // but must be consistent and documented.
         if (pass == 0) {
             utag.append(direction == UTRANS_FORWARD ?
-                        TRANSLITERATE_TO : TRANSLITERATE_FROM);
+                        TRANSLITERATE_TO : TRANSLITERATE_FROM, -1);
         } else {
-            utag.append(TRANSLITERATE);
+            utag.append(TRANSLITERATE, -1);
         }
         UnicodeString s(specToFind.get());
         utag.append(s.toUpper(""));
-        CharString tag(utag);
-        
         UErrorCode status = U_ZERO_ERROR;
-        ResourceBundle subres(specToOpen.getBundle().get(tag, status));
+        ResourceBundle subres(specToOpen.getBundle().get(
+            CharString().appendInvariantChars(utag, status).data(), status));
         if (U_FAILURE(status) || status == U_USING_DEFAULT_WARNING) {
             continue;
         }
-        
+
         s.truncate(0);
         if (specToOpen.get() != LocaleUtility::initNameFromLocale(subres.getLocale(), s)) {
             continue;
         }
-        
+
         if (variant.length() != 0) {
-            CharString var(variant);
             status = U_ZERO_ERROR;
-            resStr = subres.getStringEx(var, status);
+            resStr = subres.getStringEx(
+                CharString().appendInvariantChars(variant, status).data(), status);
             if (U_SUCCESS(status)) {
                 // Exit loop successfully
                 break;
             }
-        }
-        
-        else {
+        } else {
             // Variant is empty, which means match the first variant listed.
             status = U_ZERO_ERROR;
             resStr = subres.getStringEx(1, status);
@@ -1090,7 +1119,7 @@ Entry* TransliteratorRegistry::findInBundle(const Spec& specToOpen,
 
     // We have succeeded in loading a string from the locale
     // resources.  Create a new registry entry to hold it and return it.
-    Entry *entry = new Entry();
+    TransliteratorEntry *entry = new TransliteratorEntry();
     if (entry != 0) {
         // The direction is always forward for the
         // TransliterateTo_xxx and TransliterateFrom_xxx
@@ -1099,7 +1128,7 @@ Entry* TransliteratorRegistry::findInBundle(const Spec& specToOpen,
         // the direction is the value passed in to this
         // function.
         int32_t dir = (pass == 0) ? UTRANS_FORWARD : direction;
-        entry->entryType = Entry::LOCALE_RULES;
+        entry->entryType = TransliteratorEntry::LOCALE_RULES;
         entry->stringArg = resStr;
         entry->intArg = dir;
     }
@@ -1110,7 +1139,7 @@ Entry* TransliteratorRegistry::findInBundle(const Spec& specToOpen,
 /**
  * Convenience method.  Calls 3-arg find().
  */
-Entry* TransliteratorRegistry::find(const UnicodeString& ID) {
+TransliteratorEntry* TransliteratorRegistry::find(const UnicodeString& ID) {
     UnicodeString source, target, variant;
     UBool sawSource;
     TransliteratorIDParser::IDtoSTV(ID, source, target, variant, sawSource);
@@ -1138,13 +1167,25 @@ Entry* TransliteratorRegistry::find(const UnicodeString& ID) {
  *
  * Caller does NOT own returned object.  Return 0 on failure.
  */
-Entry* TransliteratorRegistry::find(UnicodeString& source,
+TransliteratorEntry* TransliteratorRegistry::find(UnicodeString& source,
                                     UnicodeString& target,
                                     UnicodeString& variant) {
     
-    Spec src(source);
-    Spec trg(target);
-    Entry* entry;
+    TransliteratorSpec src(source);
+    TransliteratorSpec trg(target);
+    TransliteratorEntry* entry;
+
+    // Seek exact match in hashtable.  Temporary fix for ICU 4.6.
+    // TODO: The general logic for finding a matching transliterator needs to be reviewed.
+    // ICU ticket #8089
+    UnicodeString ID;
+    TransliteratorIDParser::STVtoID(source, target, variant, ID);
+    entry = (TransliteratorEntry*) registry.get(ID);
+    if (entry != 0) {
+        // std::string ss;
+        // std::cout << ID.toUTF8String(ss) << std::endl;
+        return entry;
+    }
 
     if (variant.length() != 0) {
         
@@ -1202,66 +1243,74 @@ Entry* TransliteratorRegistry::find(UnicodeString& source,
  * modified.
  */
 Transliterator* TransliteratorRegistry::instantiateEntry(const UnicodeString& ID,
-                                                         Entry *entry,
+                                                         TransliteratorEntry *entry,
                                                          TransliteratorAlias* &aliasReturn,
                                                          UErrorCode& status) {
     Transliterator *t = 0;
     U_ASSERT(aliasReturn == 0);
 
     switch (entry->entryType) {
-    case Entry::RBT_DATA:
+    case TransliteratorEntry::RBT_DATA:
         t = new RuleBasedTransliterator(ID, entry->u.data);
         if (t == 0) {
             status = U_MEMORY_ALLOCATION_ERROR;
         }
         return t;
-    case Entry::PROTOTYPE:
+    case TransliteratorEntry::PROTOTYPE:
         t = entry->u.prototype->clone();
         if (t == 0) {
             status = U_MEMORY_ALLOCATION_ERROR;
         }
         return t;
-    case Entry::ALIAS:
+    case TransliteratorEntry::ALIAS:
         aliasReturn = new TransliteratorAlias(entry->stringArg, entry->compoundFilter);
         if (aliasReturn == 0) {
             status = U_MEMORY_ALLOCATION_ERROR;
         }
         return 0;
-    case Entry::FACTORY:
+    case TransliteratorEntry::FACTORY:
         t = entry->u.factory.function(ID, entry->u.factory.context);
         if (t == 0) {
             status = U_MEMORY_ALLOCATION_ERROR;
         }
         return t;
-    case Entry::COMPOUND_RBT:
+    case TransliteratorEntry::COMPOUND_RBT:
         {
-            UVector* rbts = new UVector(status);
+            UVector* rbts = new UVector(entry->u.dataVector->size(), status);
+            // Check for null pointer
+            if (rbts == NULL) {
+               status = U_MEMORY_ALLOCATION_ERROR;
+               return NULL;
+            }
             int32_t passNumber = 1;
             for (int32_t i = 0; U_SUCCESS(status) && i < entry->u.dataVector->size(); i++) {
-                Transliterator* t = new RuleBasedTransliterator(UnicodeString(CompoundTransliterator::PASS_STRING) + (passNumber++),
+                // TODO: Should passNumber be turned into a decimal-string representation (1 -> "1")?
+                Transliterator* t = new RuleBasedTransliterator(UnicodeString(CompoundTransliterator::PASS_STRING) + UnicodeString(passNumber++),
                     (TransliterationRuleData*)(entry->u.dataVector->elementAt(i)), FALSE);
                 if (t == 0)
                     status = U_MEMORY_ALLOCATION_ERROR;
                 else
                     rbts->addElement(t, status);
             }
-            if (U_FAILURE(status))
+            if (U_FAILURE(status)) {
+                delete rbts;
                 return 0;
+            }
             aliasReturn = new TransliteratorAlias(ID, entry->stringArg, rbts, entry->compoundFilter);
         }
         if (aliasReturn == 0) {
             status = U_MEMORY_ALLOCATION_ERROR;
         }
         return 0;
-    case Entry::LOCALE_RULES:
+    case TransliteratorEntry::LOCALE_RULES:
         aliasReturn = new TransliteratorAlias(ID, entry->stringArg,
                                               (UTransDirection) entry->intArg);
         if (aliasReturn == 0) {
             status = U_MEMORY_ALLOCATION_ERROR;
         }
         return 0;
-    case Entry::RULES_FORWARD:
-    case Entry::RULES_REVERSE:
+    case TransliteratorEntry::RULES_FORWARD:
+    case TransliteratorEntry::RULES_REVERSE:
         // Process the rule data into a TransliteratorRuleData object,
         // and possibly also into an ::id header and/or footer.  Then
         // we modify the registry with the parsed data and retry.
@@ -1293,7 +1342,7 @@ Transliterator* TransliteratorRegistry::instantiateEntry(const UnicodeString& ID
                 // transliterators; if it lists something that's not
                 // installed, we'll get an error from ResourceBundle.
                 aliasReturn = new TransliteratorAlias(ID, rules,
-                    ((entry->entryType == Entry::RULES_REVERSE) ?
+                    ((entry->entryType == TransliteratorEntry::RULES_REVERSE) ?
                      UTRANS_REVERSE : UTRANS_FORWARD));
                 if (aliasReturn == 0) {
                     status = U_MEMORY_ALLOCATION_ERROR;