michael@0: /* michael@0: ********************************************************************** michael@0: * Copyright (C) 1999-2011, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ********************************************************************** michael@0: * Date Name Description michael@0: * 11/17/99 aliu Creation. michael@0: ********************************************************************** michael@0: */ michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "umutex.h" michael@0: michael@0: #if !UCONFIG_NO_TRANSLITERATION michael@0: michael@0: #include "unicode/unistr.h" michael@0: #include "unicode/uniset.h" michael@0: #include "rbt_data.h" michael@0: #include "hash.h" michael@0: #include "cmemory.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: TransliterationRuleData::TransliterationRuleData(UErrorCode& status) michael@0: : UMemory(), ruleSet(status), variableNames(status), michael@0: variables(0), variablesAreOwned(TRUE) michael@0: { michael@0: if (U_FAILURE(status)) { michael@0: return; michael@0: } michael@0: variableNames.setValueDeleter(uprv_deleteUObject); michael@0: variables = 0; michael@0: variablesLength = 0; michael@0: } michael@0: michael@0: TransliterationRuleData::TransliterationRuleData(const TransliterationRuleData& other) : michael@0: UMemory(other), ruleSet(other.ruleSet), michael@0: variablesAreOwned(TRUE), michael@0: variablesBase(other.variablesBase), michael@0: variablesLength(other.variablesLength) michael@0: { michael@0: UErrorCode status = U_ZERO_ERROR; michael@0: int32_t i = 0; michael@0: variableNames.setValueDeleter(uprv_deleteUObject); michael@0: int32_t pos = -1; michael@0: const UHashElement *e; michael@0: while ((e = other.variableNames.nextElement(pos)) != 0) { michael@0: UnicodeString* value = michael@0: new UnicodeString(*(const UnicodeString*)e->value.pointer); michael@0: // Exit out if value could not be created. michael@0: if (value == NULL) { michael@0: return; michael@0: } michael@0: variableNames.put(*(UnicodeString*)e->key.pointer, value, status); michael@0: } michael@0: michael@0: variables = 0; michael@0: if (other.variables != 0) { michael@0: variables = (UnicodeFunctor **)uprv_malloc(variablesLength * sizeof(UnicodeFunctor *)); michael@0: /* test for NULL */ michael@0: if (variables == 0) { michael@0: status = U_MEMORY_ALLOCATION_ERROR; michael@0: return; michael@0: } michael@0: for (i=0; iclone(); michael@0: if (variables[i] == NULL) { michael@0: status = U_MEMORY_ALLOCATION_ERROR; michael@0: break; michael@0: } michael@0: } michael@0: } michael@0: // Remove the array and exit if memory allocation error occured. michael@0: if (U_FAILURE(status)) { michael@0: for (int32_t n = i-1; n >= 0; n++) { michael@0: delete variables[n]; michael@0: } michael@0: uprv_free(variables); michael@0: variables = NULL; michael@0: return; michael@0: } michael@0: michael@0: // Do this last, _after_ setting up variables[]. michael@0: ruleSet.setData(this); // ruleSet must already be frozen michael@0: } michael@0: michael@0: TransliterationRuleData::~TransliterationRuleData() { michael@0: if (variablesAreOwned && variables != 0) { michael@0: for (int32_t i=0; i= 0 && i < variablesLength) ? variables[i] : 0; michael@0: } michael@0: michael@0: UnicodeMatcher* michael@0: TransliterationRuleData::lookupMatcher(UChar32 standIn) const { michael@0: UnicodeFunctor *f = lookup(standIn); michael@0: return (f != 0) ? f->toMatcher() : 0; michael@0: } michael@0: michael@0: UnicodeReplacer* michael@0: TransliterationRuleData::lookupReplacer(UChar32 standIn) const { michael@0: UnicodeFunctor *f = lookup(standIn); michael@0: return (f != 0) ? f->toReplacer() : 0; michael@0: } michael@0: michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif /* #if !UCONFIG_NO_TRANSLITERATION */