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 **********************************************************************
13 #include "unicode/utypes.h"
15 #if !UCONFIG_NO_TRANSLITERATION
17 #include "unicode/translit.h"
21 class U_COMMON_API UVector;
22 class TransliteratorRegistry;
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.
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.
38 class U_I18N_API CompoundTransliterator : public Transliterator {
40 Transliterator** trans;
44 int32_t numAnonymousRBTs;
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>
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.
62 CompoundTransliterator(Transliterator* const transliterators[],
63 int32_t transliteratorCount,
64 UnicodeFilter* adoptedFilter = 0);
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
73 CompoundTransliterator(const UnicodeString& id,
75 UnicodeFilter* adoptedFilter,
76 UParseError& parseError,
80 * Constructs a new compound transliterator in the FORWARD
81 * direction with a NULL filter.
83 CompoundTransliterator(const UnicodeString& id,
84 UParseError& parseError,
89 virtual ~CompoundTransliterator();
94 CompoundTransliterator(const CompoundTransliterator&);
99 virtual Transliterator* clone(void) const;
102 * Returns the number of transliterators in this chain.
103 * @return number of transliterators in this chain.
105 virtual int32_t getCount(void) const;
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
112 virtual const Transliterator& getTransliterator(int32_t idx) const;
115 * Sets the transliterators.
117 void setTransliterators(Transliterator* const transliterators[],
121 * Adopts the transliterators.
123 void adoptTransliterators(Transliterator* adoptedTransliterators[],
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.
137 virtual UnicodeString& toRules(UnicodeString& result,
138 UBool escapeUnprintable) const;
142 * Implement Transliterator framework
144 virtual void handleGetSourceSet(UnicodeSet& result) const;
148 * Override Transliterator framework
150 virtual UnicodeSet& getTargetSet(UnicodeSet& result) const;
154 * Implements {@link Transliterator#handleTransliterate}.
156 virtual void handleTransliterate(Replaceable& text, UTransPosition& idx,
157 UBool incremental) const;
162 * ICU "poor man's RTTI", returns a UClassID for the actual class.
164 virtual UClassID getDynamicClassID() const;
167 * ICU "poor man's RTTI", returns a UClassID for this class.
169 static UClassID U_EXPORT2 getStaticClassID();
172 static const UChar PASS_STRING[];
176 friend class Transliterator;
177 friend class TransliteratorAlias; // to access private ct
180 * Assignment operator.
182 CompoundTransliterator& operator=(const CompoundTransliterator&);
185 * Private constructor for Transliterator.
187 CompoundTransliterator(const UnicodeString& ID,
189 UnicodeFilter* adoptedFilter,
190 int32_t numAnonymousRBTs,
191 UParseError& parseError,
194 CompoundTransliterator(UVector& list,
195 UParseError& parseError,
198 CompoundTransliterator(UVector& list,
199 int32_t anonymousRBTs,
200 UParseError& parseError,
203 void init(const UnicodeString& id,
204 UTransDirection direction,
208 void init(UVector& list,
209 UTransDirection direction,
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).
218 UnicodeString joinIDs(Transliterator* const transliterators[],
221 void freeTransliterators(void);
223 void computeMaximumContextLength(void);
228 #endif /* #if !UCONFIG_NO_TRANSLITERATION */