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