diff options
author | Steven R. Loomis <srloomis@us.ibm.com> | 2016-04-08 19:03:16 -0700 |
---|---|---|
committer | Steven R. Loomis <srloomis@us.ibm.com> | 2016-05-04 16:02:45 -0700 |
commit | 2bbd1cd6004b3e1467e30d860385a85dad01fe24 (patch) | |
tree | b812046e89e46e0de09bc858e0b128787cbc0632 /deps/icu-small/source/i18n/rbt_data.cpp | |
parent | cd752e8463fad7c4805951d9ba47cd2f39691f2d (diff) | |
download | android-node-v8-2bbd1cd6004b3e1467e30d860385a85dad01fe24.tar.gz android-node-v8-2bbd1cd6004b3e1467e30d860385a85dad01fe24.tar.bz2 android-node-v8-2bbd1cd6004b3e1467e30d860385a85dad01fe24.zip |
deps: Intl: Check in "small-icu" 57.1
* this commit has "small" ICU 57.1.
See other related commit for tools to generate this commit.
Fixes: https://github.com/nodejs/node/issues/3476
PR-URL: https://github.com/nodejs/node/pull/6088
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'deps/icu-small/source/i18n/rbt_data.cpp')
-rw-r--r-- | deps/icu-small/source/i18n/rbt_data.cpp | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/deps/icu-small/source/i18n/rbt_data.cpp b/deps/icu-small/source/i18n/rbt_data.cpp new file mode 100644 index 0000000000..579c681de0 --- /dev/null +++ b/deps/icu-small/source/i18n/rbt_data.cpp @@ -0,0 +1,117 @@ +/* +********************************************************************** +* Copyright (C) 1999-2014, International Business Machines +* Corporation and others. All Rights Reserved. +********************************************************************** +* Date Name Description +* 11/17/99 aliu Creation. +********************************************************************** +*/ + +#include "unicode/utypes.h" +#include "umutex.h" + +#if !UCONFIG_NO_TRANSLITERATION + +#include "unicode/unistr.h" +#include "unicode/uniset.h" +#include "rbt_data.h" +#include "hash.h" +#include "cmemory.h" + +U_NAMESPACE_BEGIN + +TransliterationRuleData::TransliterationRuleData(UErrorCode& status) + : UMemory(), ruleSet(status), variableNames(status), + variables(0), variablesAreOwned(TRUE) +{ + if (U_FAILURE(status)) { + return; + } + variableNames.setValueDeleter(uprv_deleteUObject); + variables = 0; + variablesLength = 0; +} + +TransliterationRuleData::TransliterationRuleData(const TransliterationRuleData& other) : + UMemory(other), ruleSet(other.ruleSet), + variablesAreOwned(TRUE), + variablesBase(other.variablesBase), + variablesLength(other.variablesLength) +{ + UErrorCode status = U_ZERO_ERROR; + int32_t i = 0; + variableNames.setValueDeleter(uprv_deleteUObject); + int32_t pos = UHASH_FIRST; + const UHashElement *e; + while ((e = other.variableNames.nextElement(pos)) != 0) { + UnicodeString* value = + new UnicodeString(*(const UnicodeString*)e->value.pointer); + // Exit out if value could not be created. + if (value == NULL) { + return; + } + variableNames.put(*(UnicodeString*)e->key.pointer, value, status); + } + + variables = 0; + if (other.variables != 0) { + variables = (UnicodeFunctor **)uprv_malloc(variablesLength * sizeof(UnicodeFunctor *)); + /* test for NULL */ + if (variables == 0) { + status = U_MEMORY_ALLOCATION_ERROR; + return; + } + for (i=0; i<variablesLength; ++i) { + variables[i] = other.variables[i]->clone(); + if (variables[i] == NULL) { + status = U_MEMORY_ALLOCATION_ERROR; + break; + } + } + } + // Remove the array and exit if memory allocation error occured. + if (U_FAILURE(status)) { + for (int32_t n = i-1; n >= 0; n--) { + delete variables[n]; + } + uprv_free(variables); + variables = NULL; + return; + } + + // Do this last, _after_ setting up variables[]. + ruleSet.setData(this); // ruleSet must already be frozen +} + +TransliterationRuleData::~TransliterationRuleData() { + if (variablesAreOwned && variables != 0) { + for (int32_t i=0; i<variablesLength; ++i) { + delete variables[i]; + } + } + uprv_free(variables); +} + +UnicodeFunctor* +TransliterationRuleData::lookup(UChar32 standIn) const { + int32_t i = standIn - variablesBase; + return (i >= 0 && i < variablesLength) ? variables[i] : 0; +} + +UnicodeMatcher* +TransliterationRuleData::lookupMatcher(UChar32 standIn) const { + UnicodeFunctor *f = lookup(standIn); + return (f != 0) ? f->toMatcher() : 0; +} + +UnicodeReplacer* +TransliterationRuleData::lookupReplacer(UChar32 standIn) const { + UnicodeFunctor *f = lookup(standIn); + return (f != 0) ? f->toReplacer() : 0; +} + + +U_NAMESPACE_END + +#endif /* #if !UCONFIG_NO_TRANSLITERATION */ |