2
* Copyright (C) {1999}, International Business Machines Corporation and others. All Rights Reserved.
3
**********************************************************************
4
* Date Name Description
5
* 11/17/99 aliu Creation.
6
**********************************************************************
12
#include "unicode/utrans.h"
17
class TransliterationRule;
18
class TransliterationRuleData;
23
* A set of rules for a <code>RuleBasedTransliterator</code>.
26
class U_I18N_API TransliterationRuleSet {
28
* Vector of rules, in the order added. This is used while the
29
* rule set is getting built. After that, freeze() reorders and
30
* indexes the rules into rules[]. Any given rule is stored once
31
* in ruleVector, and one or more times in rules[]. ruleVector
32
* owns and deletes the rules.
37
* Sorted and indexed table of rules. This is created by freeze()
38
* from the rules in ruleVector. It contains alias pointers to
39
* the rules in ruleVector. It is zero before freeze() is called
40
* and non-zero thereafter.
42
TransliterationRule** rules;
45
* Index table. For text having a first character c, compute x = c&0xFF.
46
* Now use rules[index[x]..index[x+1]-1]. This index table is created by
47
* freeze(). Before freeze() is called it contains garbage.
52
* Length of the longest preceding context
54
int32_t maxContextLength;
59
* Construct a new empty rule set.
61
TransliterationRuleSet(UErrorCode& status);
66
TransliterationRuleSet(const TransliterationRuleSet&);
71
virtual ~TransliterationRuleSet();
74
* Change the data object that this rule belongs to. Used
75
* internally by the TransliterationRuleData copy constructor.
77
void setData(const TransliterationRuleData* data);
80
* Return the maximum context length.
81
* @return the length of the longest preceding context.
83
virtual int32_t getMaximumContextLength(void) const;
86
* Add a rule to this set. Rules are added in order, and order is
87
* significant. The last call to this method must be followed by
88
* a call to <code>freeze()</code> before the rule set is used.
89
* This method must <em>not</em> be called after freeze() has been
92
* @param adoptedRule the rule to add
94
virtual void addRule(TransliterationRule* adoptedRule,
98
* Check this for masked rules and index it to optimize performance.
99
* The sequence of operations is: (1) add rules to a set using
100
* <code>addRule()</code>; (2) freeze the set using
101
* <code>freeze()</code>; (3) use the rule set. If
102
* <code>addRule()</code> is called after calling this method, it
103
* invalidates this object, and this method must be called again.
104
* That is, <code>freeze()</code> may be called multiple times,
105
* although for optimal performance it shouldn't be.
107
virtual void freeze(UParseError& parseError, UErrorCode& status);
110
* Transliterate the given text with the given UTransPosition
111
* indices. Return TRUE if the transliteration should continue
112
* or FALSE if it should halt (because of a U_PARTIAL_MATCH match).
113
* Note that FALSE is only ever returned if isIncremental is TRUE.
114
* @param text the text to be transliterated
115
* @param index the position indices, which will be updated
116
* @param isIncremental if TRUE, assume new text may be inserted
117
* at index.limit, and return FALSE if thre is a partial match.
118
* @return TRUE unless a U_PARTIAL_MATCH has been obtained,
119
* indicating that transliteration should stop until more text
122
UBool transliterate(Replaceable& text,
123
UTransPosition& index,
124
UBool isIncremental);
127
* Create rule strings that represents this rule set.
128
* @param result string to receive the rule strings. Current
129
* contents will be deleted.
131
virtual UnicodeString& toRules(UnicodeString& result,
132
UBool escapeUnprintable) const;