]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/cpdtrans.h
ICU-62141.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / cpdtrans.h
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
b75a7d8f
A
3/*
4**********************************************************************
4388f060 5* Copyright (C) 1999-2011, International Business Machines
b75a7d8f
A
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
21U_NAMESPACE_BEGIN
22
374ca955 23class U_COMMON_API UVector;
b75a7d8f
A
24class 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
b75a7d8f
A
39 */
40class U_I18N_API CompoundTransliterator : public Transliterator {
41
42 Transliterator** trans;
43
44 int32_t count;
45
73c04bcf 46 int32_t numAnonymousRBTs;
b75a7d8f
A
47
48public:
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.
b75a7d8f
A
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
b75a7d8f
A
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.
b75a7d8f
A
84 */
85 CompoundTransliterator(const UnicodeString& id,
86 UParseError& parseError,
87 UErrorCode& status);
88 /**
89 * Destructor.
b75a7d8f
A
90 */
91 virtual ~CompoundTransliterator();
92
93 /**
94 * Copy constructor.
b75a7d8f
A
95 */
96 CompoundTransliterator(const CompoundTransliterator&);
97
b75a7d8f
A
98 /**
99 * Transliterator API.
b75a7d8f 100 */
374ca955 101 virtual Transliterator* clone(void) const;
b75a7d8f
A
102
103 /**
104 * Returns the number of transliterators in this chain.
105 * @return number of transliterators in this chain.
b75a7d8f
A
106 */
107 virtual int32_t getCount(void) const;
108
109 /**
110 * Returns the transliterator at the given index in this chain.
729e4ab9 111 * @param idx index into chain, from 0 to <code>getCount() - 1</code>
b75a7d8f 112 * @return transliterator at the given index
b75a7d8f 113 */
729e4ab9 114 virtual const Transliterator& getTransliterator(int32_t idx) const;
b75a7d8f
A
115
116 /**
117 * Sets the transliterators.
b75a7d8f
A
118 */
119 void setTransliterators(Transliterator* const transliterators[],
120 int32_t count);
121
122 /**
123 * Adopts the transliterators.
b75a7d8f
A
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.
b75a7d8f
A
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
154protected:
155 /**
156 * Implements {@link Transliterator#handleTransliterate}.
b75a7d8f 157 */
729e4ab9 158 virtual void handleTransliterate(Replaceable& text, UTransPosition& idx,
b75a7d8f
A
159 UBool incremental) const;
160
161public:
162
163 /**
164 * ICU "poor man's RTTI", returns a UClassID for the actual class.
b75a7d8f 165 */
374ca955 166 virtual UClassID getDynamicClassID() const;
b75a7d8f
A
167
168 /**
169 * ICU "poor man's RTTI", returns a UClassID for this class.
b75a7d8f 170 */
374ca955 171 static UClassID U_EXPORT2 getStaticClassID();
b75a7d8f 172
73c04bcf
A
173 /* @internal */
174 static const UChar PASS_STRING[];
175
b75a7d8f
A
176private:
177
178 friend class Transliterator;
179 friend class TransliteratorAlias; // to access private ct
180
46f4442e
A
181 /**
182 * Assignment operator.
46f4442e
A
183 */
184 CompoundTransliterator& operator=(const CompoundTransliterator&);
185
b75a7d8f 186 /**
73c04bcf 187 * Private constructor for Transliterator.
b75a7d8f
A
188 */
189 CompoundTransliterator(const UnicodeString& ID,
73c04bcf
A
190 UVector& list,
191 UnicodeFilter* adoptedFilter,
192 int32_t numAnonymousRBTs,
193 UParseError& parseError,
b75a7d8f 194 UErrorCode& status);
73c04bcf
A
195
196 CompoundTransliterator(UVector& list,
197 UParseError& parseError,
198 UErrorCode& status);
199
b75a7d8f 200 CompoundTransliterator(UVector& list,
73c04bcf 201 int32_t anonymousRBTs,
b75a7d8f
A
202 UParseError& parseError,
203 UErrorCode& status);
204
205 void init(const UnicodeString& id,
206 UTransDirection direction,
b75a7d8f
A
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);
b75a7d8f
A
226};
227
b75a7d8f
A
228U_NAMESPACE_END
229
230#endif /* #if !UCONFIG_NO_TRANSLITERATION */
231
232#endif