]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
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 | ********************************************************************** | |
7 | */ | |
8 | #ifndef RBT_SET_H | |
9 | #define RBT_SET_H | |
10 | ||
11 | #include "unicode/utypes.h" | |
12 | ||
13 | #if !UCONFIG_NO_TRANSLITERATION | |
14 | ||
15 | #include "unicode/uobject.h" | |
16 | #include "unicode/utrans.h" | |
17 | #include "uvector.h" | |
18 | ||
19 | U_NAMESPACE_BEGIN | |
20 | ||
21 | class Replaceable; | |
22 | class TransliterationRule; | |
23 | class TransliterationRuleData; | |
24 | class UnicodeFilter; | |
25 | class UnicodeString; | |
26 | class UnicodeSet; | |
27 | ||
28 | /** | |
29 | * A set of rules for a <code>RuleBasedTransliterator</code>. | |
30 | * @author Alan Liu | |
31 | */ | |
32 | class U_I18N_API TransliterationRuleSet : public UMemory { | |
33 | /** | |
34 | * Vector of rules, in the order added. This is used while the | |
35 | * rule set is getting built. After that, freeze() reorders and | |
36 | * indexes the rules into rules[]. Any given rule is stored once | |
37 | * in ruleVector, and one or more times in rules[]. ruleVector | |
38 | * owns and deletes the rules. | |
39 | */ | |
40 | UVector* ruleVector; | |
41 | ||
42 | /** | |
43 | * Sorted and indexed table of rules. This is created by freeze() | |
44 | * from the rules in ruleVector. It contains alias pointers to | |
45 | * the rules in ruleVector. It is zero before freeze() is called | |
46 | * and non-zero thereafter. | |
47 | */ | |
48 | TransliterationRule** rules; | |
49 | ||
50 | /** | |
51 | * Index table. For text having a first character c, compute x = c&0xFF. | |
52 | * Now use rules[index[x]..index[x+1]-1]. This index table is created by | |
53 | * freeze(). Before freeze() is called it contains garbage. | |
54 | */ | |
55 | int32_t index[257]; | |
56 | ||
57 | /** | |
58 | * Length of the longest preceding context | |
59 | */ | |
60 | int32_t maxContextLength; | |
61 | ||
62 | public: | |
63 | ||
64 | /** | |
65 | * Construct a new empty rule set. | |
66 | * @param status Output parameter filled in with success or failure status. | |
67 | */ | |
68 | TransliterationRuleSet(UErrorCode& status); | |
69 | ||
70 | /** | |
71 | * Copy constructor. | |
72 | */ | |
73 | TransliterationRuleSet(const TransliterationRuleSet&); | |
74 | ||
75 | /** | |
76 | * Destructor. | |
77 | */ | |
78 | virtual ~TransliterationRuleSet(); | |
79 | ||
80 | /** | |
81 | * Change the data object that this rule belongs to. Used | |
82 | * internally by the TransliterationRuleData copy constructor. | |
83 | * @param data the new data value to be set. | |
84 | */ | |
85 | void setData(const TransliterationRuleData* data); | |
86 | ||
87 | /** | |
88 | * Return the maximum context length. | |
89 | * @return the length of the longest preceding context. | |
90 | */ | |
91 | virtual int32_t getMaximumContextLength(void) const; | |
92 | ||
93 | /** | |
94 | * Add a rule to this set. Rules are added in order, and order is | |
95 | * significant. The last call to this method must be followed by | |
96 | * a call to <code>freeze()</code> before the rule set is used. | |
97 | * This method must <em>not</em> be called after freeze() has been | |
98 | * called. | |
99 | * | |
100 | * @param adoptedRule the rule to add | |
101 | */ | |
102 | virtual void addRule(TransliterationRule* adoptedRule, | |
103 | UErrorCode& status); | |
104 | ||
105 | /** | |
106 | * Check this for masked rules and index it to optimize performance. | |
107 | * The sequence of operations is: (1) add rules to a set using | |
108 | * <code>addRule()</code>; (2) freeze the set using | |
109 | * <code>freeze()</code>; (3) use the rule set. If | |
110 | * <code>addRule()</code> is called after calling this method, it | |
111 | * invalidates this object, and this method must be called again. | |
112 | * That is, <code>freeze()</code> may be called multiple times, | |
113 | * although for optimal performance it shouldn't be. | |
114 | * @param parseError A pointer to UParseError to receive information about errors | |
115 | * occurred. | |
116 | * @param status Output parameter filled in with success or failure status. | |
117 | */ | |
118 | virtual void freeze(UParseError& parseError, UErrorCode& status); | |
119 | ||
120 | /** | |
121 | * Transliterate the given text with the given UTransPosition | |
122 | * indices. Return TRUE if the transliteration should continue | |
123 | * or FALSE if it should halt (because of a U_PARTIAL_MATCH match). | |
124 | * Note that FALSE is only ever returned if isIncremental is TRUE. | |
125 | * @param text the text to be transliterated | |
126 | * @param index the position indices, which will be updated | |
127 | * @param isIncremental if TRUE, assume new text may be inserted | |
128 | * at index.limit, and return FALSE if thre is a partial match. | |
129 | * @return TRUE unless a U_PARTIAL_MATCH has been obtained, | |
130 | * indicating that transliteration should stop until more text | |
131 | * arrives. | |
132 | */ | |
133 | UBool transliterate(Replaceable& text, | |
134 | UTransPosition& index, | |
135 | UBool isIncremental); | |
136 | ||
137 | /** | |
138 | * Create rule strings that represents this rule set. | |
139 | * @param result string to receive the rule strings. Current | |
140 | * contents will be deleted. | |
141 | * @param escapeUnprintable True, will escape the unprintable characters | |
142 | * @return A reference to 'result'. | |
143 | */ | |
144 | virtual UnicodeString& toRules(UnicodeString& result, | |
145 | UBool escapeUnprintable) const; | |
146 | ||
147 | /** | |
148 | * Return the set of all characters that may be modified | |
149 | * (getTarget=false) or emitted (getTarget=true) by this set. | |
150 | */ | |
151 | UnicodeSet& getSourceTargetSet(UnicodeSet& result, | |
374ca955 | 152 | UBool getTarget) const; |
b75a7d8f A |
153 | |
154 | private: | |
155 | ||
156 | TransliterationRuleSet &operator=(const TransliterationRuleSet &other); // forbid copying of this class | |
157 | }; | |
158 | ||
159 | U_NAMESPACE_END | |
160 | ||
161 | #endif /* #if !UCONFIG_NO_TRANSLITERATION */ | |
162 | ||
163 | #endif |