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.
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
#include "rbt_data.h"
|
2000-03-28 22:12:14 +00:00
|
|
|
#include "hash.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/unistr.h"
|
2000-05-20 04:40:29 +00:00
|
|
|
#include "unicode/uniset.h"
|
1999-11-20 00:40:50 +00:00
|
|
|
|
2001-08-23 01:06:08 +00:00
|
|
|
TransliterationRuleData::TransliterationRuleData(UErrorCode& status)
|
|
|
|
: ruleSet(status),
|
|
|
|
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);
|
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) :
|
2000-07-11 18:45:49 +00:00
|
|
|
ruleSet(other.ruleSet),
|
2001-07-27 00:18:53 +00:00
|
|
|
variablesBase(other.variablesBase),
|
|
|
|
variablesLength(other.variablesLength),
|
2001-08-23 01:06:08 +00:00
|
|
|
segmentBase(other.segmentBase)
|
|
|
|
{
|
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 =
|
|
|
|
new UnicodeString(*(const UnicodeString*)e->value);
|
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) {
|
|
|
|
variables = new UnicodeMatcher*[variablesLength];
|
|
|
|
for (int32_t i=0; i<variablesLength; ++i) {
|
|
|
|
variables[i] = other.variables[i]->clone();
|
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
|
|
|
}
|
2001-07-27 00:18:53 +00:00
|
|
|
delete[] variables;
|
1999-11-20 00:40:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-27 00:18:53 +00:00
|
|
|
const UnicodeMatcher*
|
|
|
|
TransliterationRuleData::lookup(UChar32 standIn) const {
|
|
|
|
int32_t i = standIn - variablesBase;
|
|
|
|
return (i >= 0 && i < variablesLength) ? variables[i] : 0;
|
1999-11-20 00:40:50 +00:00
|
|
|
}
|
|
|
|
|
2000-05-20 04:40:29 +00:00
|
|
|
int32_t
|
2001-07-25 19:11:02 +00:00
|
|
|
TransliterationRuleData::lookupSegmentReference(UChar32 c) const {
|
2001-07-30 23:22:51 +00:00
|
|
|
int32_t i = segmentBase - c;
|
|
|
|
return (i >= 0 && i < segmentCount) ? i : -1;
|
1999-11-20 00:40:50 +00:00
|
|
|
}
|