]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/cpdtrans.h
ICU-511.32.tar.gz
[apple/icu.git] / icuSources / i18n / cpdtrans.h
CommitLineData
b75a7d8f
A
1/*
2**********************************************************************
4388f060 3* Copyright (C) 1999-2011, International Business Machines
b75a7d8f
A
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
19U_NAMESPACE_BEGIN
20
374ca955 21class U_COMMON_API UVector;
b75a7d8f
A
22class 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
b75a7d8f
A
37 */
38class U_I18N_API CompoundTransliterator : public Transliterator {
39
40 Transliterator** trans;
41
42 int32_t count;
43
73c04bcf 44 int32_t numAnonymousRBTs;
b75a7d8f
A
45
46public:
47
48 /**
49 * Constructs a new compound transliterator given an array of
50 * transliterators. The array of transliterators may be of any
51 * length, including zero or one, however, useful compound
52 * transliterators have at least two components.
53 * @param transliterators array of <code>Transliterator</code>
54 * objects
55 * @param transliteratorCount The number of
56 * <code>Transliterator</code> objects in transliterators.
57 * @param adoptedFilter the filter. Any character for which
58 * <tt>filter.contains()</tt> returns <tt>false</tt> will not be
59 * altered by this transliterator. If <tt>filter</tt> is
60 * <tt>null</tt> then no filtering is applied.
b75a7d8f
A
61 */
62 CompoundTransliterator(Transliterator* const transliterators[],
63 int32_t transliteratorCount,
64 UnicodeFilter* adoptedFilter = 0);
65
66 /**
67 * Constructs a new compound transliterator.
68 * @param id compound ID
69 * @param dir either UTRANS_FORWARD or UTRANS_REVERSE
70 * @param adoptedFilter a global filter for this compound transliterator
71 * or NULL
b75a7d8f
A
72 */
73 CompoundTransliterator(const UnicodeString& id,
74 UTransDirection dir,
75 UnicodeFilter* adoptedFilter,
76 UParseError& parseError,
77 UErrorCode& status);
78
79 /**
80 * Constructs a new compound transliterator in the FORWARD
81 * direction with a NULL filter.
b75a7d8f
A
82 */
83 CompoundTransliterator(const UnicodeString& id,
84 UParseError& parseError,
85 UErrorCode& status);
86 /**
87 * Destructor.
b75a7d8f
A
88 */
89 virtual ~CompoundTransliterator();
90
91 /**
92 * Copy constructor.
b75a7d8f
A
93 */
94 CompoundTransliterator(const CompoundTransliterator&);
95
b75a7d8f
A
96 /**
97 * Transliterator API.
b75a7d8f 98 */
374ca955 99 virtual Transliterator* clone(void) const;
b75a7d8f
A
100
101 /**
102 * Returns the number of transliterators in this chain.
103 * @return number of transliterators in this chain.
b75a7d8f
A
104 */
105 virtual int32_t getCount(void) const;
106
107 /**
108 * Returns the transliterator at the given index in this chain.
729e4ab9 109 * @param idx index into chain, from 0 to <code>getCount() - 1</code>
b75a7d8f 110 * @return transliterator at the given index
b75a7d8f 111 */
729e4ab9 112 virtual const Transliterator& getTransliterator(int32_t idx) const;
b75a7d8f
A
113
114 /**
115 * Sets the transliterators.
b75a7d8f
A
116 */
117 void setTransliterators(Transliterator* const transliterators[],
118 int32_t count);
119
120 /**
121 * Adopts the transliterators.
b75a7d8f
A
122 */
123 void adoptTransliterators(Transliterator* adoptedTransliterators[],
124 int32_t count);
125
126 /**
127 * Override Transliterator:
128 * Create a rule string that can be passed to createFromRules()
129 * to recreate this transliterator.
130 * @param result the string to receive the rules. Previous
131 * contents will be deleted.
132 * @param escapeUnprintable if TRUE then convert unprintable
133 * character to their hex escape representations, \uxxxx or
134 * \Uxxxxxxxx. Unprintable characters are those other than
135 * U+000A, U+0020..U+007E.
b75a7d8f
A
136 */
137 virtual UnicodeString& toRules(UnicodeString& result,
138 UBool escapeUnprintable) const;
139
140 protected:
141 /**
142 * Implement Transliterator framework
143 */
144 virtual void handleGetSourceSet(UnicodeSet& result) const;
145
146 public:
147 /**
148 * Override Transliterator framework
149 */
150 virtual UnicodeSet& getTargetSet(UnicodeSet& result) const;
151
152protected:
153 /**
154 * Implements {@link Transliterator#handleTransliterate}.
b75a7d8f 155 */
729e4ab9 156 virtual void handleTransliterate(Replaceable& text, UTransPosition& idx,
b75a7d8f
A
157 UBool incremental) const;
158
159public:
160
161 /**
162 * ICU "poor man's RTTI", returns a UClassID for the actual class.
b75a7d8f 163 */
374ca955 164 virtual UClassID getDynamicClassID() const;
b75a7d8f
A
165
166 /**
167 * ICU "poor man's RTTI", returns a UClassID for this class.
b75a7d8f 168 */
374ca955 169 static UClassID U_EXPORT2 getStaticClassID();
b75a7d8f 170
73c04bcf
A
171 /* @internal */
172 static const UChar PASS_STRING[];
173
b75a7d8f
A
174private:
175
176 friend class Transliterator;
177 friend class TransliteratorAlias; // to access private ct
178
46f4442e
A
179 /**
180 * Assignment operator.
46f4442e
A
181 */
182 CompoundTransliterator& operator=(const CompoundTransliterator&);
183
b75a7d8f 184 /**
73c04bcf 185 * Private constructor for Transliterator.
b75a7d8f
A
186 */
187 CompoundTransliterator(const UnicodeString& ID,
73c04bcf
A
188 UVector& list,
189 UnicodeFilter* adoptedFilter,
190 int32_t numAnonymousRBTs,
191 UParseError& parseError,
b75a7d8f 192 UErrorCode& status);
73c04bcf
A
193
194 CompoundTransliterator(UVector& list,
195 UParseError& parseError,
196 UErrorCode& status);
197
b75a7d8f 198 CompoundTransliterator(UVector& list,
73c04bcf 199 int32_t anonymousRBTs,
b75a7d8f
A
200 UParseError& parseError,
201 UErrorCode& status);
202
203 void init(const UnicodeString& id,
204 UTransDirection direction,
b75a7d8f
A
205 UBool fixReverseID,
206 UErrorCode& status);
207
208 void init(UVector& list,
209 UTransDirection direction,
210 UBool fixReverseID,
211 UErrorCode& status);
212
213 /**
214 * Return the IDs of the given list of transliterators, concatenated
215 * with ';' delimiting them. Equivalent to the perlish expression
216 * join(';', map($_.getID(), transliterators).
217 */
218 UnicodeString joinIDs(Transliterator* const transliterators[],
219 int32_t transCount);
220
221 void freeTransliterators(void);
222
223 void computeMaximumContextLength(void);
b75a7d8f
A
224};
225
b75a7d8f
A
226U_NAMESPACE_END
227
228#endif /* #if !UCONFIG_NO_TRANSLITERATION */
229
230#endif