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"
|
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-02-08 02:49:15 +00:00
|
|
|
setVariables = 0;
|
|
|
|
setVariablesLength = 0;
|
1999-11-20 00:40:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TransliterationRuleData::~TransliterationRuleData() {
|
2000-03-28 22:12:14 +00:00
|
|
|
delete variableNames;
|
2000-02-08 02:49:15 +00:00
|
|
|
delete[] setVariables;
|
1999-11-20 00:40:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TransliterationRuleData::defineVariable(const UnicodeString& name,
|
|
|
|
UChar value,
|
|
|
|
UErrorCode& status) {
|
2000-03-28 22:12:14 +00:00
|
|
|
int32_t v = value | 0x10000; // Set bit 16
|
|
|
|
variableNames->put(name, (void*) v, status);
|
1999-11-20 00:40:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UChar
|
|
|
|
TransliterationRuleData::lookupVariable(const UnicodeString& name,
|
|
|
|
UErrorCode& status) const {
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2000-03-28 22:12:14 +00:00
|
|
|
void* value = variableNames->get(name);
|
|
|
|
/* Even U+0000 can be stored in the table because we set
|
|
|
|
* bit 16 in defineVariable().
|
|
|
|
*/
|
1999-11-20 00:40:50 +00:00
|
|
|
if (value == 0) {
|
|
|
|
status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
}
|
2000-03-29 21:41:11 +00:00
|
|
|
return (UChar) (int32_t) (unsigned long) value;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool_t
|
|
|
|
TransliterationRuleData::isVariableDefined(const UnicodeString& name) const {
|
2000-03-28 22:12:14 +00:00
|
|
|
return 0 != variableNames->get(name);
|
1999-11-20 00:40:50 +00:00
|
|
|
}
|