]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/rbt.h
ICU-64260.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / rbt.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**********************************************************************
46f4442e 5* Copyright (C) 1999-2007, 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 RBT_H
13#define RBT_H
14
15#include "unicode/utypes.h"
16
17#if !UCONFIG_NO_TRANSLITERATION
18
19#include "unicode/translit.h"
20#include "unicode/utypes.h"
21#include "unicode/parseerr.h"
374ca955
A
22#include "unicode/udata.h"
23
24#define U_ICUDATA_TRANSLIT U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "translit"
b75a7d8f
A
25
26U_NAMESPACE_BEGIN
27
28class TransliterationRuleData;
29
30/**
31 * <code>RuleBasedTransliterator</code> is a transliterator
3d1f044b
A
32 * built from a set of rules as defined for
33 * Transliterator::createFromRules().
34 * See the C++ class Transliterator documentation for the rule syntax.
35 *
b75a7d8f
A
36 * @author Alan Liu
37 * @internal Use transliterator factory methods instead since this class will be removed in that release.
38 */
46f4442e 39class RuleBasedTransliterator : public Transliterator {
374ca955 40private:
b75a7d8f
A
41 /**
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.
374ca955 44 * TODO: data is no longer immutable. See bugs #1866, 2155
b75a7d8f 45 */
374ca955 46 TransliterationRuleData* fData;
b75a7d8f
A
47
48 /**
49 * If true, we own the data object and must delete it.
50 */
51 UBool isDataOwned;
52
53public:
54
55 /**
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.
61 */
62 RuleBasedTransliterator(const UnicodeString& id,
63 const UnicodeString& rules,
64 UTransDirection direction,
65 UnicodeFilter* adoptedFilter,
66 UParseError& parseError,
67 UErrorCode& status);
68
69 /**
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.
75 */
46f4442e 76 /*RuleBasedTransliterator(const UnicodeString& id,
b75a7d8f
A
77 const UnicodeString& rules,
78 UTransDirection direction,
79 UnicodeFilter* adoptedFilter,
46f4442e 80 UErrorCode& status);*/
b75a7d8f
A
81
82 /**
83 * Covenience constructor with no filter.
84 * @internal Use transliterator factory methods instead since this class will be removed in that release.
85 */
46f4442e 86 /*RuleBasedTransliterator(const UnicodeString& id,
b75a7d8f
A
87 const UnicodeString& rules,
88 UTransDirection direction,
46f4442e 89 UErrorCode& status);*/
b75a7d8f
A
90
91 /**
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.
94 */
46f4442e 95 /*RuleBasedTransliterator(const UnicodeString& id,
b75a7d8f 96 const UnicodeString& rules,
46f4442e 97 UErrorCode& status);*/
b75a7d8f
A
98
99 /**
100 * Covenience constructor with FORWARD direction.
101 * @internal Use transliterator factory methods instead since this class will be removed in that release.
102 */
46f4442e 103 /*RuleBasedTransliterator(const UnicodeString& id,
b75a7d8f
A
104 const UnicodeString& rules,
105 UnicodeFilter* adoptedFilter,
46f4442e 106 UErrorCode& status);*/
374ca955 107private:
b75a7d8f
A
108
109 friend class TransliteratorRegistry; // to access TransliterationRuleData convenience ctor
110 /**
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
115 */
116 RuleBasedTransliterator(const UnicodeString& id,
117 const TransliterationRuleData* theData,
118 UnicodeFilter* adoptedFilter = 0);
119
120
121 friend class Transliterator; // to access following ct
122
123 /**
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'.
128 */
129 RuleBasedTransliterator(const UnicodeString& id,
130 TransliterationRuleData* data,
131 UBool isDataAdopted);
132
374ca955 133public:
b75a7d8f
A
134
135 /**
136 * Copy constructor.
137 * @internal Use transliterator factory methods instead since this class will be removed in that release.
138 */
139 RuleBasedTransliterator(const RuleBasedTransliterator&);
140
141 virtual ~RuleBasedTransliterator();
142
143 /**
144 * Implement Transliterator API.
145 * @internal Use transliterator factory methods instead since this class will be removed in that release.
146 */
374ca955 147 virtual Transliterator* clone(void) const;
b75a7d8f 148
374ca955 149protected:
b75a7d8f
A
150 /**
151 * Implements {@link Transliterator#handleTransliterate}.
152 * @internal Use transliterator factory methods instead since this class will be removed in that release.
153 */
154 virtual void handleTransliterate(Replaceable& text, UTransPosition& offsets,
155 UBool isIncremental) const;
156
374ca955 157public:
b75a7d8f
A
158 /**
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.
169 */
170 virtual UnicodeString& toRules(UnicodeString& result,
171 UBool escapeUnprintable) const;
172
374ca955 173protected:
b75a7d8f
A
174 /**
175 * Implement Transliterator framework
176 */
177 virtual void handleGetSourceSet(UnicodeSet& result) const;
178
374ca955 179public:
b75a7d8f
A
180 /**
181 * Override Transliterator framework
182 */
183 virtual UnicodeSet& getTargetSet(UnicodeSet& result) const;
184
185 /**
186 * Return the class ID for this class. This is useful only for
187 * comparing to a return value from getDynamicClassID(). For example:
188 * <pre>
189 * . Base* polymorphic_pointer = createPolymorphicObject();
190 * . if (polymorphic_pointer->getDynamicClassID() ==
191 * . Derived::getStaticClassID()) ...
192 * </pre>
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.
195 */
46f4442e 196 U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
b75a7d8f
A
197
198 /**
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.
203 *
b75a7d8f
A
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.
207 */
374ca955 208 virtual UClassID getDynamicClassID(void) const;
b75a7d8f
A
209
210private:
211
b75a7d8f
A
212 void _construct(const UnicodeString& rules,
213 UTransDirection direction,
214 UParseError& parseError,
215 UErrorCode& status);
216};
217
b75a7d8f
A
218
219U_NAMESPACE_END
220
221#endif /* #if !UCONFIG_NO_TRANSLITERATION */
222
223#endif