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
|
|
|
|
|
|
|
TransliterationRuleData::TransliterationRuleData(UErrorCode& status) :
|
|
|
|
variableNames(0), setVariables(0) {
|
|
|
|
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);
|
|
|
|
}
|
2000-02-08 02:49:15 +00:00
|
|
|
setVariables = 0;
|
|
|
|
setVariablesLength = 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),
|
2000-06-30 23:26:07 +00:00
|
|
|
setVariablesBase(other.setVariablesBase),
|
|
|
|
setVariablesLength(other.setVariablesLength),
|
|
|
|
segmentBase(other.segmentBase) {
|
|
|
|
|
|
|
|
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);
|
|
|
|
variableNames->put(*(UnicodeString*)e->key, value, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setVariables = 0;
|
|
|
|
if (other.setVariables != 0) {
|
|
|
|
setVariables = new UnicodeSet*[setVariablesLength];
|
|
|
|
for (int32_t i=0; i<setVariablesLength; ++i) {
|
|
|
|
setVariables[i] = new UnicodeSet(*other.setVariables[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-20 00:40:50 +00:00
|
|
|
TransliterationRuleData::~TransliterationRuleData() {
|
2000-03-28 22:12:14 +00:00
|
|
|
delete variableNames;
|
2000-05-20 04:40:29 +00:00
|
|
|
if (setVariables != 0) {
|
|
|
|
for (int32_t i=0; i<setVariablesLength; ++i) {
|
|
|
|
delete setVariables[i];
|
|
|
|
}
|
|
|
|
delete[] setVariables;
|
1999-11-20 00:40:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-08 02:49:15 +00:00
|
|
|
const UnicodeSet*
|
1999-11-20 00:40:50 +00:00
|
|
|
TransliterationRuleData::lookupSet(UChar standIn) const {
|
2000-02-08 02:49:15 +00:00
|
|
|
int32_t i = standIn - setVariablesBase;
|
|
|
|
return (i >= 0 && i < setVariablesLength) ? setVariables[i] : 0;
|
1999-11-20 00:40:50 +00:00
|
|
|
}
|
|
|
|
|
2000-05-20 04:40:29 +00:00
|
|
|
int32_t
|
|
|
|
TransliterationRuleData::lookupSegmentReference(UChar c) const {
|
|
|
|
int32_t i = c - segmentBase;
|
|
|
|
return (i >= 0 && i < 9) ? i : -1;
|
1999-11-20 00:40:50 +00:00
|
|
|
}
|