1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
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 **********************************************************************
15 #include "unicode/utypes.h"
17 #if !UCONFIG_NO_TRANSLITERATION
19 #include "unicode/translit.h"
23 class U_COMMON_API UVector
;
24 class TransliteratorRegistry
;
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.
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.
40 class U_I18N_API CompoundTransliterator
: public Transliterator
{
42 Transliterator
** trans
;
46 int32_t numAnonymousRBTs
;
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>
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.
64 CompoundTransliterator(Transliterator
* const transliterators
[],
65 int32_t transliteratorCount
,
66 UnicodeFilter
* adoptedFilter
= 0);
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
75 CompoundTransliterator(const UnicodeString
& id
,
77 UnicodeFilter
* adoptedFilter
,
78 UParseError
& parseError
,
82 * Constructs a new compound transliterator in the FORWARD
83 * direction with a NULL filter.
85 CompoundTransliterator(const UnicodeString
& id
,
86 UParseError
& parseError
,
91 virtual ~CompoundTransliterator();
96 CompoundTransliterator(const CompoundTransliterator
&);
101 virtual Transliterator
* clone(void) const;
104 * Returns the number of transliterators in this chain.
105 * @return number of transliterators in this chain.
107 virtual int32_t getCount(void) const;
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
114 virtual const Transliterator
& getTransliterator(int32_t idx
) const;
117 * Sets the transliterators.
119 void setTransliterators(Transliterator
* const transliterators
[],
123 * Adopts the transliterators.
125 void adoptTransliterators(Transliterator
* adoptedTransliterators
[],
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.
139 virtual UnicodeString
& toRules(UnicodeString
& result
,
140 UBool escapeUnprintable
) const;
144 * Implement Transliterator framework
146 virtual void handleGetSourceSet(UnicodeSet
& result
) const;
150 * Override Transliterator framework
152 virtual UnicodeSet
& getTargetSet(UnicodeSet
& result
) const;
156 * Implements {@link Transliterator#handleTransliterate}.
158 virtual void handleTransliterate(Replaceable
& text
, UTransPosition
& idx
,
159 UBool incremental
) const;
164 * ICU "poor man's RTTI", returns a UClassID for the actual class.
166 virtual UClassID
getDynamicClassID() const;
169 * ICU "poor man's RTTI", returns a UClassID for this class.
171 static UClassID U_EXPORT2
getStaticClassID();
174 static const UChar PASS_STRING
[];
178 friend class Transliterator
;
179 friend class TransliteratorAlias
; // to access private ct
182 * Assignment operator.
184 CompoundTransliterator
& operator=(const CompoundTransliterator
&);
187 * Private constructor for Transliterator.
189 CompoundTransliterator(const UnicodeString
& ID
,
191 UnicodeFilter
* adoptedFilter
,
192 int32_t numAnonymousRBTs
,
193 UParseError
& parseError
,
196 CompoundTransliterator(UVector
& list
,
197 UParseError
& parseError
,
200 CompoundTransliterator(UVector
& list
,
201 int32_t anonymousRBTs
,
202 UParseError
& parseError
,
205 void init(const UnicodeString
& id
,
206 UTransDirection direction
,
210 void init(UVector
& list
,
211 UTransDirection direction
,
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).
220 UnicodeString
joinIDs(Transliterator
* const transliterators
[],
223 void freeTransliterators(void);
225 void computeMaximumContextLength(void);
230 #endif /* #if !UCONFIG_NO_TRANSLITERATION */