1999-11-20 00:40:50 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
2006-04-14 21:09:42 +00:00
|
|
|
* Copyright (C) 1999-2006, International Business Machines
|
1999-11-20 00:40:50 +00:00
|
|
|
* 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"
|
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),
|
|
|
|
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;
|
|
|
|
}
|
2006-04-14 21:09:42 +00:00
|
|
|
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),
|
2005-06-09 23:54:30 +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;
|
2006-04-14 21:09:42 +00:00
|
|
|
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.pointer);
|
|
|
|
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() {
|
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 */
|