1999-11-20 00:40:50 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
|
|
|
* Copyright (C) 1999, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
|
|
|
* Date Name Description
|
|
|
|
* 11/17/99 aliu Creation.
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
2002-09-20 01:54:48 +00:00
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#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)
|
2002-10-04 18:06:33 +00:00
|
|
|
: UMemory(), ruleSet(status),
|
2001-08-23 01:06:08 +00:00
|
|
|
variableNames(0), variables(0)
|
|
|
|
{
|
1999-11-20 00:40:50 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return;
|
|
|
|
}
|
2000-03-28 22:12:14 +00:00
|
|
|
variableNames = new Hashtable(status);
|
2002-07-02 15:10:30 +00:00
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
if (variableNames == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2000-05-20 04:40:29 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
variableNames->setValueDeleter(uhash_deleteUnicodeString);
|
|
|
|
}
|
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),
|
2001-07-27 00:18:53 +00:00
|
|
|
variablesBase(other.variablesBase),
|
2002-02-07 01:07:55 +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;
|
|
|
|
variableNames = new Hashtable(status);
|
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
variableNames->setValueDeleter(uhash_deleteUnicodeString);
|
|
|
|
int32_t pos = -1;
|
|
|
|
const UHashElement *e;
|
|
|
|
while ((e = other.variableNames->nextElement(pos)) != 0) {
|
|
|
|
UnicodeString* value =
|
2001-10-16 18:31:13 +00:00
|
|
|
new UnicodeString(*(const UnicodeString*)e->value.pointer);
|
2001-07-06 19:53:12 +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;
|
|
|
|
}
|
2001-07-27 00:18:53 +00:00
|
|
|
for (int32_t i=0; i<variablesLength; ++i) {
|
|
|
|
variables[i] = other.variables[i]->clone();
|
2000-06-30 23:26:07 +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() {
|
2000-03-28 22:12:14 +00:00
|
|
|
delete variableNames;
|
2001-07-27 00:18:53 +00:00
|
|
|
if (variables != 0) {
|
|
|
|
for (int32_t i=0; i<variablesLength; ++i) {
|
|
|
|
delete variables[i];
|
2000-05-20 04:40:29 +00:00
|
|
|
}
|
2002-07-16 17:50:42 +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
|
|
|
|
|
|
|
U_NAMESPACE_END
|
2002-09-20 01:54:48 +00:00
|
|
|
|
|
|
|
#endif /* #if !UCONFIG_NO_TRANSLITERATION */
|