2017-01-20 00:20:31 +00:00
|
|
|
// © 2016 and later: Unicode, Inc. and others.
|
2016-06-15 18:58:17 +00:00
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
1999-11-20 00:40:50 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (C) 1999-2014, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
1999-11-20 00:40:50 +00:00
|
|
|
**********************************************************************
|
|
|
|
* Date Name Description
|
|
|
|
* 11/17/99 aliu Creation.
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
2002-09-20 01:54:48 +00:00
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
2003-12-10 01:52:39 +00:00
|
|
|
#include "umutex.h"
|
2002-09-20 01:54:48 +00:00
|
|
|
|
|
|
|
#if !UCONFIG_NO_TRANSLITERATION
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/unistr.h"
|
2000-05-20 04:40:29 +00:00
|
|
|
#include "unicode/uniset.h"
|
2002-07-12 21:42:24 +00:00
|
|
|
#include "rbt_data.h"
|
|
|
|
#include "hash.h"
|
2002-07-16 17:50:42 +00:00
|
|
|
#include "cmemory.h"
|
1999-11-20 00:40:50 +00:00
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2001-08-23 01:06:08 +00:00
|
|
|
TransliterationRuleData::TransliterationRuleData(UErrorCode& status)
|
2006-04-14 21:09:42 +00:00
|
|
|
: UMemory(), ruleSet(status), variableNames(status),
|
2022-09-08 21:15:13 +00:00
|
|
|
variables(0), variablesAreOwned(true)
|
2001-08-23 01:06:08 +00:00
|
|
|
{
|
1999-11-20 00:40:50 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-06-03 05:23:57 +00:00
|
|
|
variableNames.setValueDeleter(uprv_deleteUObject);
|
2001-07-27 00:18:53 +00:00
|
|
|
variables = 0;
|
|
|
|
variablesLength = 0;
|
1999-11-20 00:40:50 +00:00
|
|
|
}
|
|
|
|
|
2000-06-30 23:26:07 +00:00
|
|
|
TransliterationRuleData::TransliterationRuleData(const TransliterationRuleData& other) :
|
2002-10-04 18:06:33 +00:00
|
|
|
UMemory(other), ruleSet(other.ruleSet),
|
2022-09-08 21:15:13 +00:00
|
|
|
variablesAreOwned(true),
|
2001-07-27 00:18:53 +00:00
|
|
|
variablesBase(other.variablesBase),
|
2005-06-09 23:54:30 +00:00
|
|
|
variablesLength(other.variablesLength)
|
2001-08-23 01:06:08 +00:00
|
|
|
{
|
2000-06-30 23:26:07 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2008-01-14 20:27:51 +00:00
|
|
|
int32_t i = 0;
|
2011-06-03 05:23:57 +00:00
|
|
|
variableNames.setValueDeleter(uprv_deleteUObject);
|
2014-12-09 23:54:56 +00:00
|
|
|
int32_t pos = UHASH_FIRST;
|
2006-04-14 21:09:42 +00:00
|
|
|
const UHashElement *e;
|
|
|
|
while ((e = other.variableNames.nextElement(pos)) != 0) {
|
|
|
|
UnicodeString* value =
|
|
|
|
new UnicodeString(*(const UnicodeString*)e->value.pointer);
|
2008-01-14 20:27:51 +00:00
|
|
|
// Exit out if value could not be created.
|
|
|
|
if (value == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2006-04-14 21:09:42 +00:00
|
|
|
variableNames.put(*(UnicodeString*)e->key.pointer, value, status);
|
2000-06-30 23:26:07 +00:00
|
|
|
}
|
|
|
|
|
2001-07-27 00:18:53 +00:00
|
|
|
variables = 0;
|
|
|
|
if (other.variables != 0) {
|
2002-07-16 17:50:42 +00:00
|
|
|
variables = (UnicodeFunctor **)uprv_malloc(variablesLength * sizeof(UnicodeFunctor *));
|
2002-07-02 15:10:30 +00:00
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
if (variables == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2008-01-14 20:27:51 +00:00
|
|
|
for (i=0; i<variablesLength; ++i) {
|
2001-07-27 00:18:53 +00:00
|
|
|
variables[i] = other.variables[i]->clone();
|
2008-01-14 20:27:51 +00:00
|
|
|
if (variables[i] == NULL) {
|
2008-02-23 19:15:18 +00:00
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
break;
|
2008-01-14 20:27:51 +00:00
|
|
|
}
|
2000-06-30 23:26:07 +00:00
|
|
|
}
|
2008-01-14 20:27:51 +00:00
|
|
|
}
|
2022-09-08 21:15:13 +00:00
|
|
|
// Remove the array and exit if memory allocation error occurred.
|
2008-02-23 19:15:18 +00:00
|
|
|
if (U_FAILURE(status)) {
|
2014-07-16 21:04:08 +00:00
|
|
|
for (int32_t n = i-1; n >= 0; n--) {
|
2008-02-23 19:15:18 +00:00
|
|
|
delete variables[n];
|
|
|
|
}
|
|
|
|
uprv_free(variables);
|
|
|
|
variables = NULL;
|
|
|
|
return;
|
2008-01-14 20:27:51 +00:00
|
|
|
}
|
2002-03-20 00:53:49 +00:00
|
|
|
|
|
|
|
// Do this last, _after_ setting up variables[].
|
|
|
|
ruleSet.setData(this); // ruleSet must already be frozen
|
2000-06-30 23:26:07 +00:00
|
|
|
}
|
|
|
|
|
1999-11-20 00:40:50 +00:00
|
|
|
TransliterationRuleData::~TransliterationRuleData() {
|
2005-06-09 17:30:48 +00:00
|
|
|
if (variablesAreOwned && variables != 0) {
|
2001-07-27 00:18:53 +00:00
|
|
|
for (int32_t i=0; i<variablesLength; ++i) {
|
|
|
|
delete variables[i];
|
2000-05-20 04:40:29 +00:00
|
|
|
}
|
1999-11-20 00:40:50 +00:00
|
|
|
}
|
2005-06-09 17:30:48 +00:00
|
|
|
uprv_free(variables);
|
1999-11-20 00:40:50 +00:00
|
|
|
}
|
|
|
|
|
2002-03-20 00:42:02 +00:00
|
|
|
UnicodeFunctor*
|
|
|
|
TransliterationRuleData::lookup(UChar32 standIn) const {
|
|
|
|
int32_t i = standIn - variablesBase;
|
|
|
|
return (i >= 0 && i < variablesLength) ? variables[i] : 0;
|
|
|
|
}
|
|
|
|
|
2001-10-30 23:55:09 +00:00
|
|
|
UnicodeMatcher*
|
2002-02-07 01:07:55 +00:00
|
|
|
TransliterationRuleData::lookupMatcher(UChar32 standIn) const {
|
2002-03-20 00:42:02 +00:00
|
|
|
UnicodeFunctor *f = lookup(standIn);
|
|
|
|
return (f != 0) ? f->toMatcher() : 0;
|
1999-11-20 00:40:50 +00:00
|
|
|
}
|
|
|
|
|
2002-02-07 01:07:55 +00:00
|
|
|
UnicodeReplacer*
|
|
|
|
TransliterationRuleData::lookupReplacer(UChar32 standIn) const {
|
2002-03-20 00:42:02 +00:00
|
|
|
UnicodeFunctor *f = lookup(standIn);
|
|
|
|
return (f != 0) ? f->toReplacer() : 0;
|
1999-11-20 00:40:50 +00:00
|
|
|
}
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2003-12-10 01:52:39 +00:00
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_END
|
2002-09-20 01:54:48 +00:00
|
|
|
|
|
|
|
#endif /* #if !UCONFIG_NO_TRANSLITERATION */
|