ICU-6.2.14.tar.gz
[apple/icu.git] / icuSources / i18n / cpdtrans.h
1 /*
2 **********************************************************************
3 * Copyright (C) 1999-2004, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 * Date Name Description
7 * 11/17/99 aliu Creation.
8 **********************************************************************
9 */
10 #ifndef CPDTRANS_H
11 #define CPDTRANS_H
12
13 #include "unicode/utypes.h"
14
15 #if !UCONFIG_NO_TRANSLITERATION
16
17 #include "unicode/translit.h"
18
19 U_NAMESPACE_BEGIN
20
21 class U_COMMON_API UVector;
22 class TransliteratorRegistry;
23
24 /**
25 * A transliterator that is composed of two or more other
26 * transliterator objects linked together. For example, if one
27 * transliterator transliterates from script A to script B, and
28 * another transliterates from script B to script C, the two may be
29 * combined to form a new transliterator from A to C.
30 *
31 * <p>Composed transliterators may not behave as expected. For
32 * example, inverses may not combine to form the identity
33 * transliterator. See the class documentation for {@link
34 * Transliterator} for details.
35 *
36 * @author Alan Liu
37 * @internal Use transliterator factory methods instead since this class will be removed in that release.
38 */
39 class U_I18N_API CompoundTransliterator : public Transliterator {
40
41 Transliterator** trans;
42
43 int32_t count;
44
45 /**
46 * For compound RBTs (those with an ::id block before and/or after
47 * the main rule block) we record the index of the RBT here.
48 * Otherwise, this should have a value of -1. We need this
49 * information to implement toRules().
50 */
51 int32_t compoundRBTIndex;
52
53 public:
54
55 /**
56 * Constructs a new compound transliterator given an array of
57 * transliterators. The array of transliterators may be of any
58 * length, including zero or one, however, useful compound
59 * transliterators have at least two components.
60 * @param transliterators array of <code>Transliterator</code>
61 * objects
62 * @param transliteratorCount The number of
63 * <code>Transliterator</code> objects in transliterators.
64 * @param adoptedFilter the filter. Any character for which
65 * <tt>filter.contains()</tt> returns <tt>false</tt> will not be
66 * altered by this transliterator. If <tt>filter</tt> is
67 * <tt>null</tt> then no filtering is applied.
68 * @internal Use transliterator factory methods instead since this class will be removed in that release.
69 */
70 CompoundTransliterator(Transliterator* const transliterators[],
71 int32_t transliteratorCount,
72 UnicodeFilter* adoptedFilter = 0);
73
74 /**
75 * Constructs a new compound transliterator.
76 * @param id compound ID
77 * @param dir either UTRANS_FORWARD or UTRANS_REVERSE
78 * @param adoptedFilter a global filter for this compound transliterator
79 * or NULL
80 * @internal Use transliterator factory methods instead since this class will be removed in that release.
81 */
82 CompoundTransliterator(const UnicodeString& id,
83 UTransDirection dir,
84 UnicodeFilter* adoptedFilter,
85 UParseError& parseError,
86 UErrorCode& status);
87
88 /**
89 * Constructs a new compound transliterator in the FORWARD
90 * direction with a NULL filter.
91 * @internal Use transliterator factory methods instead since this class will be removed in that release.
92 */
93 CompoundTransliterator(const UnicodeString& id,
94 UParseError& parseError,
95 UErrorCode& status);
96 /**
97 * Destructor.
98 * @internal Use transliterator factory methods instead since this class will be removed in that release.
99 */
100 virtual ~CompoundTransliterator();
101
102 /**
103 * Copy constructor.
104 * @internal Use transliterator factory methods instead since this class will be removed in that release.
105 */
106 CompoundTransliterator(const CompoundTransliterator&);
107
108 /**
109 * Assignment operator.
110 * @internal Use transliterator factory methods instead since this class will be removed in that release.
111 */
112 CompoundTransliterator& operator=(const CompoundTransliterator&);
113
114 /**
115 * Transliterator API.
116 * @internal Use transliterator factory methods instead since this class will be removed in that release.
117 */
118 virtual Transliterator* clone(void) const;
119
120 /**
121 * Returns the number of transliterators in this chain.
122 * @return number of transliterators in this chain.
123 * @internal Use transliterator factory methods instead since this class will be removed in that release.
124 */
125 virtual int32_t getCount(void) const;
126
127 /**
128 * Returns the transliterator at the given index in this chain.
129 * @param index index into chain, from 0 to <code>getCount() - 1</code>
130 * @return transliterator at the given index
131 * @internal Use transliterator factory methods instead since this class will be removed in that release.
132 */
133 virtual const Transliterator& getTransliterator(int32_t index) const;
134
135 /**
136 * Sets the transliterators.
137 * @internal Use transliterator factory methods instead since this class will be removed in that release.
138 */
139 void setTransliterators(Transliterator* const transliterators[],
140 int32_t count);
141
142 /**
143 * Adopts the transliterators.
144 * @internal Use transliterator factory methods instead since this class will be removed in that release.
145 */
146 void adoptTransliterators(Transliterator* adoptedTransliterators[],
147 int32_t count);
148
149 /**
150 * Override Transliterator:
151 * Create a rule string that can be passed to createFromRules()
152 * to recreate this transliterator.
153 * @param result the string to receive the rules. Previous
154 * contents will be deleted.
155 * @param escapeUnprintable if TRUE then convert unprintable
156 * character to their hex escape representations, \uxxxx or
157 * \Uxxxxxxxx. Unprintable characters are those other than
158 * U+000A, U+0020..U+007E.
159 * @internal Use transliterator factory methods instead since this class will be removed in that release.
160 */
161 virtual UnicodeString& toRules(UnicodeString& result,
162 UBool escapeUnprintable) const;
163
164 protected:
165 /**
166 * Implement Transliterator framework
167 */
168 virtual void handleGetSourceSet(UnicodeSet& result) const;
169
170 public:
171 /**
172 * Override Transliterator framework
173 */
174 virtual UnicodeSet& getTargetSet(UnicodeSet& result) const;
175
176 protected:
177 /**
178 * Implements {@link Transliterator#handleTransliterate}.
179 * @internal Use transliterator factory methods instead since this class will be removed in that release.
180 */
181 virtual void handleTransliterate(Replaceable& text, UTransPosition& index,
182 UBool incremental) const;
183
184 public:
185
186 /**
187 * ICU "poor man's RTTI", returns a UClassID for the actual class.
188 *
189 * @draft ICU 2.2
190 */
191 virtual UClassID getDynamicClassID() const;
192
193 /**
194 * ICU "poor man's RTTI", returns a UClassID for this class.
195 *
196 * @draft ICU 2.2
197 */
198 static UClassID U_EXPORT2 getStaticClassID();
199
200 private:
201
202 friend class Transliterator;
203 friend class TransliteratorAlias; // to access private ct
204
205 /**
206 * Private constructor for compound RBTs. Construct a compound
207 * transliterator using the given idBlock, with the adoptedTrans
208 * inserted at the idSplitPoint.
209 */
210 CompoundTransliterator(const UnicodeString& ID,
211 const UnicodeString& idBlock,
212 int32_t idSplitPoint,
213 Transliterator *adoptedTrans,
214 UErrorCode& status);
215
216 /**
217 * Private constructor for Transliterator.
218 */
219 CompoundTransliterator(UVector& list,
220 UParseError& parseError,
221 UErrorCode& status);
222
223 void init(const UnicodeString& id,
224 UTransDirection direction,
225 int32_t idSplitPoint,
226 Transliterator *adoptedRbt,
227 UBool fixReverseID,
228 UErrorCode& status);
229
230 void init(UVector& list,
231 UTransDirection direction,
232 UBool fixReverseID,
233 UErrorCode& status);
234
235 /**
236 * Return the IDs of the given list of transliterators, concatenated
237 * with ';' delimiting them. Equivalent to the perlish expression
238 * join(';', map($_.getID(), transliterators).
239 */
240 UnicodeString joinIDs(Transliterator* const transliterators[],
241 int32_t transCount);
242
243 void freeTransliterators(void);
244
245 void computeMaximumContextLength(void);
246 };
247
248 U_NAMESPACE_END
249
250 #endif /* #if !UCONFIG_NO_TRANSLITERATION */
251
252 #endif