1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /*
4*0e209d39SAndroid Build Coastguard Worker **********************************************************************
5*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 1999-2014, International Business Machines
6*0e209d39SAndroid Build Coastguard Worker * Corporation and others. All Rights Reserved.
7*0e209d39SAndroid Build Coastguard Worker **********************************************************************
8*0e209d39SAndroid Build Coastguard Worker * Date Name Description
9*0e209d39SAndroid Build Coastguard Worker * 11/17/99 aliu Creation.
10*0e209d39SAndroid Build Coastguard Worker **********************************************************************
11*0e209d39SAndroid Build Coastguard Worker */
12*0e209d39SAndroid Build Coastguard Worker #ifndef TRANSLIT_H
13*0e209d39SAndroid Build Coastguard Worker #define TRANSLIT_H
14*0e209d39SAndroid Build Coastguard Worker
15*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
16*0e209d39SAndroid Build Coastguard Worker
17*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API
18*0e209d39SAndroid Build Coastguard Worker
19*0e209d39SAndroid Build Coastguard Worker /**
20*0e209d39SAndroid Build Coastguard Worker * \file
21*0e209d39SAndroid Build Coastguard Worker * \brief C++ API: Transforms text from one format to another.
22*0e209d39SAndroid Build Coastguard Worker */
23*0e209d39SAndroid Build Coastguard Worker
24*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_TRANSLITERATION
25*0e209d39SAndroid Build Coastguard Worker
26*0e209d39SAndroid Build Coastguard Worker #include "unicode/uobject.h"
27*0e209d39SAndroid Build Coastguard Worker #include "unicode/unistr.h"
28*0e209d39SAndroid Build Coastguard Worker #include "unicode/parseerr.h"
29*0e209d39SAndroid Build Coastguard Worker #include "unicode/utrans.h" // UTransPosition, UTransDirection
30*0e209d39SAndroid Build Coastguard Worker #include "unicode/strenum.h"
31*0e209d39SAndroid Build Coastguard Worker
32*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
33*0e209d39SAndroid Build Coastguard Worker
34*0e209d39SAndroid Build Coastguard Worker class UnicodeFilter;
35*0e209d39SAndroid Build Coastguard Worker class UnicodeSet;
36*0e209d39SAndroid Build Coastguard Worker class TransliteratorParser;
37*0e209d39SAndroid Build Coastguard Worker class NormalizationTransliterator;
38*0e209d39SAndroid Build Coastguard Worker class TransliteratorIDParser;
39*0e209d39SAndroid Build Coastguard Worker
40*0e209d39SAndroid Build Coastguard Worker /**
41*0e209d39SAndroid Build Coastguard Worker *
42*0e209d39SAndroid Build Coastguard Worker * <code>Transliterator</code> is an abstract class that
43*0e209d39SAndroid Build Coastguard Worker * transliterates text from one format to another. The most common
44*0e209d39SAndroid Build Coastguard Worker * kind of transliterator is a script, or alphabet, transliterator.
45*0e209d39SAndroid Build Coastguard Worker * For example, a Russian to Latin transliterator changes Russian text
46*0e209d39SAndroid Build Coastguard Worker * written in Cyrillic characters to phonetically equivalent Latin
47*0e209d39SAndroid Build Coastguard Worker * characters. It does not <em>translate</em> Russian to English!
48*0e209d39SAndroid Build Coastguard Worker * Transliteration, unlike translation, operates on characters, without
49*0e209d39SAndroid Build Coastguard Worker * reference to the meanings of words and sentences.
50*0e209d39SAndroid Build Coastguard Worker *
51*0e209d39SAndroid Build Coastguard Worker * <p>Although script conversion is its most common use, a
52*0e209d39SAndroid Build Coastguard Worker * transliterator can actually perform a more general class of tasks.
53*0e209d39SAndroid Build Coastguard Worker * In fact, <code>Transliterator</code> defines a very general API
54*0e209d39SAndroid Build Coastguard Worker * which specifies only that a segment of the input text is replaced
55*0e209d39SAndroid Build Coastguard Worker * by new text. The particulars of this conversion are determined
56*0e209d39SAndroid Build Coastguard Worker * entirely by subclasses of <code>Transliterator</code>.
57*0e209d39SAndroid Build Coastguard Worker *
58*0e209d39SAndroid Build Coastguard Worker * <p><b>Transliterators are stateless</b>
59*0e209d39SAndroid Build Coastguard Worker *
60*0e209d39SAndroid Build Coastguard Worker * <p><code>Transliterator</code> objects are <em>stateless</em>; they
61*0e209d39SAndroid Build Coastguard Worker * retain no information between calls to
62*0e209d39SAndroid Build Coastguard Worker * <code>transliterate()</code>. (However, this does <em>not</em>
63*0e209d39SAndroid Build Coastguard Worker * mean that threads may share transliterators without synchronizing
64*0e209d39SAndroid Build Coastguard Worker * them. Transliterators are not immutable, so they must be
65*0e209d39SAndroid Build Coastguard Worker * synchronized when shared between threads.) This might seem to
66*0e209d39SAndroid Build Coastguard Worker * limit the complexity of the transliteration operation. In
67*0e209d39SAndroid Build Coastguard Worker * practice, subclasses perform complex transliterations by delaying
68*0e209d39SAndroid Build Coastguard Worker * the replacement of text until it is known that no other
69*0e209d39SAndroid Build Coastguard Worker * replacements are possible. In other words, although the
70*0e209d39SAndroid Build Coastguard Worker * <code>Transliterator</code> objects are stateless, the source text
71*0e209d39SAndroid Build Coastguard Worker * itself embodies all the needed information, and delayed operation
72*0e209d39SAndroid Build Coastguard Worker * allows arbitrary complexity.
73*0e209d39SAndroid Build Coastguard Worker *
74*0e209d39SAndroid Build Coastguard Worker * <p><b>Batch transliteration</b>
75*0e209d39SAndroid Build Coastguard Worker *
76*0e209d39SAndroid Build Coastguard Worker * <p>The simplest way to perform transliteration is all at once, on a
77*0e209d39SAndroid Build Coastguard Worker * string of existing text. This is referred to as <em>batch</em>
78*0e209d39SAndroid Build Coastguard Worker * transliteration. For example, given a string <code>input</code>
79*0e209d39SAndroid Build Coastguard Worker * and a transliterator <code>t</code>, the call
80*0e209d39SAndroid Build Coastguard Worker *
81*0e209d39SAndroid Build Coastguard Worker * String result = t.transliterate(input);
82*0e209d39SAndroid Build Coastguard Worker *
83*0e209d39SAndroid Build Coastguard Worker * will transliterate it and return the result. Other methods allow
84*0e209d39SAndroid Build Coastguard Worker * the client to specify a substring to be transliterated and to use
85*0e209d39SAndroid Build Coastguard Worker * {@link Replaceable } objects instead of strings, in order to
86*0e209d39SAndroid Build Coastguard Worker * preserve out-of-band information (such as text styles).
87*0e209d39SAndroid Build Coastguard Worker *
88*0e209d39SAndroid Build Coastguard Worker * <p><b>Keyboard transliteration</b>
89*0e209d39SAndroid Build Coastguard Worker *
90*0e209d39SAndroid Build Coastguard Worker * <p>Somewhat more involved is <em>keyboard</em>, or incremental
91*0e209d39SAndroid Build Coastguard Worker * transliteration. This is the transliteration of text that is
92*0e209d39SAndroid Build Coastguard Worker * arriving from some source (typically the user's keyboard) one
93*0e209d39SAndroid Build Coastguard Worker * character at a time, or in some other piecemeal fashion.
94*0e209d39SAndroid Build Coastguard Worker *
95*0e209d39SAndroid Build Coastguard Worker * <p>In keyboard transliteration, a <code>Replaceable</code> buffer
96*0e209d39SAndroid Build Coastguard Worker * stores the text. As text is inserted, as much as possible is
97*0e209d39SAndroid Build Coastguard Worker * transliterated on the fly. This means a GUI that displays the
98*0e209d39SAndroid Build Coastguard Worker * contents of the buffer may show text being modified as each new
99*0e209d39SAndroid Build Coastguard Worker * character arrives.
100*0e209d39SAndroid Build Coastguard Worker *
101*0e209d39SAndroid Build Coastguard Worker * <p>Consider the simple rule-based Transliterator:
102*0e209d39SAndroid Build Coastguard Worker * <pre>
103*0e209d39SAndroid Build Coastguard Worker * th>{theta}
104*0e209d39SAndroid Build Coastguard Worker * t>{tau}
105*0e209d39SAndroid Build Coastguard Worker * </pre>
106*0e209d39SAndroid Build Coastguard Worker *
107*0e209d39SAndroid Build Coastguard Worker * When the user types 't', nothing will happen, since the
108*0e209d39SAndroid Build Coastguard Worker * transliterator is waiting to see if the next character is 'h'. To
109*0e209d39SAndroid Build Coastguard Worker * remedy this, we introduce the notion of a cursor, marked by a '|'
110*0e209d39SAndroid Build Coastguard Worker * in the output string:
111*0e209d39SAndroid Build Coastguard Worker * <pre>
112*0e209d39SAndroid Build Coastguard Worker * t>|{tau}
113*0e209d39SAndroid Build Coastguard Worker * {tau}h>{theta}
114*0e209d39SAndroid Build Coastguard Worker * </pre>
115*0e209d39SAndroid Build Coastguard Worker *
116*0e209d39SAndroid Build Coastguard Worker * Now when the user types 't', tau appears, and if the next character
117*0e209d39SAndroid Build Coastguard Worker * is 'h', the tau changes to a theta. This is accomplished by
118*0e209d39SAndroid Build Coastguard Worker * maintaining a cursor position (independent of the insertion point,
119*0e209d39SAndroid Build Coastguard Worker * and invisible in the GUI) across calls to
120*0e209d39SAndroid Build Coastguard Worker * <code>transliterate()</code>. Typically, the cursor will
121*0e209d39SAndroid Build Coastguard Worker * be coincident with the insertion point, but in a case like the one
122*0e209d39SAndroid Build Coastguard Worker * above, it will precede the insertion point.
123*0e209d39SAndroid Build Coastguard Worker *
124*0e209d39SAndroid Build Coastguard Worker * <p>Keyboard transliteration methods maintain a set of three indices
125*0e209d39SAndroid Build Coastguard Worker * that are updated with each call to
126*0e209d39SAndroid Build Coastguard Worker * <code>transliterate()</code>, including the cursor, start,
127*0e209d39SAndroid Build Coastguard Worker * and limit. Since these indices are changed by the method, they are
128*0e209d39SAndroid Build Coastguard Worker * passed in an <code>int[]</code> array. The <code>START</code> index
129*0e209d39SAndroid Build Coastguard Worker * marks the beginning of the substring that the transliterator will
130*0e209d39SAndroid Build Coastguard Worker * look at. It is advanced as text becomes committed (but it is not
131*0e209d39SAndroid Build Coastguard Worker * the committed index; that's the <code>CURSOR</code>). The
132*0e209d39SAndroid Build Coastguard Worker * <code>CURSOR</code> index, described above, marks the point at
133*0e209d39SAndroid Build Coastguard Worker * which the transliterator last stopped, either because it reached
134*0e209d39SAndroid Build Coastguard Worker * the end, or because it required more characters to disambiguate
135*0e209d39SAndroid Build Coastguard Worker * between possible inputs. The <code>CURSOR</code> can also be
136*0e209d39SAndroid Build Coastguard Worker * explicitly set by rules in a rule-based Transliterator.
137*0e209d39SAndroid Build Coastguard Worker * Any characters before the <code>CURSOR</code> index are frozen;
138*0e209d39SAndroid Build Coastguard Worker * future keyboard transliteration calls within this input sequence
139*0e209d39SAndroid Build Coastguard Worker * will not change them. New text is inserted at the
140*0e209d39SAndroid Build Coastguard Worker * <code>LIMIT</code> index, which marks the end of the substring that
141*0e209d39SAndroid Build Coastguard Worker * the transliterator looks at.
142*0e209d39SAndroid Build Coastguard Worker *
143*0e209d39SAndroid Build Coastguard Worker * <p>Because keyboard transliteration assumes that more characters
144*0e209d39SAndroid Build Coastguard Worker * are to arrive, it is conservative in its operation. It only
145*0e209d39SAndroid Build Coastguard Worker * transliterates when it can do so unambiguously. Otherwise it waits
146*0e209d39SAndroid Build Coastguard Worker * for more characters to arrive. When the client code knows that no
147*0e209d39SAndroid Build Coastguard Worker * more characters are forthcoming, perhaps because the user has
148*0e209d39SAndroid Build Coastguard Worker * performed some input termination operation, then it should call
149*0e209d39SAndroid Build Coastguard Worker * <code>finishTransliteration()</code> to complete any
150*0e209d39SAndroid Build Coastguard Worker * pending transliterations.
151*0e209d39SAndroid Build Coastguard Worker *
152*0e209d39SAndroid Build Coastguard Worker * <p><b>Inverses</b>
153*0e209d39SAndroid Build Coastguard Worker *
154*0e209d39SAndroid Build Coastguard Worker * <p>Pairs of transliterators may be inverses of one another. For
155*0e209d39SAndroid Build Coastguard Worker * example, if transliterator <b>A</b> transliterates characters by
156*0e209d39SAndroid Build Coastguard Worker * incrementing their Unicode value (so "abc" -> "def"), and
157*0e209d39SAndroid Build Coastguard Worker * transliterator <b>B</b> decrements character values, then <b>A</b>
158*0e209d39SAndroid Build Coastguard Worker * is an inverse of <b>B</b> and vice versa. If we compose <b>A</b>
159*0e209d39SAndroid Build Coastguard Worker * with <b>B</b> in a compound transliterator, the result is the
160*0e209d39SAndroid Build Coastguard Worker * identity transliterator, that is, a transliterator that does not
161*0e209d39SAndroid Build Coastguard Worker * change its input text.
162*0e209d39SAndroid Build Coastguard Worker *
163*0e209d39SAndroid Build Coastguard Worker * The <code>Transliterator</code> method <code>getInverse()</code>
164*0e209d39SAndroid Build Coastguard Worker * returns a transliterator's inverse, if one exists, or
165*0e209d39SAndroid Build Coastguard Worker * <code>null</code> otherwise. However, the result of
166*0e209d39SAndroid Build Coastguard Worker * <code>getInverse()</code> usually will <em>not</em> be a true
167*0e209d39SAndroid Build Coastguard Worker * mathematical inverse. This is because true inverse transliterators
168*0e209d39SAndroid Build Coastguard Worker * are difficult to formulate. For example, consider two
169*0e209d39SAndroid Build Coastguard Worker * transliterators: <b>AB</b>, which transliterates the character 'A'
170*0e209d39SAndroid Build Coastguard Worker * to 'B', and <b>BA</b>, which transliterates 'B' to 'A'. It might
171*0e209d39SAndroid Build Coastguard Worker * seem that these are exact inverses, since
172*0e209d39SAndroid Build Coastguard Worker *
173*0e209d39SAndroid Build Coastguard Worker * \htmlonly<blockquote>\endhtmlonly"A" x <b>AB</b> -> "B"<br>
174*0e209d39SAndroid Build Coastguard Worker * "B" x <b>BA</b> -> "A"\htmlonly</blockquote>\endhtmlonly
175*0e209d39SAndroid Build Coastguard Worker *
176*0e209d39SAndroid Build Coastguard Worker * where 'x' represents transliteration. However,
177*0e209d39SAndroid Build Coastguard Worker *
178*0e209d39SAndroid Build Coastguard Worker * \htmlonly<blockquote>\endhtmlonly"ABCD" x <b>AB</b> -> "BBCD"<br>
179*0e209d39SAndroid Build Coastguard Worker * "BBCD" x <b>BA</b> -> "AACD"\htmlonly</blockquote>\endhtmlonly
180*0e209d39SAndroid Build Coastguard Worker *
181*0e209d39SAndroid Build Coastguard Worker * so <b>AB</b> composed with <b>BA</b> is not the
182*0e209d39SAndroid Build Coastguard Worker * identity. Nonetheless, <b>BA</b> may be usefully considered to be
183*0e209d39SAndroid Build Coastguard Worker * <b>AB</b>'s inverse, and it is on this basis that
184*0e209d39SAndroid Build Coastguard Worker * <b>AB</b><code>.getInverse()</code> could legitimately return
185*0e209d39SAndroid Build Coastguard Worker * <b>BA</b>.
186*0e209d39SAndroid Build Coastguard Worker *
187*0e209d39SAndroid Build Coastguard Worker * <p><b>IDs and display names</b>
188*0e209d39SAndroid Build Coastguard Worker *
189*0e209d39SAndroid Build Coastguard Worker * <p>A transliterator is designated by a short identifier string or
190*0e209d39SAndroid Build Coastguard Worker * <em>ID</em>. IDs follow the format <em>source-destination</em>,
191*0e209d39SAndroid Build Coastguard Worker * where <em>source</em> describes the entity being replaced, and
192*0e209d39SAndroid Build Coastguard Worker * <em>destination</em> describes the entity replacing
193*0e209d39SAndroid Build Coastguard Worker * <em>source</em>. The entities may be the names of scripts,
194*0e209d39SAndroid Build Coastguard Worker * particular sequences of characters, or whatever else it is that the
195*0e209d39SAndroid Build Coastguard Worker * transliterator converts to or from. For example, a transliterator
196*0e209d39SAndroid Build Coastguard Worker * from Russian to Latin might be named "Russian-Latin". A
197*0e209d39SAndroid Build Coastguard Worker * transliterator from keyboard escape sequences to Latin-1 characters
198*0e209d39SAndroid Build Coastguard Worker * might be named "KeyboardEscape-Latin1". By convention, system
199*0e209d39SAndroid Build Coastguard Worker * entity names are in English, with the initial letters of words
200*0e209d39SAndroid Build Coastguard Worker * capitalized; user entity names may follow any format so long as
201*0e209d39SAndroid Build Coastguard Worker * they do not contain dashes.
202*0e209d39SAndroid Build Coastguard Worker *
203*0e209d39SAndroid Build Coastguard Worker * <p>In addition to programmatic IDs, transliterator objects have
204*0e209d39SAndroid Build Coastguard Worker * display names for presentation in user interfaces, returned by
205*0e209d39SAndroid Build Coastguard Worker * {@link #getDisplayName }.
206*0e209d39SAndroid Build Coastguard Worker *
207*0e209d39SAndroid Build Coastguard Worker * <p><b>Factory methods and registration</b>
208*0e209d39SAndroid Build Coastguard Worker *
209*0e209d39SAndroid Build Coastguard Worker * <p>In general, client code should use the factory method
210*0e209d39SAndroid Build Coastguard Worker * {@link #createInstance } to obtain an instance of a
211*0e209d39SAndroid Build Coastguard Worker * transliterator given its ID. Valid IDs may be enumerated using
212*0e209d39SAndroid Build Coastguard Worker * <code>getAvailableIDs()</code>. Since transliterators are mutable,
213*0e209d39SAndroid Build Coastguard Worker * multiple calls to {@link #createInstance } with the same ID will
214*0e209d39SAndroid Build Coastguard Worker * return distinct objects.
215*0e209d39SAndroid Build Coastguard Worker *
216*0e209d39SAndroid Build Coastguard Worker * <p>In addition to the system transliterators registered at startup,
217*0e209d39SAndroid Build Coastguard Worker * user transliterators may be registered by calling
218*0e209d39SAndroid Build Coastguard Worker * <code>registerInstance()</code> at run time. A registered instance
219*0e209d39SAndroid Build Coastguard Worker * acts a template; future calls to {@link #createInstance } with the ID
220*0e209d39SAndroid Build Coastguard Worker * of the registered object return clones of that object. Thus any
221*0e209d39SAndroid Build Coastguard Worker * object passed to <tt>registerInstance()</tt> must implement
222*0e209d39SAndroid Build Coastguard Worker * <tt>clone()</tt> properly. To register a transliterator subclass
223*0e209d39SAndroid Build Coastguard Worker * without instantiating it (until it is needed), users may call
224*0e209d39SAndroid Build Coastguard Worker * {@link #registerFactory }. In this case, the objects are
225*0e209d39SAndroid Build Coastguard Worker * instantiated by invoking the zero-argument public constructor of
226*0e209d39SAndroid Build Coastguard Worker * the class.
227*0e209d39SAndroid Build Coastguard Worker *
228*0e209d39SAndroid Build Coastguard Worker * <p><b>Subclassing</b>
229*0e209d39SAndroid Build Coastguard Worker *
230*0e209d39SAndroid Build Coastguard Worker * Subclasses must implement the abstract method
231*0e209d39SAndroid Build Coastguard Worker * <code>handleTransliterate()</code>. <p>Subclasses should override
232*0e209d39SAndroid Build Coastguard Worker * the <code>transliterate()</code> method taking a
233*0e209d39SAndroid Build Coastguard Worker * <code>Replaceable</code> and the <code>transliterate()</code>
234*0e209d39SAndroid Build Coastguard Worker * method taking a <code>String</code> and <code>StringBuffer</code>
235*0e209d39SAndroid Build Coastguard Worker * if the performance of these methods can be improved over the
236*0e209d39SAndroid Build Coastguard Worker * performance obtained by the default implementations in this class.
237*0e209d39SAndroid Build Coastguard Worker *
238*0e209d39SAndroid Build Coastguard Worker * <p><b>Rule syntax</b>
239*0e209d39SAndroid Build Coastguard Worker *
240*0e209d39SAndroid Build Coastguard Worker * <p>A set of rules determines how to perform translations.
241*0e209d39SAndroid Build Coastguard Worker * Rules within a rule set are separated by semicolons (';').
242*0e209d39SAndroid Build Coastguard Worker * To include a literal semicolon, prefix it with a backslash ('\').
243*0e209d39SAndroid Build Coastguard Worker * Unicode Pattern_White_Space is ignored.
244*0e209d39SAndroid Build Coastguard Worker * If the first non-blank character on a line is '#',
245*0e209d39SAndroid Build Coastguard Worker * the entire line is ignored as a comment.
246*0e209d39SAndroid Build Coastguard Worker *
247*0e209d39SAndroid Build Coastguard Worker * <p>Each set of rules consists of two groups, one forward, and one
248*0e209d39SAndroid Build Coastguard Worker * reverse. This is a convention that is not enforced; rules for one
249*0e209d39SAndroid Build Coastguard Worker * direction may be omitted, with the result that translations in
250*0e209d39SAndroid Build Coastguard Worker * that direction will not modify the source text. In addition,
251*0e209d39SAndroid Build Coastguard Worker * bidirectional forward-reverse rules may be specified for
252*0e209d39SAndroid Build Coastguard Worker * symmetrical transformations.
253*0e209d39SAndroid Build Coastguard Worker *
254*0e209d39SAndroid Build Coastguard Worker * <p>Note: Another description of the Transliterator rule syntax is available in
255*0e209d39SAndroid Build Coastguard Worker * <a href="https://www.unicode.org/reports/tr35/tr35-general.html#Transform_Rules_Syntax">section
256*0e209d39SAndroid Build Coastguard Worker * Transform Rules Syntax of UTS #35: Unicode LDML</a>.
257*0e209d39SAndroid Build Coastguard Worker * The rules are shown there using arrow symbols ← and → and ↔.
258*0e209d39SAndroid Build Coastguard Worker * ICU supports both those and the equivalent ASCII symbols < and > and <>.
259*0e209d39SAndroid Build Coastguard Worker *
260*0e209d39SAndroid Build Coastguard Worker * <p>Rule statements take one of the following forms:
261*0e209d39SAndroid Build Coastguard Worker *
262*0e209d39SAndroid Build Coastguard Worker * <dl>
263*0e209d39SAndroid Build Coastguard Worker * <dt><code>$alefmadda=\\u0622;</code></dt>
264*0e209d39SAndroid Build Coastguard Worker * <dd><strong>Variable definition.</strong> The name on the
265*0e209d39SAndroid Build Coastguard Worker * left is assigned the text on the right. In this example,
266*0e209d39SAndroid Build Coastguard Worker * after this statement, instances of the left hand name,
267*0e209d39SAndroid Build Coastguard Worker * "<code>$alefmadda</code>", will be replaced by
268*0e209d39SAndroid Build Coastguard Worker * the Unicode character U+0622. Variable names must begin
269*0e209d39SAndroid Build Coastguard Worker * with a letter and consist only of letters, digits, and
270*0e209d39SAndroid Build Coastguard Worker * underscores. Case is significant. Duplicate names cause
271*0e209d39SAndroid Build Coastguard Worker * an exception to be thrown, that is, variables cannot be
272*0e209d39SAndroid Build Coastguard Worker * redefined. The right hand side may contain well-formed
273*0e209d39SAndroid Build Coastguard Worker * text of any length, including no text at all ("<code>$empty=;</code>").
274*0e209d39SAndroid Build Coastguard Worker * The right hand side may contain embedded <code>UnicodeSet</code>
275*0e209d39SAndroid Build Coastguard Worker * patterns, for example, "<code>$softvowel=[eiyEIY]</code>".</dd>
276*0e209d39SAndroid Build Coastguard Worker * <dt><code>ai>$alefmadda;</code></dt>
277*0e209d39SAndroid Build Coastguard Worker * <dd><strong>Forward translation rule.</strong> This rule
278*0e209d39SAndroid Build Coastguard Worker * states that the string on the left will be changed to the
279*0e209d39SAndroid Build Coastguard Worker * string on the right when performing forward
280*0e209d39SAndroid Build Coastguard Worker * transliteration.</dd>
281*0e209d39SAndroid Build Coastguard Worker * <dt><code>ai<$alefmadda;</code></dt>
282*0e209d39SAndroid Build Coastguard Worker * <dd><strong>Reverse translation rule.</strong> This rule
283*0e209d39SAndroid Build Coastguard Worker * states that the string on the right will be changed to
284*0e209d39SAndroid Build Coastguard Worker * the string on the left when performing reverse
285*0e209d39SAndroid Build Coastguard Worker * transliteration.</dd>
286*0e209d39SAndroid Build Coastguard Worker * </dl>
287*0e209d39SAndroid Build Coastguard Worker *
288*0e209d39SAndroid Build Coastguard Worker * <dl>
289*0e209d39SAndroid Build Coastguard Worker * <dt><code>ai<>$alefmadda;</code></dt>
290*0e209d39SAndroid Build Coastguard Worker * <dd><strong>Bidirectional translation rule.</strong> This
291*0e209d39SAndroid Build Coastguard Worker * rule states that the string on the right will be changed
292*0e209d39SAndroid Build Coastguard Worker * to the string on the left when performing forward
293*0e209d39SAndroid Build Coastguard Worker * transliteration, and vice versa when performing reverse
294*0e209d39SAndroid Build Coastguard Worker * transliteration.</dd>
295*0e209d39SAndroid Build Coastguard Worker * </dl>
296*0e209d39SAndroid Build Coastguard Worker *
297*0e209d39SAndroid Build Coastguard Worker * <p>Translation rules consist of a <em>match pattern</em> and an <em>output
298*0e209d39SAndroid Build Coastguard Worker * string</em>. The match pattern consists of literal characters,
299*0e209d39SAndroid Build Coastguard Worker * optionally preceded by context, and optionally followed by
300*0e209d39SAndroid Build Coastguard Worker * context. Context characters, like literal pattern characters,
301*0e209d39SAndroid Build Coastguard Worker * must be matched in the text being transliterated. However, unlike
302*0e209d39SAndroid Build Coastguard Worker * literal pattern characters, they are not replaced by the output
303*0e209d39SAndroid Build Coastguard Worker * text. For example, the pattern "<code>abc{def}</code>"
304*0e209d39SAndroid Build Coastguard Worker * indicates the characters "<code>def</code>" must be
305*0e209d39SAndroid Build Coastguard Worker * preceded by "<code>abc</code>" for a successful match.
306*0e209d39SAndroid Build Coastguard Worker * If there is a successful match, "<code>def</code>" will
307*0e209d39SAndroid Build Coastguard Worker * be replaced, but not "<code>abc</code>". The final '<code>}</code>'
308*0e209d39SAndroid Build Coastguard Worker * is optional, so "<code>abc{def</code>" is equivalent to
309*0e209d39SAndroid Build Coastguard Worker * "<code>abc{def}</code>". Another example is "<code>{123}456</code>"
310*0e209d39SAndroid Build Coastguard Worker * (or "<code>123}456</code>") in which the literal
311*0e209d39SAndroid Build Coastguard Worker * pattern "<code>123</code>" must be followed by "<code>456</code>".
312*0e209d39SAndroid Build Coastguard Worker *
313*0e209d39SAndroid Build Coastguard Worker * <p>The output string of a forward or reverse rule consists of
314*0e209d39SAndroid Build Coastguard Worker * characters to replace the literal pattern characters. If the
315*0e209d39SAndroid Build Coastguard Worker * output string contains the character '<code>|</code>', this is
316*0e209d39SAndroid Build Coastguard Worker * taken to indicate the location of the <em>cursor</em> after
317*0e209d39SAndroid Build Coastguard Worker * replacement. The cursor is the point in the text at which the
318*0e209d39SAndroid Build Coastguard Worker * next replacement, if any, will be applied. The cursor is usually
319*0e209d39SAndroid Build Coastguard Worker * placed within the replacement text; however, it can actually be
320*0e209d39SAndroid Build Coastguard Worker * placed into the preceding or following context by using the
321*0e209d39SAndroid Build Coastguard Worker * special character '@'. Examples:
322*0e209d39SAndroid Build Coastguard Worker *
323*0e209d39SAndroid Build Coastguard Worker * <pre>
324*0e209d39SAndroid Build Coastguard Worker * a {foo} z > | @ bar; # foo -> bar, move cursor before a
325*0e209d39SAndroid Build Coastguard Worker * {foo} xyz > bar @@|; # foo -> bar, cursor between y and z
326*0e209d39SAndroid Build Coastguard Worker * </pre>
327*0e209d39SAndroid Build Coastguard Worker *
328*0e209d39SAndroid Build Coastguard Worker * <p><b>UnicodeSet</b>
329*0e209d39SAndroid Build Coastguard Worker *
330*0e209d39SAndroid Build Coastguard Worker * <p><code>UnicodeSet</code> patterns may appear anywhere that
331*0e209d39SAndroid Build Coastguard Worker * makes sense. They may appear in variable definitions.
332*0e209d39SAndroid Build Coastguard Worker * Contrariwise, <code>UnicodeSet</code> patterns may themselves
333*0e209d39SAndroid Build Coastguard Worker * contain variable references, such as "<code>$a=[a-z];$not_a=[^$a]</code>",
334*0e209d39SAndroid Build Coastguard Worker * or "<code>$range=a-z;$ll=[$range]</code>".
335*0e209d39SAndroid Build Coastguard Worker *
336*0e209d39SAndroid Build Coastguard Worker * <p><code>UnicodeSet</code> patterns may also be embedded directly
337*0e209d39SAndroid Build Coastguard Worker * into rule strings. Thus, the following two rules are equivalent:
338*0e209d39SAndroid Build Coastguard Worker *
339*0e209d39SAndroid Build Coastguard Worker * <pre>
340*0e209d39SAndroid Build Coastguard Worker * $vowel=[aeiou]; $vowel>'*'; # One way to do this
341*0e209d39SAndroid Build Coastguard Worker * [aeiou]>'*'; # Another way
342*0e209d39SAndroid Build Coastguard Worker * </pre>
343*0e209d39SAndroid Build Coastguard Worker *
344*0e209d39SAndroid Build Coastguard Worker * <p>See {@link UnicodeSet} for more documentation and examples.
345*0e209d39SAndroid Build Coastguard Worker *
346*0e209d39SAndroid Build Coastguard Worker * <p><b>Segments</b>
347*0e209d39SAndroid Build Coastguard Worker *
348*0e209d39SAndroid Build Coastguard Worker * <p>Segments of the input string can be matched and copied to the
349*0e209d39SAndroid Build Coastguard Worker * output string. This makes certain sets of rules simpler and more
350*0e209d39SAndroid Build Coastguard Worker * general, and makes reordering possible. For example:
351*0e209d39SAndroid Build Coastguard Worker *
352*0e209d39SAndroid Build Coastguard Worker * <pre>
353*0e209d39SAndroid Build Coastguard Worker * ([a-z]) > $1 $1; # double lowercase letters
354*0e209d39SAndroid Build Coastguard Worker * ([:Lu:]) ([:Ll:]) > $2 $1; # reverse order of Lu-Ll pairs
355*0e209d39SAndroid Build Coastguard Worker * </pre>
356*0e209d39SAndroid Build Coastguard Worker *
357*0e209d39SAndroid Build Coastguard Worker * <p>The segment of the input string to be copied is delimited by
358*0e209d39SAndroid Build Coastguard Worker * "<code>(</code>" and "<code>)</code>". Up to
359*0e209d39SAndroid Build Coastguard Worker * nine segments may be defined. Segments may not overlap. In the
360*0e209d39SAndroid Build Coastguard Worker * output string, "<code>$1</code>" through "<code>$9</code>"
361*0e209d39SAndroid Build Coastguard Worker * represent the input string segments, in left-to-right order of
362*0e209d39SAndroid Build Coastguard Worker * definition.
363*0e209d39SAndroid Build Coastguard Worker *
364*0e209d39SAndroid Build Coastguard Worker * <p><b>Anchors</b>
365*0e209d39SAndroid Build Coastguard Worker *
366*0e209d39SAndroid Build Coastguard Worker * <p>Patterns can be anchored to the beginning or the end of the text. This is done with the
367*0e209d39SAndroid Build Coastguard Worker * special characters '<code>^</code>' and '<code>$</code>'. For example:
368*0e209d39SAndroid Build Coastguard Worker *
369*0e209d39SAndroid Build Coastguard Worker * <pre>
370*0e209d39SAndroid Build Coastguard Worker * ^ a > 'BEG_A'; # match 'a' at start of text
371*0e209d39SAndroid Build Coastguard Worker * a > 'A'; # match other instances of 'a'
372*0e209d39SAndroid Build Coastguard Worker * z $ > 'END_Z'; # match 'z' at end of text
373*0e209d39SAndroid Build Coastguard Worker * z > 'Z'; # match other instances of 'z'
374*0e209d39SAndroid Build Coastguard Worker * </pre>
375*0e209d39SAndroid Build Coastguard Worker *
376*0e209d39SAndroid Build Coastguard Worker * <p>It is also possible to match the beginning or the end of the text using a <code>UnicodeSet</code>.
377*0e209d39SAndroid Build Coastguard Worker * This is done by including a virtual anchor character '<code>$</code>' at the end of the
378*0e209d39SAndroid Build Coastguard Worker * set pattern. Although this is usually the match character for the end anchor, the set will
379*0e209d39SAndroid Build Coastguard Worker * match either the beginning or the end of the text, depending on its placement. For
380*0e209d39SAndroid Build Coastguard Worker * example:
381*0e209d39SAndroid Build Coastguard Worker *
382*0e209d39SAndroid Build Coastguard Worker * <pre>
383*0e209d39SAndroid Build Coastguard Worker * $x = [a-z$]; # match 'a' through 'z' OR anchor
384*0e209d39SAndroid Build Coastguard Worker * $x 1 > 2; # match '1' after a-z or at the start
385*0e209d39SAndroid Build Coastguard Worker * 3 $x > 4; # match '3' before a-z or at the end
386*0e209d39SAndroid Build Coastguard Worker * </pre>
387*0e209d39SAndroid Build Coastguard Worker *
388*0e209d39SAndroid Build Coastguard Worker * <p><b>Example</b>
389*0e209d39SAndroid Build Coastguard Worker *
390*0e209d39SAndroid Build Coastguard Worker * <p>The following example rules illustrate many of the features of
391*0e209d39SAndroid Build Coastguard Worker * the rule language.
392*0e209d39SAndroid Build Coastguard Worker *
393*0e209d39SAndroid Build Coastguard Worker * <table border="0" cellpadding="4">
394*0e209d39SAndroid Build Coastguard Worker * <tr>
395*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top;">Rule 1.</td>
396*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top; write-space: nowrap;"><code>abc{def}>x|y</code></td>
397*0e209d39SAndroid Build Coastguard Worker * </tr>
398*0e209d39SAndroid Build Coastguard Worker * <tr>
399*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top;">Rule 2.</td>
400*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top; write-space: nowrap;"><code>xyz>r</code></td>
401*0e209d39SAndroid Build Coastguard Worker * </tr>
402*0e209d39SAndroid Build Coastguard Worker * <tr>
403*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top;">Rule 3.</td>
404*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top; write-space: nowrap;"><code>yz>q</code></td>
405*0e209d39SAndroid Build Coastguard Worker * </tr>
406*0e209d39SAndroid Build Coastguard Worker * </table>
407*0e209d39SAndroid Build Coastguard Worker *
408*0e209d39SAndroid Build Coastguard Worker * <p>Applying these rules to the string "<code>adefabcdefz</code>"
409*0e209d39SAndroid Build Coastguard Worker * yields the following results:
410*0e209d39SAndroid Build Coastguard Worker *
411*0e209d39SAndroid Build Coastguard Worker * <table border="0" cellpadding="4">
412*0e209d39SAndroid Build Coastguard Worker * <tr>
413*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top; write-space: nowrap;"><code>|adefabcdefz</code></td>
414*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top;">Initial state, no rules match. Advance
415*0e209d39SAndroid Build Coastguard Worker * cursor.</td>
416*0e209d39SAndroid Build Coastguard Worker * </tr>
417*0e209d39SAndroid Build Coastguard Worker * <tr>
418*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top; write-space: nowrap;"><code>a|defabcdefz</code></td>
419*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top;">Still no match. Rule 1 does not match
420*0e209d39SAndroid Build Coastguard Worker * because the preceding context is not present.</td>
421*0e209d39SAndroid Build Coastguard Worker * </tr>
422*0e209d39SAndroid Build Coastguard Worker * <tr>
423*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top; write-space: nowrap;"><code>ad|efabcdefz</code></td>
424*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top;">Still no match. Keep advancing until
425*0e209d39SAndroid Build Coastguard Worker * there is a match...</td>
426*0e209d39SAndroid Build Coastguard Worker * </tr>
427*0e209d39SAndroid Build Coastguard Worker * <tr>
428*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top; write-space: nowrap;"><code>ade|fabcdefz</code></td>
429*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top;">...</td>
430*0e209d39SAndroid Build Coastguard Worker * </tr>
431*0e209d39SAndroid Build Coastguard Worker * <tr>
432*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top; write-space: nowrap;"><code>adef|abcdefz</code></td>
433*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top;">...</td>
434*0e209d39SAndroid Build Coastguard Worker * </tr>
435*0e209d39SAndroid Build Coastguard Worker * <tr>
436*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top; write-space: nowrap;"><code>adefa|bcdefz</code></td>
437*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top;">...</td>
438*0e209d39SAndroid Build Coastguard Worker * </tr>
439*0e209d39SAndroid Build Coastguard Worker * <tr>
440*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top; write-space: nowrap;"><code>adefab|cdefz</code></td>
441*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top;">...</td>
442*0e209d39SAndroid Build Coastguard Worker * </tr>
443*0e209d39SAndroid Build Coastguard Worker * <tr>
444*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top; write-space: nowrap;"><code>adefabc|defz</code></td>
445*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top;">Rule 1 matches; replace "<code>def</code>"
446*0e209d39SAndroid Build Coastguard Worker * with "<code>xy</code>" and back up the cursor
447*0e209d39SAndroid Build Coastguard Worker * to before the '<code>y</code>'.</td>
448*0e209d39SAndroid Build Coastguard Worker * </tr>
449*0e209d39SAndroid Build Coastguard Worker * <tr>
450*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top; write-space: nowrap;"><code>adefabcx|yz</code></td>
451*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top;">Although "<code>xyz</code>" is
452*0e209d39SAndroid Build Coastguard Worker * present, rule 2 does not match because the cursor is
453*0e209d39SAndroid Build Coastguard Worker * before the '<code>y</code>', not before the '<code>x</code>'.
454*0e209d39SAndroid Build Coastguard Worker * Rule 3 does match. Replace "<code>yz</code>"
455*0e209d39SAndroid Build Coastguard Worker * with "<code>q</code>".</td>
456*0e209d39SAndroid Build Coastguard Worker * </tr>
457*0e209d39SAndroid Build Coastguard Worker * <tr>
458*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top; write-space: nowrap;"><code>adefabcxq|</code></td>
459*0e209d39SAndroid Build Coastguard Worker * <td style="vertical-align: top;">The cursor is at the end;
460*0e209d39SAndroid Build Coastguard Worker * transliteration is complete.</td>
461*0e209d39SAndroid Build Coastguard Worker * </tr>
462*0e209d39SAndroid Build Coastguard Worker * </table>
463*0e209d39SAndroid Build Coastguard Worker *
464*0e209d39SAndroid Build Coastguard Worker * <p>The order of rules is significant. If multiple rules may match
465*0e209d39SAndroid Build Coastguard Worker * at some point, the first matching rule is applied.
466*0e209d39SAndroid Build Coastguard Worker *
467*0e209d39SAndroid Build Coastguard Worker * <p>Forward and reverse rules may have an empty output string.
468*0e209d39SAndroid Build Coastguard Worker * Otherwise, an empty left or right hand side of any statement is a
469*0e209d39SAndroid Build Coastguard Worker * syntax error.
470*0e209d39SAndroid Build Coastguard Worker *
471*0e209d39SAndroid Build Coastguard Worker * <p>Single quotes are used to quote any character other than a
472*0e209d39SAndroid Build Coastguard Worker * digit or letter. To specify a single quote itself, inside or
473*0e209d39SAndroid Build Coastguard Worker * outside of quotes, use two single quotes in a row. For example,
474*0e209d39SAndroid Build Coastguard Worker * the rule "<code>'>'>o''clock</code>" changes the
475*0e209d39SAndroid Build Coastguard Worker * string "<code>></code>" to the string "<code>o'clock</code>".
476*0e209d39SAndroid Build Coastguard Worker *
477*0e209d39SAndroid Build Coastguard Worker * <p><b>Notes</b>
478*0e209d39SAndroid Build Coastguard Worker *
479*0e209d39SAndroid Build Coastguard Worker * <p>While a Transliterator is being built from rules, it checks that
480*0e209d39SAndroid Build Coastguard Worker * the rules are added in proper order. For example, if the rule
481*0e209d39SAndroid Build Coastguard Worker * "a>x" is followed by the rule "ab>y",
482*0e209d39SAndroid Build Coastguard Worker * then the second rule will throw an exception. The reason is that
483*0e209d39SAndroid Build Coastguard Worker * the second rule can never be triggered, since the first rule
484*0e209d39SAndroid Build Coastguard Worker * always matches anything it matches. In other words, the first
485*0e209d39SAndroid Build Coastguard Worker * rule <em>masks</em> the second rule.
486*0e209d39SAndroid Build Coastguard Worker *
487*0e209d39SAndroid Build Coastguard Worker * @author Alan Liu
488*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
489*0e209d39SAndroid Build Coastguard Worker */
490*0e209d39SAndroid Build Coastguard Worker class U_I18N_API Transliterator : public UObject {
491*0e209d39SAndroid Build Coastguard Worker
492*0e209d39SAndroid Build Coastguard Worker private:
493*0e209d39SAndroid Build Coastguard Worker
494*0e209d39SAndroid Build Coastguard Worker /**
495*0e209d39SAndroid Build Coastguard Worker * Programmatic name, e.g., "Latin-Arabic".
496*0e209d39SAndroid Build Coastguard Worker */
497*0e209d39SAndroid Build Coastguard Worker UnicodeString ID;
498*0e209d39SAndroid Build Coastguard Worker
499*0e209d39SAndroid Build Coastguard Worker /**
500*0e209d39SAndroid Build Coastguard Worker * This transliterator's filter. Any character for which
501*0e209d39SAndroid Build Coastguard Worker * <tt>filter.contains()</tt> returns <tt>false</tt> will not be
502*0e209d39SAndroid Build Coastguard Worker * altered by this transliterator. If <tt>filter</tt> is
503*0e209d39SAndroid Build Coastguard Worker * <tt>null</tt> then no filtering is applied.
504*0e209d39SAndroid Build Coastguard Worker */
505*0e209d39SAndroid Build Coastguard Worker UnicodeFilter* filter;
506*0e209d39SAndroid Build Coastguard Worker
507*0e209d39SAndroid Build Coastguard Worker int32_t maximumContextLength;
508*0e209d39SAndroid Build Coastguard Worker
509*0e209d39SAndroid Build Coastguard Worker public:
510*0e209d39SAndroid Build Coastguard Worker
511*0e209d39SAndroid Build Coastguard Worker /**
512*0e209d39SAndroid Build Coastguard Worker * A context integer or pointer for a factory function, passed by
513*0e209d39SAndroid Build Coastguard Worker * value.
514*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4
515*0e209d39SAndroid Build Coastguard Worker */
516*0e209d39SAndroid Build Coastguard Worker union Token {
517*0e209d39SAndroid Build Coastguard Worker /**
518*0e209d39SAndroid Build Coastguard Worker * This token, interpreted as a 32-bit integer.
519*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4
520*0e209d39SAndroid Build Coastguard Worker */
521*0e209d39SAndroid Build Coastguard Worker int32_t integer;
522*0e209d39SAndroid Build Coastguard Worker /**
523*0e209d39SAndroid Build Coastguard Worker * This token, interpreted as a native pointer.
524*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4
525*0e209d39SAndroid Build Coastguard Worker */
526*0e209d39SAndroid Build Coastguard Worker void* pointer;
527*0e209d39SAndroid Build Coastguard Worker };
528*0e209d39SAndroid Build Coastguard Worker
529*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
530*0e209d39SAndroid Build Coastguard Worker /**
531*0e209d39SAndroid Build Coastguard Worker * Return a token containing an integer.
532*0e209d39SAndroid Build Coastguard Worker * @return a token containing an integer.
533*0e209d39SAndroid Build Coastguard Worker * @internal
534*0e209d39SAndroid Build Coastguard Worker */
535*0e209d39SAndroid Build Coastguard Worker inline static Token integerToken(int32_t);
536*0e209d39SAndroid Build Coastguard Worker
537*0e209d39SAndroid Build Coastguard Worker /**
538*0e209d39SAndroid Build Coastguard Worker * Return a token containing a pointer.
539*0e209d39SAndroid Build Coastguard Worker * @return a token containing a pointer.
540*0e209d39SAndroid Build Coastguard Worker * @internal
541*0e209d39SAndroid Build Coastguard Worker */
542*0e209d39SAndroid Build Coastguard Worker inline static Token pointerToken(void*);
543*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */
544*0e209d39SAndroid Build Coastguard Worker
545*0e209d39SAndroid Build Coastguard Worker /**
546*0e209d39SAndroid Build Coastguard Worker * A function that creates and returns a Transliterator. When
547*0e209d39SAndroid Build Coastguard Worker * invoked, it will be passed the ID string that is being
548*0e209d39SAndroid Build Coastguard Worker * instantiated, together with the context pointer that was passed
549*0e209d39SAndroid Build Coastguard Worker * in when the factory function was first registered. Many
550*0e209d39SAndroid Build Coastguard Worker * factory functions will ignore both parameters, however,
551*0e209d39SAndroid Build Coastguard Worker * functions that are registered to more than one ID may use the
552*0e209d39SAndroid Build Coastguard Worker * ID or the context parameter to parameterize the transliterator
553*0e209d39SAndroid Build Coastguard Worker * they create.
554*0e209d39SAndroid Build Coastguard Worker * @param ID the string identifier for this transliterator
555*0e209d39SAndroid Build Coastguard Worker * @param context a context pointer that will be stored and
556*0e209d39SAndroid Build Coastguard Worker * later passed to the factory function when an ID matching
557*0e209d39SAndroid Build Coastguard Worker * the registration ID is being instantiated with this factory.
558*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4
559*0e209d39SAndroid Build Coastguard Worker */
560*0e209d39SAndroid Build Coastguard Worker typedef Transliterator* (U_EXPORT2 *Factory)(const UnicodeString& ID, Token context);
561*0e209d39SAndroid Build Coastguard Worker
562*0e209d39SAndroid Build Coastguard Worker protected:
563*0e209d39SAndroid Build Coastguard Worker
564*0e209d39SAndroid Build Coastguard Worker /**
565*0e209d39SAndroid Build Coastguard Worker * Default constructor.
566*0e209d39SAndroid Build Coastguard Worker * @param ID the string identifier for this transliterator
567*0e209d39SAndroid Build Coastguard Worker * @param adoptedFilter the filter. Any character for which
568*0e209d39SAndroid Build Coastguard Worker * <tt>filter.contains()</tt> returns <tt>false</tt> will not be
569*0e209d39SAndroid Build Coastguard Worker * altered by this transliterator. If <tt>filter</tt> is
570*0e209d39SAndroid Build Coastguard Worker * <tt>null</tt> then no filtering is applied.
571*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4
572*0e209d39SAndroid Build Coastguard Worker */
573*0e209d39SAndroid Build Coastguard Worker Transliterator(const UnicodeString& ID, UnicodeFilter* adoptedFilter);
574*0e209d39SAndroid Build Coastguard Worker
575*0e209d39SAndroid Build Coastguard Worker /**
576*0e209d39SAndroid Build Coastguard Worker * Copy constructor.
577*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4
578*0e209d39SAndroid Build Coastguard Worker */
579*0e209d39SAndroid Build Coastguard Worker Transliterator(const Transliterator&);
580*0e209d39SAndroid Build Coastguard Worker
581*0e209d39SAndroid Build Coastguard Worker /**
582*0e209d39SAndroid Build Coastguard Worker * Assignment operator.
583*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4
584*0e209d39SAndroid Build Coastguard Worker */
585*0e209d39SAndroid Build Coastguard Worker Transliterator& operator=(const Transliterator&);
586*0e209d39SAndroid Build Coastguard Worker
587*0e209d39SAndroid Build Coastguard Worker /**
588*0e209d39SAndroid Build Coastguard Worker * Create a transliterator from a basic ID. This is an ID
589*0e209d39SAndroid Build Coastguard Worker * containing only the forward direction source, target, and
590*0e209d39SAndroid Build Coastguard Worker * variant.
591*0e209d39SAndroid Build Coastguard Worker * @param id a basic ID of the form S-T or S-T/V.
592*0e209d39SAndroid Build Coastguard Worker * @param canon canonical ID to assign to the object, or
593*0e209d39SAndroid Build Coastguard Worker * nullptr to leave the ID unchanged
594*0e209d39SAndroid Build Coastguard Worker * @return a newly created Transliterator or null if the ID is
595*0e209d39SAndroid Build Coastguard Worker * invalid.
596*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4
597*0e209d39SAndroid Build Coastguard Worker */
598*0e209d39SAndroid Build Coastguard Worker static Transliterator* createBasicInstance(const UnicodeString& id,
599*0e209d39SAndroid Build Coastguard Worker const UnicodeString* canon);
600*0e209d39SAndroid Build Coastguard Worker
601*0e209d39SAndroid Build Coastguard Worker friend class TransliteratorParser; // for parseID()
602*0e209d39SAndroid Build Coastguard Worker friend class TransliteratorIDParser; // for createBasicInstance()
603*0e209d39SAndroid Build Coastguard Worker friend class TransliteratorAlias; // for setID()
604*0e209d39SAndroid Build Coastguard Worker
605*0e209d39SAndroid Build Coastguard Worker public:
606*0e209d39SAndroid Build Coastguard Worker
607*0e209d39SAndroid Build Coastguard Worker /**
608*0e209d39SAndroid Build Coastguard Worker * Destructor.
609*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
610*0e209d39SAndroid Build Coastguard Worker */
611*0e209d39SAndroid Build Coastguard Worker virtual ~Transliterator();
612*0e209d39SAndroid Build Coastguard Worker
613*0e209d39SAndroid Build Coastguard Worker /**
614*0e209d39SAndroid Build Coastguard Worker * Implements Cloneable.
615*0e209d39SAndroid Build Coastguard Worker * All subclasses are encouraged to implement this method if it is
616*0e209d39SAndroid Build Coastguard Worker * possible and reasonable to do so. Subclasses that are to be
617*0e209d39SAndroid Build Coastguard Worker * registered with the system using <tt>registerInstance()</tt>
618*0e209d39SAndroid Build Coastguard Worker * are required to implement this method. If a subclass does not
619*0e209d39SAndroid Build Coastguard Worker * implement clone() properly and is registered with the system
620*0e209d39SAndroid Build Coastguard Worker * using registerInstance(), then the default clone() implementation
621*0e209d39SAndroid Build Coastguard Worker * will return null, and calls to createInstance() will fail.
622*0e209d39SAndroid Build Coastguard Worker *
623*0e209d39SAndroid Build Coastguard Worker * @return a copy of the object.
624*0e209d39SAndroid Build Coastguard Worker * @see #registerInstance
625*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
626*0e209d39SAndroid Build Coastguard Worker */
627*0e209d39SAndroid Build Coastguard Worker virtual Transliterator* clone() const;
628*0e209d39SAndroid Build Coastguard Worker
629*0e209d39SAndroid Build Coastguard Worker /**
630*0e209d39SAndroid Build Coastguard Worker * Transliterates a segment of a string, with optional filtering.
631*0e209d39SAndroid Build Coastguard Worker *
632*0e209d39SAndroid Build Coastguard Worker * @param text the string to be transliterated
633*0e209d39SAndroid Build Coastguard Worker * @param start the beginning index, inclusive; <code>0 <= start
634*0e209d39SAndroid Build Coastguard Worker * <= limit</code>.
635*0e209d39SAndroid Build Coastguard Worker * @param limit the ending index, exclusive; <code>start <= limit
636*0e209d39SAndroid Build Coastguard Worker * <= text.length()</code>.
637*0e209d39SAndroid Build Coastguard Worker * @return The new limit index. The text previously occupying <code>[start,
638*0e209d39SAndroid Build Coastguard Worker * limit)</code> has been transliterated, possibly to a string of a different
639*0e209d39SAndroid Build Coastguard Worker * length, at <code>[start, </code><em>new-limit</em><code>)</code>, where
640*0e209d39SAndroid Build Coastguard Worker * <em>new-limit</em> is the return value. If the input offsets are out of bounds,
641*0e209d39SAndroid Build Coastguard Worker * the returned value is -1 and the input string remains unchanged.
642*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
643*0e209d39SAndroid Build Coastguard Worker */
644*0e209d39SAndroid Build Coastguard Worker virtual int32_t transliterate(Replaceable& text,
645*0e209d39SAndroid Build Coastguard Worker int32_t start, int32_t limit) const;
646*0e209d39SAndroid Build Coastguard Worker
647*0e209d39SAndroid Build Coastguard Worker /**
648*0e209d39SAndroid Build Coastguard Worker * Transliterates an entire string in place. Convenience method.
649*0e209d39SAndroid Build Coastguard Worker * @param text the string to be transliterated
650*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
651*0e209d39SAndroid Build Coastguard Worker */
652*0e209d39SAndroid Build Coastguard Worker virtual void transliterate(Replaceable& text) const;
653*0e209d39SAndroid Build Coastguard Worker
654*0e209d39SAndroid Build Coastguard Worker /**
655*0e209d39SAndroid Build Coastguard Worker * Transliterates the portion of the text buffer that can be
656*0e209d39SAndroid Build Coastguard Worker * transliterated unambiguosly after new text has been inserted,
657*0e209d39SAndroid Build Coastguard Worker * typically as a result of a keyboard event. The new text in
658*0e209d39SAndroid Build Coastguard Worker * <code>insertion</code> will be inserted into <code>text</code>
659*0e209d39SAndroid Build Coastguard Worker * at <code>index.limit</code>, advancing
660*0e209d39SAndroid Build Coastguard Worker * <code>index.limit</code> by <code>insertion.length()</code>.
661*0e209d39SAndroid Build Coastguard Worker * Then the transliterator will try to transliterate characters of
662*0e209d39SAndroid Build Coastguard Worker * <code>text</code> between <code>index.cursor</code> and
663*0e209d39SAndroid Build Coastguard Worker * <code>index.limit</code>. Characters before
664*0e209d39SAndroid Build Coastguard Worker * <code>index.cursor</code> will not be changed.
665*0e209d39SAndroid Build Coastguard Worker *
666*0e209d39SAndroid Build Coastguard Worker * <p>Upon return, values in <code>index</code> will be updated.
667*0e209d39SAndroid Build Coastguard Worker * <code>index.start</code> will be advanced to the first
668*0e209d39SAndroid Build Coastguard Worker * character that future calls to this method will read.
669*0e209d39SAndroid Build Coastguard Worker * <code>index.cursor</code> and <code>index.limit</code> will
670*0e209d39SAndroid Build Coastguard Worker * be adjusted to delimit the range of text that future calls to
671*0e209d39SAndroid Build Coastguard Worker * this method may change.
672*0e209d39SAndroid Build Coastguard Worker *
673*0e209d39SAndroid Build Coastguard Worker * <p>Typical usage of this method begins with an initial call
674*0e209d39SAndroid Build Coastguard Worker * with <code>index.start</code> and <code>index.limit</code>
675*0e209d39SAndroid Build Coastguard Worker * set to indicate the portion of <code>text</code> to be
676*0e209d39SAndroid Build Coastguard Worker * transliterated, and <code>index.cursor == index.start</code>.
677*0e209d39SAndroid Build Coastguard Worker * Thereafter, <code>index</code> can be used without
678*0e209d39SAndroid Build Coastguard Worker * modification in future calls, provided that all changes to
679*0e209d39SAndroid Build Coastguard Worker * <code>text</code> are made via this method.
680*0e209d39SAndroid Build Coastguard Worker *
681*0e209d39SAndroid Build Coastguard Worker * <p>This method assumes that future calls may be made that will
682*0e209d39SAndroid Build Coastguard Worker * insert new text into the buffer. As a result, it only performs
683*0e209d39SAndroid Build Coastguard Worker * unambiguous transliterations. After the last call to this
684*0e209d39SAndroid Build Coastguard Worker * method, there may be untransliterated text that is waiting for
685*0e209d39SAndroid Build Coastguard Worker * more input to resolve an ambiguity. In order to perform these
686*0e209d39SAndroid Build Coastguard Worker * pending transliterations, clients should call
687*0e209d39SAndroid Build Coastguard Worker * {@link #finishTransliteration } after the last call to this
688*0e209d39SAndroid Build Coastguard Worker * method has been made.
689*0e209d39SAndroid Build Coastguard Worker *
690*0e209d39SAndroid Build Coastguard Worker * @param text the buffer holding transliterated and untransliterated text
691*0e209d39SAndroid Build Coastguard Worker * @param index an array of three integers.
692*0e209d39SAndroid Build Coastguard Worker *
693*0e209d39SAndroid Build Coastguard Worker * <ul><li><code>index.start</code>: the beginning index,
694*0e209d39SAndroid Build Coastguard Worker * inclusive; <code>0 <= index.start <= index.limit</code>.
695*0e209d39SAndroid Build Coastguard Worker *
696*0e209d39SAndroid Build Coastguard Worker * <li><code>index.limit</code>: the ending index, exclusive;
697*0e209d39SAndroid Build Coastguard Worker * <code>index.start <= index.limit <= text.length()</code>.
698*0e209d39SAndroid Build Coastguard Worker * <code>insertion</code> is inserted at
699*0e209d39SAndroid Build Coastguard Worker * <code>index.limit</code>.
700*0e209d39SAndroid Build Coastguard Worker *
701*0e209d39SAndroid Build Coastguard Worker * <li><code>index.cursor</code>: the next character to be
702*0e209d39SAndroid Build Coastguard Worker * considered for transliteration; <code>index.start <=
703*0e209d39SAndroid Build Coastguard Worker * index.cursor <= index.limit</code>. Characters before
704*0e209d39SAndroid Build Coastguard Worker * <code>index.cursor</code> will not be changed by future calls
705*0e209d39SAndroid Build Coastguard Worker * to this method.</ul>
706*0e209d39SAndroid Build Coastguard Worker *
707*0e209d39SAndroid Build Coastguard Worker * @param insertion text to be inserted and possibly
708*0e209d39SAndroid Build Coastguard Worker * transliterated into the translation buffer at
709*0e209d39SAndroid Build Coastguard Worker * <code>index.limit</code>. If <code>null</code> then no text
710*0e209d39SAndroid Build Coastguard Worker * is inserted.
711*0e209d39SAndroid Build Coastguard Worker * @param status Output param to filled in with a success or an error.
712*0e209d39SAndroid Build Coastguard Worker * @see #handleTransliterate
713*0e209d39SAndroid Build Coastguard Worker * @exception IllegalArgumentException if <code>index</code>
714*0e209d39SAndroid Build Coastguard Worker * is invalid
715*0e209d39SAndroid Build Coastguard Worker * @see UTransPosition
716*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
717*0e209d39SAndroid Build Coastguard Worker */
718*0e209d39SAndroid Build Coastguard Worker virtual void transliterate(Replaceable& text, UTransPosition& index,
719*0e209d39SAndroid Build Coastguard Worker const UnicodeString& insertion,
720*0e209d39SAndroid Build Coastguard Worker UErrorCode& status) const;
721*0e209d39SAndroid Build Coastguard Worker
722*0e209d39SAndroid Build Coastguard Worker /**
723*0e209d39SAndroid Build Coastguard Worker * Transliterates the portion of the text buffer that can be
724*0e209d39SAndroid Build Coastguard Worker * transliterated unambiguosly after a new character has been
725*0e209d39SAndroid Build Coastguard Worker * inserted, typically as a result of a keyboard event. This is a
726*0e209d39SAndroid Build Coastguard Worker * convenience method.
727*0e209d39SAndroid Build Coastguard Worker * @param text the buffer holding transliterated and
728*0e209d39SAndroid Build Coastguard Worker * untransliterated text
729*0e209d39SAndroid Build Coastguard Worker * @param index an array of three integers.
730*0e209d39SAndroid Build Coastguard Worker * @param insertion text to be inserted and possibly
731*0e209d39SAndroid Build Coastguard Worker * transliterated into the translation buffer at
732*0e209d39SAndroid Build Coastguard Worker * <code>index.limit</code>.
733*0e209d39SAndroid Build Coastguard Worker * @param status Output param to filled in with a success or an error.
734*0e209d39SAndroid Build Coastguard Worker * @see #transliterate(Replaceable&, UTransPosition&, const UnicodeString&, UErrorCode&) const
735*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
736*0e209d39SAndroid Build Coastguard Worker */
737*0e209d39SAndroid Build Coastguard Worker virtual void transliterate(Replaceable& text, UTransPosition& index,
738*0e209d39SAndroid Build Coastguard Worker UChar32 insertion,
739*0e209d39SAndroid Build Coastguard Worker UErrorCode& status) const;
740*0e209d39SAndroid Build Coastguard Worker
741*0e209d39SAndroid Build Coastguard Worker /**
742*0e209d39SAndroid Build Coastguard Worker * Transliterates the portion of the text buffer that can be
743*0e209d39SAndroid Build Coastguard Worker * transliterated unambiguosly. This is a convenience method; see
744*0e209d39SAndroid Build Coastguard Worker * {@link #transliterate(Replaceable&, UTransPosition&, const UnicodeString&, UErrorCode&) const }
745*0e209d39SAndroid Build Coastguard Worker * for details.
746*0e209d39SAndroid Build Coastguard Worker * @param text the buffer holding transliterated and
747*0e209d39SAndroid Build Coastguard Worker * untransliterated text
748*0e209d39SAndroid Build Coastguard Worker * @param index an array of three integers.
749*0e209d39SAndroid Build Coastguard Worker * @param status Output param to filled in with a success or an error.
750*0e209d39SAndroid Build Coastguard Worker * @see #transliterate(Replaceable&, UTransPosition&, const UnicodeString&, UErrorCode &) const
751*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
752*0e209d39SAndroid Build Coastguard Worker */
753*0e209d39SAndroid Build Coastguard Worker virtual void transliterate(Replaceable& text, UTransPosition& index,
754*0e209d39SAndroid Build Coastguard Worker UErrorCode& status) const;
755*0e209d39SAndroid Build Coastguard Worker
756*0e209d39SAndroid Build Coastguard Worker /**
757*0e209d39SAndroid Build Coastguard Worker * Finishes any pending transliterations that were waiting for
758*0e209d39SAndroid Build Coastguard Worker * more characters. Clients should call this method as the last
759*0e209d39SAndroid Build Coastguard Worker * call after a sequence of one or more calls to
760*0e209d39SAndroid Build Coastguard Worker * <code>transliterate()</code>.
761*0e209d39SAndroid Build Coastguard Worker * @param text the buffer holding transliterated and
762*0e209d39SAndroid Build Coastguard Worker * untransliterated text.
763*0e209d39SAndroid Build Coastguard Worker * @param index the array of indices previously passed to {@link #transliterate }
764*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
765*0e209d39SAndroid Build Coastguard Worker */
766*0e209d39SAndroid Build Coastguard Worker virtual void finishTransliteration(Replaceable& text,
767*0e209d39SAndroid Build Coastguard Worker UTransPosition& index) const;
768*0e209d39SAndroid Build Coastguard Worker
769*0e209d39SAndroid Build Coastguard Worker private:
770*0e209d39SAndroid Build Coastguard Worker
771*0e209d39SAndroid Build Coastguard Worker /**
772*0e209d39SAndroid Build Coastguard Worker * This internal method does incremental transliteration. If the
773*0e209d39SAndroid Build Coastguard Worker * 'insertion' is non-null then we append it to 'text' before
774*0e209d39SAndroid Build Coastguard Worker * proceeding. This method calls through to the pure virtual
775*0e209d39SAndroid Build Coastguard Worker * framework method handleTransliterate() to do the actual
776*0e209d39SAndroid Build Coastguard Worker * work.
777*0e209d39SAndroid Build Coastguard Worker * @param text the buffer holding transliterated and
778*0e209d39SAndroid Build Coastguard Worker * untransliterated text
779*0e209d39SAndroid Build Coastguard Worker * @param index an array of three integers. See {@link
780*0e209d39SAndroid Build Coastguard Worker * #transliterate(Replaceable, int[], String)}.
781*0e209d39SAndroid Build Coastguard Worker * @param insertion text to be inserted and possibly
782*0e209d39SAndroid Build Coastguard Worker * transliterated into the translation buffer at
783*0e209d39SAndroid Build Coastguard Worker * <code>index.limit</code>.
784*0e209d39SAndroid Build Coastguard Worker * @param status Output param to filled in with a success or an error.
785*0e209d39SAndroid Build Coastguard Worker */
786*0e209d39SAndroid Build Coastguard Worker void _transliterate(Replaceable& text,
787*0e209d39SAndroid Build Coastguard Worker UTransPosition& index,
788*0e209d39SAndroid Build Coastguard Worker const UnicodeString* insertion,
789*0e209d39SAndroid Build Coastguard Worker UErrorCode &status) const;
790*0e209d39SAndroid Build Coastguard Worker
791*0e209d39SAndroid Build Coastguard Worker protected:
792*0e209d39SAndroid Build Coastguard Worker
793*0e209d39SAndroid Build Coastguard Worker /**
794*0e209d39SAndroid Build Coastguard Worker * Abstract method that concrete subclasses define to implement
795*0e209d39SAndroid Build Coastguard Worker * their transliteration algorithm. This method handles both
796*0e209d39SAndroid Build Coastguard Worker * incremental and non-incremental transliteration. Let
797*0e209d39SAndroid Build Coastguard Worker * <code>originalStart</code> refer to the value of
798*0e209d39SAndroid Build Coastguard Worker * <code>pos.start</code> upon entry.
799*0e209d39SAndroid Build Coastguard Worker *
800*0e209d39SAndroid Build Coastguard Worker * <ul>
801*0e209d39SAndroid Build Coastguard Worker * <li>If <code>incremental</code> is false, then this method
802*0e209d39SAndroid Build Coastguard Worker * should transliterate all characters between
803*0e209d39SAndroid Build Coastguard Worker * <code>pos.start</code> and <code>pos.limit</code>. Upon return
804*0e209d39SAndroid Build Coastguard Worker * <code>pos.start</code> must == <code> pos.limit</code>.</li>
805*0e209d39SAndroid Build Coastguard Worker *
806*0e209d39SAndroid Build Coastguard Worker * <li>If <code>incremental</code> is true, then this method
807*0e209d39SAndroid Build Coastguard Worker * should transliterate all characters between
808*0e209d39SAndroid Build Coastguard Worker * <code>pos.start</code> and <code>pos.limit</code> that can be
809*0e209d39SAndroid Build Coastguard Worker * unambiguously transliterated, regardless of future insertions
810*0e209d39SAndroid Build Coastguard Worker * of text at <code>pos.limit</code>. Upon return,
811*0e209d39SAndroid Build Coastguard Worker * <code>pos.start</code> should be in the range
812*0e209d39SAndroid Build Coastguard Worker * [<code>originalStart</code>, <code>pos.limit</code>).
813*0e209d39SAndroid Build Coastguard Worker * <code>pos.start</code> should be positioned such that
814*0e209d39SAndroid Build Coastguard Worker * characters [<code>originalStart</code>, <code>
815*0e209d39SAndroid Build Coastguard Worker * pos.start</code>) will not be changed in the future by this
816*0e209d39SAndroid Build Coastguard Worker * transliterator and characters [<code>pos.start</code>,
817*0e209d39SAndroid Build Coastguard Worker * <code>pos.limit</code>) are unchanged.</li>
818*0e209d39SAndroid Build Coastguard Worker * </ul>
819*0e209d39SAndroid Build Coastguard Worker *
820*0e209d39SAndroid Build Coastguard Worker * <p>Implementations of this method should also obey the
821*0e209d39SAndroid Build Coastguard Worker * following invariants:</p>
822*0e209d39SAndroid Build Coastguard Worker *
823*0e209d39SAndroid Build Coastguard Worker * <ul>
824*0e209d39SAndroid Build Coastguard Worker * <li> <code>pos.limit</code> and <code>pos.contextLimit</code>
825*0e209d39SAndroid Build Coastguard Worker * should be updated to reflect changes in length of the text
826*0e209d39SAndroid Build Coastguard Worker * between <code>pos.start</code> and <code>pos.limit</code>. The
827*0e209d39SAndroid Build Coastguard Worker * difference <code> pos.contextLimit - pos.limit</code> should
828*0e209d39SAndroid Build Coastguard Worker * not change.</li>
829*0e209d39SAndroid Build Coastguard Worker *
830*0e209d39SAndroid Build Coastguard Worker * <li><code>pos.contextStart</code> should not change.</li>
831*0e209d39SAndroid Build Coastguard Worker *
832*0e209d39SAndroid Build Coastguard Worker * <li>Upon return, neither <code>pos.start</code> nor
833*0e209d39SAndroid Build Coastguard Worker * <code>pos.limit</code> should be less than
834*0e209d39SAndroid Build Coastguard Worker * <code>originalStart</code>.</li>
835*0e209d39SAndroid Build Coastguard Worker *
836*0e209d39SAndroid Build Coastguard Worker * <li>Text before <code>originalStart</code> and text after
837*0e209d39SAndroid Build Coastguard Worker * <code>pos.limit</code> should not change.</li>
838*0e209d39SAndroid Build Coastguard Worker *
839*0e209d39SAndroid Build Coastguard Worker * <li>Text before <code>pos.contextStart</code> and text after
840*0e209d39SAndroid Build Coastguard Worker * <code> pos.contextLimit</code> should be ignored.</li>
841*0e209d39SAndroid Build Coastguard Worker * </ul>
842*0e209d39SAndroid Build Coastguard Worker *
843*0e209d39SAndroid Build Coastguard Worker * <p>Subclasses may safely assume that all characters in
844*0e209d39SAndroid Build Coastguard Worker * [<code>pos.start</code>, <code>pos.limit</code>) are filtered.
845*0e209d39SAndroid Build Coastguard Worker * In other words, the filter has already been applied by the time
846*0e209d39SAndroid Build Coastguard Worker * this method is called. See
847*0e209d39SAndroid Build Coastguard Worker * <code>filteredTransliterate()</code>.
848*0e209d39SAndroid Build Coastguard Worker *
849*0e209d39SAndroid Build Coastguard Worker * <p>This method is <b>not</b> for public consumption. Calling
850*0e209d39SAndroid Build Coastguard Worker * this method directly will transliterate
851*0e209d39SAndroid Build Coastguard Worker * [<code>pos.start</code>, <code>pos.limit</code>) without
852*0e209d39SAndroid Build Coastguard Worker * applying the filter. End user code should call <code>
853*0e209d39SAndroid Build Coastguard Worker * transliterate()</code> instead of this method. Subclass code
854*0e209d39SAndroid Build Coastguard Worker * and wrapping transliterators should call
855*0e209d39SAndroid Build Coastguard Worker * <code>filteredTransliterate()</code> instead of this method.<p>
856*0e209d39SAndroid Build Coastguard Worker *
857*0e209d39SAndroid Build Coastguard Worker * @param text the buffer holding transliterated and
858*0e209d39SAndroid Build Coastguard Worker * untransliterated text
859*0e209d39SAndroid Build Coastguard Worker *
860*0e209d39SAndroid Build Coastguard Worker * @param pos the indices indicating the start, limit, context
861*0e209d39SAndroid Build Coastguard Worker * start, and context limit of the text.
862*0e209d39SAndroid Build Coastguard Worker *
863*0e209d39SAndroid Build Coastguard Worker * @param incremental if true, assume more text may be inserted at
864*0e209d39SAndroid Build Coastguard Worker * <code>pos.limit</code> and act accordingly. Otherwise,
865*0e209d39SAndroid Build Coastguard Worker * transliterate all text between <code>pos.start</code> and
866*0e209d39SAndroid Build Coastguard Worker * <code>pos.limit</code> and move <code>pos.start</code> up to
867*0e209d39SAndroid Build Coastguard Worker * <code>pos.limit</code>.
868*0e209d39SAndroid Build Coastguard Worker *
869*0e209d39SAndroid Build Coastguard Worker * @see #transliterate
870*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4
871*0e209d39SAndroid Build Coastguard Worker */
872*0e209d39SAndroid Build Coastguard Worker virtual void handleTransliterate(Replaceable& text,
873*0e209d39SAndroid Build Coastguard Worker UTransPosition& pos,
874*0e209d39SAndroid Build Coastguard Worker UBool incremental) const = 0;
875*0e209d39SAndroid Build Coastguard Worker
876*0e209d39SAndroid Build Coastguard Worker public:
877*0e209d39SAndroid Build Coastguard Worker /**
878*0e209d39SAndroid Build Coastguard Worker * Transliterate a substring of text, as specified by index, taking filters
879*0e209d39SAndroid Build Coastguard Worker * into account. This method is for subclasses that need to delegate to
880*0e209d39SAndroid Build Coastguard Worker * another transliterator.
881*0e209d39SAndroid Build Coastguard Worker * @param text the text to be transliterated
882*0e209d39SAndroid Build Coastguard Worker * @param index the position indices
883*0e209d39SAndroid Build Coastguard Worker * @param incremental if true, then assume more characters may be inserted
884*0e209d39SAndroid Build Coastguard Worker * at index.limit, and postpone processing to accommodate future incoming
885*0e209d39SAndroid Build Coastguard Worker * characters
886*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4
887*0e209d39SAndroid Build Coastguard Worker */
888*0e209d39SAndroid Build Coastguard Worker virtual void filteredTransliterate(Replaceable& text,
889*0e209d39SAndroid Build Coastguard Worker UTransPosition& index,
890*0e209d39SAndroid Build Coastguard Worker UBool incremental) const;
891*0e209d39SAndroid Build Coastguard Worker
892*0e209d39SAndroid Build Coastguard Worker private:
893*0e209d39SAndroid Build Coastguard Worker
894*0e209d39SAndroid Build Coastguard Worker /**
895*0e209d39SAndroid Build Coastguard Worker * Top-level transliteration method, handling filtering, incremental and
896*0e209d39SAndroid Build Coastguard Worker * non-incremental transliteration, and rollback. All transliteration
897*0e209d39SAndroid Build Coastguard Worker * public API methods eventually call this method with a rollback argument
898*0e209d39SAndroid Build Coastguard Worker * of true. Other entities may call this method but rollback should be
899*0e209d39SAndroid Build Coastguard Worker * false.
900*0e209d39SAndroid Build Coastguard Worker *
901*0e209d39SAndroid Build Coastguard Worker * <p>If this transliterator has a filter, break up the input text into runs
902*0e209d39SAndroid Build Coastguard Worker * of unfiltered characters. Pass each run to
903*0e209d39SAndroid Build Coastguard Worker * subclass.handleTransliterate().
904*0e209d39SAndroid Build Coastguard Worker *
905*0e209d39SAndroid Build Coastguard Worker * <p>In incremental mode, if rollback is true, perform a special
906*0e209d39SAndroid Build Coastguard Worker * incremental procedure in which several passes are made over the input
907*0e209d39SAndroid Build Coastguard Worker * text, adding one character at a time, and committing successful
908*0e209d39SAndroid Build Coastguard Worker * transliterations as they occur. Unsuccessful transliterations are rolled
909*0e209d39SAndroid Build Coastguard Worker * back and retried with additional characters to give correct results.
910*0e209d39SAndroid Build Coastguard Worker *
911*0e209d39SAndroid Build Coastguard Worker * @param text the text to be transliterated
912*0e209d39SAndroid Build Coastguard Worker * @param index the position indices
913*0e209d39SAndroid Build Coastguard Worker * @param incremental if true, then assume more characters may be inserted
914*0e209d39SAndroid Build Coastguard Worker * at index.limit, and postpone processing to accommodate future incoming
915*0e209d39SAndroid Build Coastguard Worker * characters
916*0e209d39SAndroid Build Coastguard Worker * @param rollback if true and if incremental is true, then perform special
917*0e209d39SAndroid Build Coastguard Worker * incremental processing, as described above, and undo partial
918*0e209d39SAndroid Build Coastguard Worker * transliterations where necessary. If incremental is false then this
919*0e209d39SAndroid Build Coastguard Worker * parameter is ignored.
920*0e209d39SAndroid Build Coastguard Worker */
921*0e209d39SAndroid Build Coastguard Worker virtual void filteredTransliterate(Replaceable& text,
922*0e209d39SAndroid Build Coastguard Worker UTransPosition& index,
923*0e209d39SAndroid Build Coastguard Worker UBool incremental,
924*0e209d39SAndroid Build Coastguard Worker UBool rollback) const;
925*0e209d39SAndroid Build Coastguard Worker
926*0e209d39SAndroid Build Coastguard Worker public:
927*0e209d39SAndroid Build Coastguard Worker
928*0e209d39SAndroid Build Coastguard Worker /**
929*0e209d39SAndroid Build Coastguard Worker * Returns the length of the longest context required by this transliterator.
930*0e209d39SAndroid Build Coastguard Worker * This is <em>preceding</em> context. The default implementation supplied
931*0e209d39SAndroid Build Coastguard Worker * by <code>Transliterator</code> returns zero; subclasses
932*0e209d39SAndroid Build Coastguard Worker * that use preceding context should override this method to return the
933*0e209d39SAndroid Build Coastguard Worker * correct value. For example, if a transliterator translates "ddd" (where
934*0e209d39SAndroid Build Coastguard Worker * d is any digit) to "555" when preceded by "(ddd)", then the preceding
935*0e209d39SAndroid Build Coastguard Worker * context length is 5, the length of "(ddd)".
936*0e209d39SAndroid Build Coastguard Worker *
937*0e209d39SAndroid Build Coastguard Worker * @return The maximum number of preceding context characters this
938*0e209d39SAndroid Build Coastguard Worker * transliterator needs to examine
939*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
940*0e209d39SAndroid Build Coastguard Worker */
941*0e209d39SAndroid Build Coastguard Worker int32_t getMaximumContextLength() const;
942*0e209d39SAndroid Build Coastguard Worker
943*0e209d39SAndroid Build Coastguard Worker protected:
944*0e209d39SAndroid Build Coastguard Worker
945*0e209d39SAndroid Build Coastguard Worker /**
946*0e209d39SAndroid Build Coastguard Worker * Method for subclasses to use to set the maximum context length.
947*0e209d39SAndroid Build Coastguard Worker * @param maxContextLength the new value to be set.
948*0e209d39SAndroid Build Coastguard Worker * @see #getMaximumContextLength
949*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4
950*0e209d39SAndroid Build Coastguard Worker */
951*0e209d39SAndroid Build Coastguard Worker void setMaximumContextLength(int32_t maxContextLength);
952*0e209d39SAndroid Build Coastguard Worker
953*0e209d39SAndroid Build Coastguard Worker public:
954*0e209d39SAndroid Build Coastguard Worker
955*0e209d39SAndroid Build Coastguard Worker /**
956*0e209d39SAndroid Build Coastguard Worker * Returns a programmatic identifier for this transliterator.
957*0e209d39SAndroid Build Coastguard Worker * If this identifier is passed to <code>createInstance()</code>, it
958*0e209d39SAndroid Build Coastguard Worker * will return this object, if it has been registered.
959*0e209d39SAndroid Build Coastguard Worker * @return a programmatic identifier for this transliterator.
960*0e209d39SAndroid Build Coastguard Worker * @see #registerInstance
961*0e209d39SAndroid Build Coastguard Worker * @see #registerFactory
962*0e209d39SAndroid Build Coastguard Worker * @see #getAvailableIDs
963*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
964*0e209d39SAndroid Build Coastguard Worker */
965*0e209d39SAndroid Build Coastguard Worker virtual const UnicodeString& getID() const;
966*0e209d39SAndroid Build Coastguard Worker
967*0e209d39SAndroid Build Coastguard Worker /**
968*0e209d39SAndroid Build Coastguard Worker * Returns a name for this transliterator that is appropriate for
969*0e209d39SAndroid Build Coastguard Worker * display to the user in the default locale. See {@link #getDisplayName }
970*0e209d39SAndroid Build Coastguard Worker * for details.
971*0e209d39SAndroid Build Coastguard Worker * @param ID the string identifier for this transliterator
972*0e209d39SAndroid Build Coastguard Worker * @param result Output param to receive the display name
973*0e209d39SAndroid Build Coastguard Worker * @return A reference to 'result'.
974*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
975*0e209d39SAndroid Build Coastguard Worker */
976*0e209d39SAndroid Build Coastguard Worker static UnicodeString& U_EXPORT2 getDisplayName(const UnicodeString& ID,
977*0e209d39SAndroid Build Coastguard Worker UnicodeString& result);
978*0e209d39SAndroid Build Coastguard Worker
979*0e209d39SAndroid Build Coastguard Worker /**
980*0e209d39SAndroid Build Coastguard Worker * Returns a name for this transliterator that is appropriate for
981*0e209d39SAndroid Build Coastguard Worker * display to the user in the given locale. This name is taken
982*0e209d39SAndroid Build Coastguard Worker * from the locale resource data in the standard manner of the
983*0e209d39SAndroid Build Coastguard Worker * <code>java.text</code> package.
984*0e209d39SAndroid Build Coastguard Worker *
985*0e209d39SAndroid Build Coastguard Worker * <p>If no localized names exist in the system resource bundles,
986*0e209d39SAndroid Build Coastguard Worker * a name is synthesized using a localized
987*0e209d39SAndroid Build Coastguard Worker * <code>MessageFormat</code> pattern from the resource data. The
988*0e209d39SAndroid Build Coastguard Worker * arguments to this pattern are an integer followed by one or two
989*0e209d39SAndroid Build Coastguard Worker * strings. The integer is the number of strings, either 1 or 2.
990*0e209d39SAndroid Build Coastguard Worker * The strings are formed by splitting the ID for this
991*0e209d39SAndroid Build Coastguard Worker * transliterator at the first '-'. If there is no '-', then the
992*0e209d39SAndroid Build Coastguard Worker * entire ID forms the only string.
993*0e209d39SAndroid Build Coastguard Worker * @param ID the string identifier for this transliterator
994*0e209d39SAndroid Build Coastguard Worker * @param inLocale the Locale in which the display name should be
995*0e209d39SAndroid Build Coastguard Worker * localized.
996*0e209d39SAndroid Build Coastguard Worker * @param result Output param to receive the display name
997*0e209d39SAndroid Build Coastguard Worker * @return A reference to 'result'.
998*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
999*0e209d39SAndroid Build Coastguard Worker */
1000*0e209d39SAndroid Build Coastguard Worker static UnicodeString& U_EXPORT2 getDisplayName(const UnicodeString& ID,
1001*0e209d39SAndroid Build Coastguard Worker const Locale& inLocale,
1002*0e209d39SAndroid Build Coastguard Worker UnicodeString& result);
1003*0e209d39SAndroid Build Coastguard Worker
1004*0e209d39SAndroid Build Coastguard Worker /**
1005*0e209d39SAndroid Build Coastguard Worker * Returns the filter used by this transliterator, or <tt>nullptr</tt>
1006*0e209d39SAndroid Build Coastguard Worker * if this transliterator uses no filter.
1007*0e209d39SAndroid Build Coastguard Worker * @return the filter used by this transliterator, or <tt>nullptr</tt>
1008*0e209d39SAndroid Build Coastguard Worker * if this transliterator uses no filter.
1009*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1010*0e209d39SAndroid Build Coastguard Worker */
1011*0e209d39SAndroid Build Coastguard Worker const UnicodeFilter* getFilter() const;
1012*0e209d39SAndroid Build Coastguard Worker
1013*0e209d39SAndroid Build Coastguard Worker /**
1014*0e209d39SAndroid Build Coastguard Worker * Returns the filter used by this transliterator, or <tt>nullptr</tt> if this
1015*0e209d39SAndroid Build Coastguard Worker * transliterator uses no filter. The caller must eventually delete the
1016*0e209d39SAndroid Build Coastguard Worker * result. After this call, this transliterator's filter is set to
1017*0e209d39SAndroid Build Coastguard Worker * <tt>nullptr</tt>.
1018*0e209d39SAndroid Build Coastguard Worker * @return the filter used by this transliterator, or <tt>nullptr</tt> if this
1019*0e209d39SAndroid Build Coastguard Worker * transliterator uses no filter.
1020*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4
1021*0e209d39SAndroid Build Coastguard Worker */
1022*0e209d39SAndroid Build Coastguard Worker UnicodeFilter* orphanFilter();
1023*0e209d39SAndroid Build Coastguard Worker
1024*0e209d39SAndroid Build Coastguard Worker /**
1025*0e209d39SAndroid Build Coastguard Worker * Changes the filter used by this transliterator. If the filter
1026*0e209d39SAndroid Build Coastguard Worker * is set to <tt>null</tt> then no filtering will occur.
1027*0e209d39SAndroid Build Coastguard Worker *
1028*0e209d39SAndroid Build Coastguard Worker * <p>Callers must take care if a transliterator is in use by
1029*0e209d39SAndroid Build Coastguard Worker * multiple threads. The filter should not be changed by one
1030*0e209d39SAndroid Build Coastguard Worker * thread while another thread may be transliterating.
1031*0e209d39SAndroid Build Coastguard Worker * @param adoptedFilter the new filter to be adopted.
1032*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1033*0e209d39SAndroid Build Coastguard Worker */
1034*0e209d39SAndroid Build Coastguard Worker void adoptFilter(UnicodeFilter* adoptedFilter);
1035*0e209d39SAndroid Build Coastguard Worker
1036*0e209d39SAndroid Build Coastguard Worker /**
1037*0e209d39SAndroid Build Coastguard Worker * Returns this transliterator's inverse. See the class
1038*0e209d39SAndroid Build Coastguard Worker * documentation for details. This implementation simply inverts
1039*0e209d39SAndroid Build Coastguard Worker * the two entities in the ID and attempts to retrieve the
1040*0e209d39SAndroid Build Coastguard Worker * resulting transliterator. That is, if <code>getID()</code>
1041*0e209d39SAndroid Build Coastguard Worker * returns "A-B", then this method will return the result of
1042*0e209d39SAndroid Build Coastguard Worker * <code>createInstance("B-A")</code>, or <code>null</code> if that
1043*0e209d39SAndroid Build Coastguard Worker * call fails.
1044*0e209d39SAndroid Build Coastguard Worker *
1045*0e209d39SAndroid Build Coastguard Worker * <p>Subclasses with knowledge of their inverse may wish to
1046*0e209d39SAndroid Build Coastguard Worker * override this method.
1047*0e209d39SAndroid Build Coastguard Worker *
1048*0e209d39SAndroid Build Coastguard Worker * @param status Output param to filled in with a success or an error.
1049*0e209d39SAndroid Build Coastguard Worker * @return a transliterator that is an inverse, not necessarily
1050*0e209d39SAndroid Build Coastguard Worker * exact, of this transliterator, or <code>null</code> if no such
1051*0e209d39SAndroid Build Coastguard Worker * transliterator is registered.
1052*0e209d39SAndroid Build Coastguard Worker * @see #registerInstance
1053*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1054*0e209d39SAndroid Build Coastguard Worker */
1055*0e209d39SAndroid Build Coastguard Worker Transliterator* createInverse(UErrorCode& status) const;
1056*0e209d39SAndroid Build Coastguard Worker
1057*0e209d39SAndroid Build Coastguard Worker /**
1058*0e209d39SAndroid Build Coastguard Worker * Returns a <code>Transliterator</code> object given its ID.
1059*0e209d39SAndroid Build Coastguard Worker * The ID must be either a system transliterator ID or a ID registered
1060*0e209d39SAndroid Build Coastguard Worker * using <code>registerInstance()</code>.
1061*0e209d39SAndroid Build Coastguard Worker *
1062*0e209d39SAndroid Build Coastguard Worker * @param ID a valid ID, as enumerated by <code>getAvailableIDs()</code>
1063*0e209d39SAndroid Build Coastguard Worker * @param dir either FORWARD or REVERSE.
1064*0e209d39SAndroid Build Coastguard Worker * @param parseError Struct to receive information on position
1065*0e209d39SAndroid Build Coastguard Worker * of error if an error is encountered
1066*0e209d39SAndroid Build Coastguard Worker * @param status Output param to filled in with a success or an error.
1067*0e209d39SAndroid Build Coastguard Worker * @return A <code>Transliterator</code> object with the given ID
1068*0e209d39SAndroid Build Coastguard Worker * @see #registerInstance
1069*0e209d39SAndroid Build Coastguard Worker * @see #getAvailableIDs
1070*0e209d39SAndroid Build Coastguard Worker * @see #getID
1071*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1072*0e209d39SAndroid Build Coastguard Worker */
1073*0e209d39SAndroid Build Coastguard Worker static Transliterator* U_EXPORT2 createInstance(const UnicodeString& ID,
1074*0e209d39SAndroid Build Coastguard Worker UTransDirection dir,
1075*0e209d39SAndroid Build Coastguard Worker UParseError& parseError,
1076*0e209d39SAndroid Build Coastguard Worker UErrorCode& status);
1077*0e209d39SAndroid Build Coastguard Worker
1078*0e209d39SAndroid Build Coastguard Worker /**
1079*0e209d39SAndroid Build Coastguard Worker * Returns a <code>Transliterator</code> object given its ID.
1080*0e209d39SAndroid Build Coastguard Worker * The ID must be either a system transliterator ID or a ID registered
1081*0e209d39SAndroid Build Coastguard Worker * using <code>registerInstance()</code>.
1082*0e209d39SAndroid Build Coastguard Worker * @param ID a valid ID, as enumerated by <code>getAvailableIDs()</code>
1083*0e209d39SAndroid Build Coastguard Worker * @param dir either FORWARD or REVERSE.
1084*0e209d39SAndroid Build Coastguard Worker * @param status Output param to filled in with a success or an error.
1085*0e209d39SAndroid Build Coastguard Worker * @return A <code>Transliterator</code> object with the given ID
1086*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1087*0e209d39SAndroid Build Coastguard Worker */
1088*0e209d39SAndroid Build Coastguard Worker static Transliterator* U_EXPORT2 createInstance(const UnicodeString& ID,
1089*0e209d39SAndroid Build Coastguard Worker UTransDirection dir,
1090*0e209d39SAndroid Build Coastguard Worker UErrorCode& status);
1091*0e209d39SAndroid Build Coastguard Worker
1092*0e209d39SAndroid Build Coastguard Worker /**
1093*0e209d39SAndroid Build Coastguard Worker * Returns a <code>Transliterator</code> object constructed from
1094*0e209d39SAndroid Build Coastguard Worker * the given rule string. This will be a rule-based Transliterator,
1095*0e209d39SAndroid Build Coastguard Worker * if the rule string contains only rules, or a
1096*0e209d39SAndroid Build Coastguard Worker * compound Transliterator, if it contains ID blocks, or a
1097*0e209d39SAndroid Build Coastguard Worker * null Transliterator, if it contains ID blocks which parse as
1098*0e209d39SAndroid Build Coastguard Worker * empty for the given direction.
1099*0e209d39SAndroid Build Coastguard Worker *
1100*0e209d39SAndroid Build Coastguard Worker * @param ID the id for the transliterator.
1101*0e209d39SAndroid Build Coastguard Worker * @param rules rules, separated by ';'
1102*0e209d39SAndroid Build Coastguard Worker * @param dir either FORWARD or REVERSE.
1103*0e209d39SAndroid Build Coastguard Worker * @param parseError Struct to receive information on position
1104*0e209d39SAndroid Build Coastguard Worker * of error if an error is encountered
1105*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code.
1106*0e209d39SAndroid Build Coastguard Worker * @return a newly created Transliterator
1107*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1108*0e209d39SAndroid Build Coastguard Worker */
1109*0e209d39SAndroid Build Coastguard Worker static Transliterator* U_EXPORT2 createFromRules(const UnicodeString& ID,
1110*0e209d39SAndroid Build Coastguard Worker const UnicodeString& rules,
1111*0e209d39SAndroid Build Coastguard Worker UTransDirection dir,
1112*0e209d39SAndroid Build Coastguard Worker UParseError& parseError,
1113*0e209d39SAndroid Build Coastguard Worker UErrorCode& status);
1114*0e209d39SAndroid Build Coastguard Worker
1115*0e209d39SAndroid Build Coastguard Worker /**
1116*0e209d39SAndroid Build Coastguard Worker * Create a rule string that can be passed to createFromRules()
1117*0e209d39SAndroid Build Coastguard Worker * to recreate this transliterator.
1118*0e209d39SAndroid Build Coastguard Worker * @param result the string to receive the rules. Previous
1119*0e209d39SAndroid Build Coastguard Worker * contents will be deleted.
1120*0e209d39SAndroid Build Coastguard Worker * @param escapeUnprintable if true then convert unprintable
1121*0e209d39SAndroid Build Coastguard Worker * character to their hex escape representations, \\uxxxx or
1122*0e209d39SAndroid Build Coastguard Worker * \\Uxxxxxxxx. Unprintable characters are those other than
1123*0e209d39SAndroid Build Coastguard Worker * U+000A, U+0020..U+007E.
1124*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1125*0e209d39SAndroid Build Coastguard Worker */
1126*0e209d39SAndroid Build Coastguard Worker virtual UnicodeString& toRules(UnicodeString& result,
1127*0e209d39SAndroid Build Coastguard Worker UBool escapeUnprintable) const;
1128*0e209d39SAndroid Build Coastguard Worker
1129*0e209d39SAndroid Build Coastguard Worker /**
1130*0e209d39SAndroid Build Coastguard Worker * Return the number of elements that make up this transliterator.
1131*0e209d39SAndroid Build Coastguard Worker * For example, if the transliterator "NFD;Jamo-Latin;Latin-Greek"
1132*0e209d39SAndroid Build Coastguard Worker * were created, the return value of this method would be 3.
1133*0e209d39SAndroid Build Coastguard Worker *
1134*0e209d39SAndroid Build Coastguard Worker * <p>If this transliterator is not composed of other
1135*0e209d39SAndroid Build Coastguard Worker * transliterators, then this method returns 1.
1136*0e209d39SAndroid Build Coastguard Worker * @return the number of transliterators that compose this
1137*0e209d39SAndroid Build Coastguard Worker * transliterator, or 1 if this transliterator is not composed of
1138*0e209d39SAndroid Build Coastguard Worker * multiple transliterators
1139*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.0
1140*0e209d39SAndroid Build Coastguard Worker */
1141*0e209d39SAndroid Build Coastguard Worker int32_t countElements() const;
1142*0e209d39SAndroid Build Coastguard Worker
1143*0e209d39SAndroid Build Coastguard Worker /**
1144*0e209d39SAndroid Build Coastguard Worker * Return an element that makes up this transliterator. For
1145*0e209d39SAndroid Build Coastguard Worker * example, if the transliterator "NFD;Jamo-Latin;Latin-Greek"
1146*0e209d39SAndroid Build Coastguard Worker * were created, the return value of this method would be one
1147*0e209d39SAndroid Build Coastguard Worker * of the three transliterator objects that make up that
1148*0e209d39SAndroid Build Coastguard Worker * transliterator: [NFD, Jamo-Latin, Latin-Greek].
1149*0e209d39SAndroid Build Coastguard Worker *
1150*0e209d39SAndroid Build Coastguard Worker * <p>If this transliterator is not composed of other
1151*0e209d39SAndroid Build Coastguard Worker * transliterators, then this method will return a reference to
1152*0e209d39SAndroid Build Coastguard Worker * this transliterator when given the index 0.
1153*0e209d39SAndroid Build Coastguard Worker * @param index a value from 0..countElements()-1 indicating the
1154*0e209d39SAndroid Build Coastguard Worker * transliterator to return
1155*0e209d39SAndroid Build Coastguard Worker * @param ec input-output error code
1156*0e209d39SAndroid Build Coastguard Worker * @return one of the transliterators that makes up this
1157*0e209d39SAndroid Build Coastguard Worker * transliterator, if this transliterator is made up of multiple
1158*0e209d39SAndroid Build Coastguard Worker * transliterators, otherwise a reference to this object if given
1159*0e209d39SAndroid Build Coastguard Worker * an index of 0
1160*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.0
1161*0e209d39SAndroid Build Coastguard Worker */
1162*0e209d39SAndroid Build Coastguard Worker const Transliterator& getElement(int32_t index, UErrorCode& ec) const;
1163*0e209d39SAndroid Build Coastguard Worker
1164*0e209d39SAndroid Build Coastguard Worker /**
1165*0e209d39SAndroid Build Coastguard Worker * Returns the set of all characters that may be modified in the
1166*0e209d39SAndroid Build Coastguard Worker * input text by this Transliterator. This incorporates this
1167*0e209d39SAndroid Build Coastguard Worker * object's current filter; if the filter is changed, the return
1168*0e209d39SAndroid Build Coastguard Worker * value of this function will change. The default implementation
1169*0e209d39SAndroid Build Coastguard Worker * returns an empty set. Some subclasses may override
1170*0e209d39SAndroid Build Coastguard Worker * {@link #handleGetSourceSet } to return a more precise result. The
1171*0e209d39SAndroid Build Coastguard Worker * return result is approximate in any case and is intended for
1172*0e209d39SAndroid Build Coastguard Worker * use by tests, tools, or utilities.
1173*0e209d39SAndroid Build Coastguard Worker * @param result receives result set; previous contents lost
1174*0e209d39SAndroid Build Coastguard Worker * @return a reference to result
1175*0e209d39SAndroid Build Coastguard Worker * @see #getTargetSet
1176*0e209d39SAndroid Build Coastguard Worker * @see #handleGetSourceSet
1177*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4
1178*0e209d39SAndroid Build Coastguard Worker */
1179*0e209d39SAndroid Build Coastguard Worker UnicodeSet& getSourceSet(UnicodeSet& result) const;
1180*0e209d39SAndroid Build Coastguard Worker
1181*0e209d39SAndroid Build Coastguard Worker /**
1182*0e209d39SAndroid Build Coastguard Worker * Framework method that returns the set of all characters that
1183*0e209d39SAndroid Build Coastguard Worker * may be modified in the input text by this Transliterator,
1184*0e209d39SAndroid Build Coastguard Worker * ignoring the effect of this object's filter. The base class
1185*0e209d39SAndroid Build Coastguard Worker * implementation returns the empty set. Subclasses that wish to
1186*0e209d39SAndroid Build Coastguard Worker * implement this should override this method.
1187*0e209d39SAndroid Build Coastguard Worker * @return the set of characters that this transliterator may
1188*0e209d39SAndroid Build Coastguard Worker * modify. The set may be modified, so subclasses should return a
1189*0e209d39SAndroid Build Coastguard Worker * newly-created object.
1190*0e209d39SAndroid Build Coastguard Worker * @param result receives result set; previous contents lost
1191*0e209d39SAndroid Build Coastguard Worker * @see #getSourceSet
1192*0e209d39SAndroid Build Coastguard Worker * @see #getTargetSet
1193*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4
1194*0e209d39SAndroid Build Coastguard Worker */
1195*0e209d39SAndroid Build Coastguard Worker virtual void handleGetSourceSet(UnicodeSet& result) const;
1196*0e209d39SAndroid Build Coastguard Worker
1197*0e209d39SAndroid Build Coastguard Worker /**
1198*0e209d39SAndroid Build Coastguard Worker * Returns the set of all characters that may be generated as
1199*0e209d39SAndroid Build Coastguard Worker * replacement text by this transliterator. The default
1200*0e209d39SAndroid Build Coastguard Worker * implementation returns the empty set. Some subclasses may
1201*0e209d39SAndroid Build Coastguard Worker * override this method to return a more precise result. The
1202*0e209d39SAndroid Build Coastguard Worker * return result is approximate in any case and is intended for
1203*0e209d39SAndroid Build Coastguard Worker * use by tests, tools, or utilities requiring such
1204*0e209d39SAndroid Build Coastguard Worker * meta-information.
1205*0e209d39SAndroid Build Coastguard Worker * @param result receives result set; previous contents lost
1206*0e209d39SAndroid Build Coastguard Worker * @return a reference to result
1207*0e209d39SAndroid Build Coastguard Worker * @see #getTargetSet
1208*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4
1209*0e209d39SAndroid Build Coastguard Worker */
1210*0e209d39SAndroid Build Coastguard Worker virtual UnicodeSet& getTargetSet(UnicodeSet& result) const;
1211*0e209d39SAndroid Build Coastguard Worker
1212*0e209d39SAndroid Build Coastguard Worker public:
1213*0e209d39SAndroid Build Coastguard Worker
1214*0e209d39SAndroid Build Coastguard Worker /**
1215*0e209d39SAndroid Build Coastguard Worker * Registers a factory function that creates transliterators of
1216*0e209d39SAndroid Build Coastguard Worker * a given ID.
1217*0e209d39SAndroid Build Coastguard Worker *
1218*0e209d39SAndroid Build Coastguard Worker * Because ICU may choose to cache Transliterators internally, this must
1219*0e209d39SAndroid Build Coastguard Worker * be called at application startup, prior to any calls to
1220*0e209d39SAndroid Build Coastguard Worker * Transliterator::createXXX to avoid undefined behavior.
1221*0e209d39SAndroid Build Coastguard Worker *
1222*0e209d39SAndroid Build Coastguard Worker * @param id the ID being registered
1223*0e209d39SAndroid Build Coastguard Worker * @param factory a function pointer that will be copied and
1224*0e209d39SAndroid Build Coastguard Worker * called later when the given ID is passed to createInstance()
1225*0e209d39SAndroid Build Coastguard Worker * @param context a context pointer that will be stored and
1226*0e209d39SAndroid Build Coastguard Worker * later passed to the factory function when an ID matching
1227*0e209d39SAndroid Build Coastguard Worker * the registration ID is being instantiated with this factory.
1228*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1229*0e209d39SAndroid Build Coastguard Worker */
1230*0e209d39SAndroid Build Coastguard Worker static void U_EXPORT2 registerFactory(const UnicodeString& id,
1231*0e209d39SAndroid Build Coastguard Worker Factory factory,
1232*0e209d39SAndroid Build Coastguard Worker Token context);
1233*0e209d39SAndroid Build Coastguard Worker
1234*0e209d39SAndroid Build Coastguard Worker /**
1235*0e209d39SAndroid Build Coastguard Worker * Registers an instance <tt>obj</tt> of a subclass of
1236*0e209d39SAndroid Build Coastguard Worker * <code>Transliterator</code> with the system. When
1237*0e209d39SAndroid Build Coastguard Worker * <tt>createInstance()</tt> is called with an ID string that is
1238*0e209d39SAndroid Build Coastguard Worker * equal to <tt>obj->getID()</tt>, then <tt>obj->clone()</tt> is
1239*0e209d39SAndroid Build Coastguard Worker * returned.
1240*0e209d39SAndroid Build Coastguard Worker *
1241*0e209d39SAndroid Build Coastguard Worker * After this call the Transliterator class owns the adoptedObj
1242*0e209d39SAndroid Build Coastguard Worker * and will delete it.
1243*0e209d39SAndroid Build Coastguard Worker *
1244*0e209d39SAndroid Build Coastguard Worker * Because ICU may choose to cache Transliterators internally, this must
1245*0e209d39SAndroid Build Coastguard Worker * be called at application startup, prior to any calls to
1246*0e209d39SAndroid Build Coastguard Worker * Transliterator::createXXX to avoid undefined behavior.
1247*0e209d39SAndroid Build Coastguard Worker *
1248*0e209d39SAndroid Build Coastguard Worker * @param adoptedObj an instance of subclass of
1249*0e209d39SAndroid Build Coastguard Worker * <code>Transliterator</code> that defines <tt>clone()</tt>
1250*0e209d39SAndroid Build Coastguard Worker * @see #createInstance
1251*0e209d39SAndroid Build Coastguard Worker * @see #registerFactory
1252*0e209d39SAndroid Build Coastguard Worker * @see #unregister
1253*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1254*0e209d39SAndroid Build Coastguard Worker */
1255*0e209d39SAndroid Build Coastguard Worker static void U_EXPORT2 registerInstance(Transliterator* adoptedObj);
1256*0e209d39SAndroid Build Coastguard Worker
1257*0e209d39SAndroid Build Coastguard Worker /**
1258*0e209d39SAndroid Build Coastguard Worker * Registers an ID string as an alias of another ID string.
1259*0e209d39SAndroid Build Coastguard Worker * That is, after calling this function, <tt>createInstance(aliasID)</tt>
1260*0e209d39SAndroid Build Coastguard Worker * will return the same thing as <tt>createInstance(realID)</tt>.
1261*0e209d39SAndroid Build Coastguard Worker * This is generally used to create shorter, more mnemonic aliases
1262*0e209d39SAndroid Build Coastguard Worker * for long compound IDs.
1263*0e209d39SAndroid Build Coastguard Worker *
1264*0e209d39SAndroid Build Coastguard Worker * @param aliasID The new ID being registered.
1265*0e209d39SAndroid Build Coastguard Worker * @param realID The ID that the new ID is to be an alias for.
1266*0e209d39SAndroid Build Coastguard Worker * This can be a compound ID and can include filters and should
1267*0e209d39SAndroid Build Coastguard Worker * refer to transliterators that have already been registered with
1268*0e209d39SAndroid Build Coastguard Worker * the framework, although this isn't checked.
1269*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.6
1270*0e209d39SAndroid Build Coastguard Worker */
1271*0e209d39SAndroid Build Coastguard Worker static void U_EXPORT2 registerAlias(const UnicodeString& aliasID,
1272*0e209d39SAndroid Build Coastguard Worker const UnicodeString& realID);
1273*0e209d39SAndroid Build Coastguard Worker
1274*0e209d39SAndroid Build Coastguard Worker protected:
1275*0e209d39SAndroid Build Coastguard Worker
1276*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
1277*0e209d39SAndroid Build Coastguard Worker /**
1278*0e209d39SAndroid Build Coastguard Worker * @param id the ID being registered
1279*0e209d39SAndroid Build Coastguard Worker * @param factory a function pointer that will be copied and
1280*0e209d39SAndroid Build Coastguard Worker * called later when the given ID is passed to createInstance()
1281*0e209d39SAndroid Build Coastguard Worker * @param context a context pointer that will be stored and
1282*0e209d39SAndroid Build Coastguard Worker * later passed to the factory function when an ID matching
1283*0e209d39SAndroid Build Coastguard Worker * the registration ID is being instantiated with this factory.
1284*0e209d39SAndroid Build Coastguard Worker * @internal
1285*0e209d39SAndroid Build Coastguard Worker */
1286*0e209d39SAndroid Build Coastguard Worker static void _registerFactory(const UnicodeString& id,
1287*0e209d39SAndroid Build Coastguard Worker Factory factory,
1288*0e209d39SAndroid Build Coastguard Worker Token context);
1289*0e209d39SAndroid Build Coastguard Worker
1290*0e209d39SAndroid Build Coastguard Worker /**
1291*0e209d39SAndroid Build Coastguard Worker * @internal
1292*0e209d39SAndroid Build Coastguard Worker */
1293*0e209d39SAndroid Build Coastguard Worker static void _registerInstance(Transliterator* adoptedObj);
1294*0e209d39SAndroid Build Coastguard Worker
1295*0e209d39SAndroid Build Coastguard Worker /**
1296*0e209d39SAndroid Build Coastguard Worker * @internal
1297*0e209d39SAndroid Build Coastguard Worker */
1298*0e209d39SAndroid Build Coastguard Worker static void _registerAlias(const UnicodeString& aliasID, const UnicodeString& realID);
1299*0e209d39SAndroid Build Coastguard Worker
1300*0e209d39SAndroid Build Coastguard Worker /**
1301*0e209d39SAndroid Build Coastguard Worker * Register two targets as being inverses of one another. For
1302*0e209d39SAndroid Build Coastguard Worker * example, calling registerSpecialInverse("NFC", "NFD", true) causes
1303*0e209d39SAndroid Build Coastguard Worker * Transliterator to form the following inverse relationships:
1304*0e209d39SAndroid Build Coastguard Worker *
1305*0e209d39SAndroid Build Coastguard Worker * <pre>NFC => NFD
1306*0e209d39SAndroid Build Coastguard Worker * Any-NFC => Any-NFD
1307*0e209d39SAndroid Build Coastguard Worker * NFD => NFC
1308*0e209d39SAndroid Build Coastguard Worker * Any-NFD => Any-NFC</pre>
1309*0e209d39SAndroid Build Coastguard Worker *
1310*0e209d39SAndroid Build Coastguard Worker * (Without the special inverse registration, the inverse of NFC
1311*0e209d39SAndroid Build Coastguard Worker * would be NFC-Any.) Note that NFD is shorthand for Any-NFD, but
1312*0e209d39SAndroid Build Coastguard Worker * that the presence or absence of "Any-" is preserved.
1313*0e209d39SAndroid Build Coastguard Worker *
1314*0e209d39SAndroid Build Coastguard Worker * <p>The relationship is symmetrical; registering (a, b) is
1315*0e209d39SAndroid Build Coastguard Worker * equivalent to registering (b, a).
1316*0e209d39SAndroid Build Coastguard Worker *
1317*0e209d39SAndroid Build Coastguard Worker * <p>The relevant IDs must still be registered separately as
1318*0e209d39SAndroid Build Coastguard Worker * factories or classes.
1319*0e209d39SAndroid Build Coastguard Worker *
1320*0e209d39SAndroid Build Coastguard Worker * <p>Only the targets are specified. Special inverses always
1321*0e209d39SAndroid Build Coastguard Worker * have the form Any-Target1 <=> Any-Target2. The target should
1322*0e209d39SAndroid Build Coastguard Worker * have canonical casing (the casing desired to be produced when
1323*0e209d39SAndroid Build Coastguard Worker * an inverse is formed) and should contain no whitespace or other
1324*0e209d39SAndroid Build Coastguard Worker * extraneous characters.
1325*0e209d39SAndroid Build Coastguard Worker *
1326*0e209d39SAndroid Build Coastguard Worker * @param target the target against which to register the inverse
1327*0e209d39SAndroid Build Coastguard Worker * @param inverseTarget the inverse of target, that is
1328*0e209d39SAndroid Build Coastguard Worker * Any-target.getInverse() => Any-inverseTarget
1329*0e209d39SAndroid Build Coastguard Worker * @param bidirectional if true, register the reverse relation
1330*0e209d39SAndroid Build Coastguard Worker * as well, that is, Any-inverseTarget.getInverse() => Any-target
1331*0e209d39SAndroid Build Coastguard Worker * @internal
1332*0e209d39SAndroid Build Coastguard Worker */
1333*0e209d39SAndroid Build Coastguard Worker static void _registerSpecialInverse(const UnicodeString& target,
1334*0e209d39SAndroid Build Coastguard Worker const UnicodeString& inverseTarget,
1335*0e209d39SAndroid Build Coastguard Worker UBool bidirectional);
1336*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */
1337*0e209d39SAndroid Build Coastguard Worker
1338*0e209d39SAndroid Build Coastguard Worker public:
1339*0e209d39SAndroid Build Coastguard Worker
1340*0e209d39SAndroid Build Coastguard Worker /**
1341*0e209d39SAndroid Build Coastguard Worker * Unregisters a transliterator or class. This may be either
1342*0e209d39SAndroid Build Coastguard Worker * a system transliterator or a user transliterator or class.
1343*0e209d39SAndroid Build Coastguard Worker * Any attempt to construct an unregistered transliterator based
1344*0e209d39SAndroid Build Coastguard Worker * on its ID will fail.
1345*0e209d39SAndroid Build Coastguard Worker *
1346*0e209d39SAndroid Build Coastguard Worker * Because ICU may choose to cache Transliterators internally, this should
1347*0e209d39SAndroid Build Coastguard Worker * be called during application shutdown, after all calls to
1348*0e209d39SAndroid Build Coastguard Worker * Transliterator::createXXX to avoid undefined behavior.
1349*0e209d39SAndroid Build Coastguard Worker *
1350*0e209d39SAndroid Build Coastguard Worker * @param ID the ID of the transliterator or class
1351*0e209d39SAndroid Build Coastguard Worker * @return the <code>Object</code> that was registered with
1352*0e209d39SAndroid Build Coastguard Worker * <code>ID</code>, or <code>null</code> if none was
1353*0e209d39SAndroid Build Coastguard Worker * @see #registerInstance
1354*0e209d39SAndroid Build Coastguard Worker * @see #registerFactory
1355*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1356*0e209d39SAndroid Build Coastguard Worker */
1357*0e209d39SAndroid Build Coastguard Worker static void U_EXPORT2 unregister(const UnicodeString& ID);
1358*0e209d39SAndroid Build Coastguard Worker
1359*0e209d39SAndroid Build Coastguard Worker public:
1360*0e209d39SAndroid Build Coastguard Worker
1361*0e209d39SAndroid Build Coastguard Worker /**
1362*0e209d39SAndroid Build Coastguard Worker * Return a StringEnumeration over the IDs available at the time of the
1363*0e209d39SAndroid Build Coastguard Worker * call, including user-registered IDs.
1364*0e209d39SAndroid Build Coastguard Worker * @param ec input-output error code
1365*0e209d39SAndroid Build Coastguard Worker * @return a newly-created StringEnumeration over the transliterators
1366*0e209d39SAndroid Build Coastguard Worker * available at the time of the call. The caller should delete this object
1367*0e209d39SAndroid Build Coastguard Worker * when done using it.
1368*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.0
1369*0e209d39SAndroid Build Coastguard Worker */
1370*0e209d39SAndroid Build Coastguard Worker static StringEnumeration* U_EXPORT2 getAvailableIDs(UErrorCode& ec);
1371*0e209d39SAndroid Build Coastguard Worker
1372*0e209d39SAndroid Build Coastguard Worker /**
1373*0e209d39SAndroid Build Coastguard Worker * Return the number of registered source specifiers.
1374*0e209d39SAndroid Build Coastguard Worker * @return the number of registered source specifiers.
1375*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1376*0e209d39SAndroid Build Coastguard Worker */
1377*0e209d39SAndroid Build Coastguard Worker static int32_t U_EXPORT2 countAvailableSources();
1378*0e209d39SAndroid Build Coastguard Worker
1379*0e209d39SAndroid Build Coastguard Worker /**
1380*0e209d39SAndroid Build Coastguard Worker * Return a registered source specifier.
1381*0e209d39SAndroid Build Coastguard Worker * @param index which specifier to return, from 0 to n-1, where
1382*0e209d39SAndroid Build Coastguard Worker * n = countAvailableSources()
1383*0e209d39SAndroid Build Coastguard Worker * @param result fill-in parameter to receive the source specifier.
1384*0e209d39SAndroid Build Coastguard Worker * If index is out of range, result will be empty.
1385*0e209d39SAndroid Build Coastguard Worker * @return reference to result
1386*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1387*0e209d39SAndroid Build Coastguard Worker */
1388*0e209d39SAndroid Build Coastguard Worker static UnicodeString& U_EXPORT2 getAvailableSource(int32_t index,
1389*0e209d39SAndroid Build Coastguard Worker UnicodeString& result);
1390*0e209d39SAndroid Build Coastguard Worker
1391*0e209d39SAndroid Build Coastguard Worker /**
1392*0e209d39SAndroid Build Coastguard Worker * Return the number of registered target specifiers for a given
1393*0e209d39SAndroid Build Coastguard Worker * source specifier.
1394*0e209d39SAndroid Build Coastguard Worker * @param source the given source specifier.
1395*0e209d39SAndroid Build Coastguard Worker * @return the number of registered target specifiers for a given
1396*0e209d39SAndroid Build Coastguard Worker * source specifier.
1397*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1398*0e209d39SAndroid Build Coastguard Worker */
1399*0e209d39SAndroid Build Coastguard Worker static int32_t U_EXPORT2 countAvailableTargets(const UnicodeString& source);
1400*0e209d39SAndroid Build Coastguard Worker
1401*0e209d39SAndroid Build Coastguard Worker /**
1402*0e209d39SAndroid Build Coastguard Worker * Return a registered target specifier for a given source.
1403*0e209d39SAndroid Build Coastguard Worker * @param index which specifier to return, from 0 to n-1, where
1404*0e209d39SAndroid Build Coastguard Worker * n = countAvailableTargets(source)
1405*0e209d39SAndroid Build Coastguard Worker * @param source the source specifier
1406*0e209d39SAndroid Build Coastguard Worker * @param result fill-in parameter to receive the target specifier.
1407*0e209d39SAndroid Build Coastguard Worker * If source is invalid or if index is out of range, result will
1408*0e209d39SAndroid Build Coastguard Worker * be empty.
1409*0e209d39SAndroid Build Coastguard Worker * @return reference to result
1410*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1411*0e209d39SAndroid Build Coastguard Worker */
1412*0e209d39SAndroid Build Coastguard Worker static UnicodeString& U_EXPORT2 getAvailableTarget(int32_t index,
1413*0e209d39SAndroid Build Coastguard Worker const UnicodeString& source,
1414*0e209d39SAndroid Build Coastguard Worker UnicodeString& result);
1415*0e209d39SAndroid Build Coastguard Worker
1416*0e209d39SAndroid Build Coastguard Worker /**
1417*0e209d39SAndroid Build Coastguard Worker * Return the number of registered variant specifiers for a given
1418*0e209d39SAndroid Build Coastguard Worker * source-target pair.
1419*0e209d39SAndroid Build Coastguard Worker * @param source the source specifiers.
1420*0e209d39SAndroid Build Coastguard Worker * @param target the target specifiers.
1421*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1422*0e209d39SAndroid Build Coastguard Worker */
1423*0e209d39SAndroid Build Coastguard Worker static int32_t U_EXPORT2 countAvailableVariants(const UnicodeString& source,
1424*0e209d39SAndroid Build Coastguard Worker const UnicodeString& target);
1425*0e209d39SAndroid Build Coastguard Worker
1426*0e209d39SAndroid Build Coastguard Worker /**
1427*0e209d39SAndroid Build Coastguard Worker * Return a registered variant specifier for a given source-target
1428*0e209d39SAndroid Build Coastguard Worker * pair.
1429*0e209d39SAndroid Build Coastguard Worker * @param index which specifier to return, from 0 to n-1, where
1430*0e209d39SAndroid Build Coastguard Worker * n = countAvailableVariants(source, target)
1431*0e209d39SAndroid Build Coastguard Worker * @param source the source specifier
1432*0e209d39SAndroid Build Coastguard Worker * @param target the target specifier
1433*0e209d39SAndroid Build Coastguard Worker * @param result fill-in parameter to receive the variant
1434*0e209d39SAndroid Build Coastguard Worker * specifier. If source is invalid or if target is invalid or if
1435*0e209d39SAndroid Build Coastguard Worker * index is out of range, result will be empty.
1436*0e209d39SAndroid Build Coastguard Worker * @return reference to result
1437*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1438*0e209d39SAndroid Build Coastguard Worker */
1439*0e209d39SAndroid Build Coastguard Worker static UnicodeString& U_EXPORT2 getAvailableVariant(int32_t index,
1440*0e209d39SAndroid Build Coastguard Worker const UnicodeString& source,
1441*0e209d39SAndroid Build Coastguard Worker const UnicodeString& target,
1442*0e209d39SAndroid Build Coastguard Worker UnicodeString& result);
1443*0e209d39SAndroid Build Coastguard Worker
1444*0e209d39SAndroid Build Coastguard Worker protected:
1445*0e209d39SAndroid Build Coastguard Worker
1446*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
1447*0e209d39SAndroid Build Coastguard Worker /**
1448*0e209d39SAndroid Build Coastguard Worker * Non-mutexed internal method
1449*0e209d39SAndroid Build Coastguard Worker * @internal
1450*0e209d39SAndroid Build Coastguard Worker */
1451*0e209d39SAndroid Build Coastguard Worker static int32_t _countAvailableSources();
1452*0e209d39SAndroid Build Coastguard Worker
1453*0e209d39SAndroid Build Coastguard Worker /**
1454*0e209d39SAndroid Build Coastguard Worker * Non-mutexed internal method
1455*0e209d39SAndroid Build Coastguard Worker * @internal
1456*0e209d39SAndroid Build Coastguard Worker */
1457*0e209d39SAndroid Build Coastguard Worker static UnicodeString& _getAvailableSource(int32_t index,
1458*0e209d39SAndroid Build Coastguard Worker UnicodeString& result);
1459*0e209d39SAndroid Build Coastguard Worker
1460*0e209d39SAndroid Build Coastguard Worker /**
1461*0e209d39SAndroid Build Coastguard Worker * Non-mutexed internal method
1462*0e209d39SAndroid Build Coastguard Worker * @internal
1463*0e209d39SAndroid Build Coastguard Worker */
1464*0e209d39SAndroid Build Coastguard Worker static int32_t _countAvailableTargets(const UnicodeString& source);
1465*0e209d39SAndroid Build Coastguard Worker
1466*0e209d39SAndroid Build Coastguard Worker /**
1467*0e209d39SAndroid Build Coastguard Worker * Non-mutexed internal method
1468*0e209d39SAndroid Build Coastguard Worker * @internal
1469*0e209d39SAndroid Build Coastguard Worker */
1470*0e209d39SAndroid Build Coastguard Worker static UnicodeString& _getAvailableTarget(int32_t index,
1471*0e209d39SAndroid Build Coastguard Worker const UnicodeString& source,
1472*0e209d39SAndroid Build Coastguard Worker UnicodeString& result);
1473*0e209d39SAndroid Build Coastguard Worker
1474*0e209d39SAndroid Build Coastguard Worker /**
1475*0e209d39SAndroid Build Coastguard Worker * Non-mutexed internal method
1476*0e209d39SAndroid Build Coastguard Worker * @internal
1477*0e209d39SAndroid Build Coastguard Worker */
1478*0e209d39SAndroid Build Coastguard Worker static int32_t _countAvailableVariants(const UnicodeString& source,
1479*0e209d39SAndroid Build Coastguard Worker const UnicodeString& target);
1480*0e209d39SAndroid Build Coastguard Worker
1481*0e209d39SAndroid Build Coastguard Worker /**
1482*0e209d39SAndroid Build Coastguard Worker * Non-mutexed internal method
1483*0e209d39SAndroid Build Coastguard Worker * @internal
1484*0e209d39SAndroid Build Coastguard Worker */
1485*0e209d39SAndroid Build Coastguard Worker static UnicodeString& _getAvailableVariant(int32_t index,
1486*0e209d39SAndroid Build Coastguard Worker const UnicodeString& source,
1487*0e209d39SAndroid Build Coastguard Worker const UnicodeString& target,
1488*0e209d39SAndroid Build Coastguard Worker UnicodeString& result);
1489*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */
1490*0e209d39SAndroid Build Coastguard Worker
1491*0e209d39SAndroid Build Coastguard Worker protected:
1492*0e209d39SAndroid Build Coastguard Worker
1493*0e209d39SAndroid Build Coastguard Worker /**
1494*0e209d39SAndroid Build Coastguard Worker * Set the ID of this transliterators. Subclasses shouldn't do
1495*0e209d39SAndroid Build Coastguard Worker * this, unless the underlying script behavior has changed.
1496*0e209d39SAndroid Build Coastguard Worker * @param id the new id t to be set.
1497*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4
1498*0e209d39SAndroid Build Coastguard Worker */
1499*0e209d39SAndroid Build Coastguard Worker void setID(const UnicodeString& id);
1500*0e209d39SAndroid Build Coastguard Worker
1501*0e209d39SAndroid Build Coastguard Worker public:
1502*0e209d39SAndroid Build Coastguard Worker
1503*0e209d39SAndroid Build Coastguard Worker /**
1504*0e209d39SAndroid Build Coastguard Worker * Return the class ID for this class. This is useful only for
1505*0e209d39SAndroid Build Coastguard Worker * comparing to a return value from getDynamicClassID().
1506*0e209d39SAndroid Build Coastguard Worker * Note that Transliterator is an abstract base class, and therefor
1507*0e209d39SAndroid Build Coastguard Worker * no fully constructed object will have a dynamic
1508*0e209d39SAndroid Build Coastguard Worker * UCLassID that equals the UClassID returned from
1509*0e209d39SAndroid Build Coastguard Worker * TRansliterator::getStaticClassID().
1510*0e209d39SAndroid Build Coastguard Worker * @return The class ID for class Transliterator.
1511*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1512*0e209d39SAndroid Build Coastguard Worker */
1513*0e209d39SAndroid Build Coastguard Worker static UClassID U_EXPORT2 getStaticClassID();
1514*0e209d39SAndroid Build Coastguard Worker
1515*0e209d39SAndroid Build Coastguard Worker /**
1516*0e209d39SAndroid Build Coastguard Worker * Returns a unique class ID <b>polymorphically</b>. This method
1517*0e209d39SAndroid Build Coastguard Worker * is to implement a simple version of RTTI, since not all C++
1518*0e209d39SAndroid Build Coastguard Worker * compilers support genuine RTTI. Polymorphic operator==() and
1519*0e209d39SAndroid Build Coastguard Worker * clone() methods call this method.
1520*0e209d39SAndroid Build Coastguard Worker *
1521*0e209d39SAndroid Build Coastguard Worker * <p>Concrete subclasses of Transliterator must use the
1522*0e209d39SAndroid Build Coastguard Worker * UOBJECT_DEFINE_RTTI_IMPLEMENTATION macro from
1523*0e209d39SAndroid Build Coastguard Worker * uobject.h to provide the RTTI functions.
1524*0e209d39SAndroid Build Coastguard Worker *
1525*0e209d39SAndroid Build Coastguard Worker * @return The class ID for this object. All objects of a given
1526*0e209d39SAndroid Build Coastguard Worker * class have the same class ID. Objects of other classes have
1527*0e209d39SAndroid Build Coastguard Worker * different class IDs.
1528*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1529*0e209d39SAndroid Build Coastguard Worker */
1530*0e209d39SAndroid Build Coastguard Worker virtual UClassID getDynamicClassID() const override = 0;
1531*0e209d39SAndroid Build Coastguard Worker
1532*0e209d39SAndroid Build Coastguard Worker private:
1533*0e209d39SAndroid Build Coastguard Worker static UBool initializeRegistry(UErrorCode &status);
1534*0e209d39SAndroid Build Coastguard Worker
1535*0e209d39SAndroid Build Coastguard Worker public:
1536*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_OBSOLETE_API
1537*0e209d39SAndroid Build Coastguard Worker /**
1538*0e209d39SAndroid Build Coastguard Worker * Return the number of IDs currently registered with the system.
1539*0e209d39SAndroid Build Coastguard Worker * To retrieve the actual IDs, call getAvailableID(i) with
1540*0e209d39SAndroid Build Coastguard Worker * i from 0 to countAvailableIDs() - 1.
1541*0e209d39SAndroid Build Coastguard Worker * @return the number of IDs currently registered with the system.
1542*0e209d39SAndroid Build Coastguard Worker * @obsolete ICU 3.4 use getAvailableIDs() instead
1543*0e209d39SAndroid Build Coastguard Worker */
1544*0e209d39SAndroid Build Coastguard Worker static int32_t U_EXPORT2 countAvailableIDs();
1545*0e209d39SAndroid Build Coastguard Worker
1546*0e209d39SAndroid Build Coastguard Worker /**
1547*0e209d39SAndroid Build Coastguard Worker * Return the index-th available ID. index must be between 0
1548*0e209d39SAndroid Build Coastguard Worker * and countAvailableIDs() - 1, inclusive. If index is out of
1549*0e209d39SAndroid Build Coastguard Worker * range, the result of getAvailableID(0) is returned.
1550*0e209d39SAndroid Build Coastguard Worker * @param index the given ID index.
1551*0e209d39SAndroid Build Coastguard Worker * @return the index-th available ID. index must be between 0
1552*0e209d39SAndroid Build Coastguard Worker * and countAvailableIDs() - 1, inclusive. If index is out of
1553*0e209d39SAndroid Build Coastguard Worker * range, the result of getAvailableID(0) is returned.
1554*0e209d39SAndroid Build Coastguard Worker * @obsolete ICU 3.4 use getAvailableIDs() instead; this function
1555*0e209d39SAndroid Build Coastguard Worker * is not thread safe, since it returns a reference to storage that
1556*0e209d39SAndroid Build Coastguard Worker * may become invalid if another thread calls unregister
1557*0e209d39SAndroid Build Coastguard Worker */
1558*0e209d39SAndroid Build Coastguard Worker static const UnicodeString& U_EXPORT2 getAvailableID(int32_t index);
1559*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_OBSOLETE_API */
1560*0e209d39SAndroid Build Coastguard Worker };
1561*0e209d39SAndroid Build Coastguard Worker
getMaximumContextLength()1562*0e209d39SAndroid Build Coastguard Worker inline int32_t Transliterator::getMaximumContextLength() const {
1563*0e209d39SAndroid Build Coastguard Worker return maximumContextLength;
1564*0e209d39SAndroid Build Coastguard Worker }
1565*0e209d39SAndroid Build Coastguard Worker
setID(const UnicodeString & id)1566*0e209d39SAndroid Build Coastguard Worker inline void Transliterator::setID(const UnicodeString& id) {
1567*0e209d39SAndroid Build Coastguard Worker ID = id;
1568*0e209d39SAndroid Build Coastguard Worker // NUL-terminate the ID string, which is a non-aliased copy.
1569*0e209d39SAndroid Build Coastguard Worker ID.append((char16_t)0);
1570*0e209d39SAndroid Build Coastguard Worker ID.truncate(ID.length()-1);
1571*0e209d39SAndroid Build Coastguard Worker }
1572*0e209d39SAndroid Build Coastguard Worker
1573*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
integerToken(int32_t i)1574*0e209d39SAndroid Build Coastguard Worker inline Transliterator::Token Transliterator::integerToken(int32_t i) {
1575*0e209d39SAndroid Build Coastguard Worker Token t;
1576*0e209d39SAndroid Build Coastguard Worker t.integer = i;
1577*0e209d39SAndroid Build Coastguard Worker return t;
1578*0e209d39SAndroid Build Coastguard Worker }
1579*0e209d39SAndroid Build Coastguard Worker
pointerToken(void * p)1580*0e209d39SAndroid Build Coastguard Worker inline Transliterator::Token Transliterator::pointerToken(void* p) {
1581*0e209d39SAndroid Build Coastguard Worker Token t;
1582*0e209d39SAndroid Build Coastguard Worker t.pointer = p;
1583*0e209d39SAndroid Build Coastguard Worker return t;
1584*0e209d39SAndroid Build Coastguard Worker }
1585*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */
1586*0e209d39SAndroid Build Coastguard Worker
1587*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
1588*0e209d39SAndroid Build Coastguard Worker
1589*0e209d39SAndroid Build Coastguard Worker #endif /* #if !UCONFIG_NO_TRANSLITERATION */
1590*0e209d39SAndroid Build Coastguard Worker
1591*0e209d39SAndroid Build Coastguard Worker #endif /* U_SHOW_CPLUSPLUS_API */
1592*0e209d39SAndroid Build Coastguard Worker
1593*0e209d39SAndroid Build Coastguard Worker #endif
1594