1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 **********************************************************************
5 * Copyright (C) 1999-2007, 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"
20 #include "unicode/utypes.h"
21 #include "unicode/parseerr.h"
22 #include "unicode/udata.h"
24 #define U_ICUDATA_TRANSLIT U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "translit"
28 class TransliterationRuleData
;
31 * <code>RuleBasedTransliterator</code> is a transliterator
32 * built from a set of rules as defined for
33 * Transliterator::createFromRules().
34 * See the C++ class Transliterator documentation for the rule syntax.
37 * @internal Use transliterator factory methods instead since this class will be removed in that release.
39 class RuleBasedTransliterator
: public Transliterator
{
42 * The data object is immutable, so we can freely share it with
43 * other instances of RBT, as long as we do NOT own this object.
44 * TODO: data is no longer immutable. See bugs #1866, 2155
46 TransliterationRuleData
* fData
;
49 * If true, we own the data object and must delete it.
56 * Constructs a new transliterator from the given rules.
57 * @param rules rules, separated by ';'
58 * @param direction either FORWARD or REVERSE.
59 * @exception IllegalArgumentException if rules are malformed.
60 * @internal Use transliterator factory methods instead since this class will be removed in that release.
62 RuleBasedTransliterator(const UnicodeString
& id
,
63 const UnicodeString
& rules
,
64 UTransDirection direction
,
65 UnicodeFilter
* adoptedFilter
,
66 UParseError
& parseError
,
70 * Constructs a new transliterator from the given rules.
71 * @param rules rules, separated by ';'
72 * @param direction either FORWARD or REVERSE.
73 * @exception IllegalArgumentException if rules are malformed.
74 * @internal Use transliterator factory methods instead since this class will be removed in that release.
76 /*RuleBasedTransliterator(const UnicodeString& id,
77 const UnicodeString& rules,
78 UTransDirection direction,
79 UnicodeFilter* adoptedFilter,
80 UErrorCode& status);*/
83 * Covenience constructor with no filter.
84 * @internal Use transliterator factory methods instead since this class will be removed in that release.
86 /*RuleBasedTransliterator(const UnicodeString& id,
87 const UnicodeString& rules,
88 UTransDirection direction,
89 UErrorCode& status);*/
92 * Covenience constructor with no filter and FORWARD direction.
93 * @internal Use transliterator factory methods instead since this class will be removed in that release.
95 /*RuleBasedTransliterator(const UnicodeString& id,
96 const UnicodeString& rules,
97 UErrorCode& status);*/
100 * Covenience constructor with FORWARD direction.
101 * @internal Use transliterator factory methods instead since this class will be removed in that release.
103 /*RuleBasedTransliterator(const UnicodeString& id,
104 const UnicodeString& rules,
105 UnicodeFilter* adoptedFilter,
106 UErrorCode& status);*/
109 friend class TransliteratorRegistry
; // to access TransliterationRuleData convenience ctor
111 * Covenience constructor.
112 * @param id the id for the transliterator.
113 * @param theData the rule data for the transliterator.
114 * @param adoptedFilter the filter for the transliterator
116 RuleBasedTransliterator(const UnicodeString
& id
,
117 const TransliterationRuleData
* theData
,
118 UnicodeFilter
* adoptedFilter
= 0);
121 friend class Transliterator
; // to access following ct
124 * Internal constructor.
125 * @param id the id for the transliterator.
126 * @param theData the rule data for the transliterator.
127 * @param isDataAdopted determine who will own the 'data' object. True, the caller should not delete 'data'.
129 RuleBasedTransliterator(const UnicodeString
& id
,
130 TransliterationRuleData
* data
,
131 UBool isDataAdopted
);
137 * @internal Use transliterator factory methods instead since this class will be removed in that release.
139 RuleBasedTransliterator(const RuleBasedTransliterator
&);
141 virtual ~RuleBasedTransliterator();
144 * Implement Transliterator API.
145 * @internal Use transliterator factory methods instead since this class will be removed in that release.
147 virtual Transliterator
* clone(void) const;
151 * Implements {@link Transliterator#handleTransliterate}.
152 * @internal Use transliterator factory methods instead since this class will be removed in that release.
154 virtual void handleTransliterate(Replaceable
& text
, UTransPosition
& offsets
,
155 UBool isIncremental
) const;
159 * Return a representation of this transliterator as source rules.
160 * These rules will produce an equivalent transliterator if used
161 * to construct a new transliterator.
162 * @param result the string to receive the rules. Previous
163 * contents will be deleted.
164 * @param escapeUnprintable if TRUE then convert unprintable
165 * character to their hex escape representations, \uxxxx or
166 * \Uxxxxxxxx. Unprintable characters are those other than
167 * U+000A, U+0020..U+007E.
168 * @internal Use transliterator factory methods instead since this class will be removed in that release.
170 virtual UnicodeString
& toRules(UnicodeString
& result
,
171 UBool escapeUnprintable
) const;
175 * Implement Transliterator framework
177 virtual void handleGetSourceSet(UnicodeSet
& result
) const;
181 * Override Transliterator framework
183 virtual UnicodeSet
& getTargetSet(UnicodeSet
& result
) const;
186 * Return the class ID for this class. This is useful only for
187 * comparing to a return value from getDynamicClassID(). For example:
189 * . Base* polymorphic_pointer = createPolymorphicObject();
190 * . if (polymorphic_pointer->getDynamicClassID() ==
191 * . Derived::getStaticClassID()) ...
193 * @return The class ID for all objects of this class.
194 * @internal Use transliterator factory methods instead since this class will be removed in that release.
196 U_I18N_API
static UClassID U_EXPORT2
getStaticClassID(void);
199 * Returns a unique class ID <b>polymorphically</b>. This method
200 * is to implement a simple version of RTTI, since not all C++
201 * compilers support genuine RTTI. Polymorphic operator==() and
202 * clone() methods call this method.
204 * @return The class ID for this object. All objects of a given
205 * class have the same class ID. Objects of other classes have
206 * different class IDs.
208 virtual UClassID
getDynamicClassID(void) const;
212 void _construct(const UnicodeString
& rules
,
213 UTransDirection direction
,
214 UParseError
& parseError
,
221 #endif /* #if !UCONFIG_NO_TRANSLITERATION */