Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / icu / source / i18n / cpdtrans.h
1 /*
2 **********************************************************************
3 *   Copyright (C) 1999-2011, 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  */
38 class U_I18N_API CompoundTransliterator : public Transliterator {
39
40     Transliterator** trans;
41
42     int32_t count;
43
44     int32_t numAnonymousRBTs;
45
46 public:
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.
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
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.
82      */
83     CompoundTransliterator(const UnicodeString& id,
84                            UParseError& parseError,
85                            UErrorCode& status);
86     /**
87      * Destructor.
88      */
89     virtual ~CompoundTransliterator();
90
91     /**
92      * Copy constructor.
93      */
94     CompoundTransliterator(const CompoundTransliterator&);
95
96     /**
97      * Transliterator API.
98      */
99     virtual Transliterator* clone(void) const;
100
101     /**
102      * Returns the number of transliterators in this chain.
103      * @return number of transliterators in this chain.
104      */
105     virtual int32_t getCount(void) const;
106
107     /**
108      * Returns the transliterator at the given index in this chain.
109      * @param idx index into chain, from 0 to <code>getCount() - 1</code>
110      * @return transliterator at the given index
111      */
112     virtual const Transliterator& getTransliterator(int32_t idx) const;
113
114     /**
115      * Sets the transliterators.
116      */
117     void setTransliterators(Transliterator* const transliterators[],
118                             int32_t count);
119
120     /**
121      * Adopts the transliterators.
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.
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
152 protected:
153     /**
154      * Implements {@link Transliterator#handleTransliterate}.
155      */
156     virtual void handleTransliterate(Replaceable& text, UTransPosition& idx,
157                                      UBool incremental) const;
158
159 public:
160
161     /**
162      * ICU "poor man's RTTI", returns a UClassID for the actual class.
163      */
164     virtual UClassID getDynamicClassID() const;
165
166     /**
167      * ICU "poor man's RTTI", returns a UClassID for this class.
168      */
169     static UClassID U_EXPORT2 getStaticClassID();
170
171     /* @internal */
172     static const UChar PASS_STRING[];
173
174 private:
175
176     friend class Transliterator;
177     friend class TransliteratorAlias; // to access private ct
178
179     /**
180      * Assignment operator.
181      */
182     CompoundTransliterator& operator=(const CompoundTransliterator&);
183
184     /**
185      * Private constructor for Transliterator.
186      */
187     CompoundTransliterator(const UnicodeString& ID,
188                            UVector& list,
189                            UnicodeFilter* adoptedFilter,
190                            int32_t numAnonymousRBTs,
191                            UParseError& parseError,
192                            UErrorCode& status);
193     
194     CompoundTransliterator(UVector& list,
195                            UParseError& parseError,
196                            UErrorCode& status);
197
198     CompoundTransliterator(UVector& list,
199                            int32_t anonymousRBTs,
200                            UParseError& parseError,
201                            UErrorCode& status);
202
203     void init(const UnicodeString& id,
204               UTransDirection direction,
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);
224 };
225
226 U_NAMESPACE_END
227
228 #endif /* #if !UCONFIG_NO_TRANSLITERATION */
229
230 #endif