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