2 **********************************************************************
3 * Copyright (C) 1999-2006, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 * Date Name Description
7 * 11/17/99 aliu Creation.
8 **********************************************************************
11 #include "unicode/utypes.h"
14 #if !UCONFIG_NO_TRANSLITERATION
16 #include "unicode/unistr.h"
17 #include "unicode/uniset.h"
24 TransliterationRuleData::TransliterationRuleData(UErrorCode
& status
)
25 : UMemory(), ruleSet(status
), variableNames(status
),
26 variables(0), variablesAreOwned(TRUE
)
28 if (U_FAILURE(status
)) {
31 variableNames
.setValueDeleter(uhash_deleteUnicodeString
);
36 TransliterationRuleData::TransliterationRuleData(const TransliterationRuleData
& other
) :
37 UMemory(other
), ruleSet(other
.ruleSet
),
38 variablesAreOwned(TRUE
),
39 variablesBase(other
.variablesBase
),
40 variablesLength(other
.variablesLength
)
42 UErrorCode status
= U_ZERO_ERROR
;
43 variableNames
.setValueDeleter(uhash_deleteUnicodeString
);
45 const UHashElement
*e
;
46 while ((e
= other
.variableNames
.nextElement(pos
)) != 0) {
47 UnicodeString
* value
=
48 new UnicodeString(*(const UnicodeString
*)e
->value
.pointer
);
49 variableNames
.put(*(UnicodeString
*)e
->key
.pointer
, value
, status
);
53 if (other
.variables
!= 0) {
54 variables
= (UnicodeFunctor
**)uprv_malloc(variablesLength
* sizeof(UnicodeFunctor
*));
57 status
= U_MEMORY_ALLOCATION_ERROR
;
60 for (int32_t i
=0; i
<variablesLength
; ++i
) {
61 variables
[i
] = other
.variables
[i
]->clone();
65 // Do this last, _after_ setting up variables[].
66 ruleSet
.setData(this); // ruleSet must already be frozen
69 TransliterationRuleData::~TransliterationRuleData() {
70 if (variablesAreOwned
&& variables
!= 0) {
71 for (int32_t i
=0; i
<variablesLength
; ++i
) {
79 TransliterationRuleData::lookup(UChar32 standIn
) const {
80 int32_t i
= standIn
- variablesBase
;
81 return (i
>= 0 && i
< variablesLength
) ? variables
[i
] : 0;
85 TransliterationRuleData::lookupMatcher(UChar32 standIn
) const {
86 UnicodeFunctor
*f
= lookup(standIn
);
87 return (f
!= 0) ? f
->toMatcher() : 0;
91 TransliterationRuleData::lookupReplacer(UChar32 standIn
) const {
92 UnicodeFunctor
*f
= lookup(standIn
);
93 return (f
!= 0) ? f
->toReplacer() : 0;
99 #endif /* #if !UCONFIG_NO_TRANSLITERATION */