]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/unicode/translit.h
ICU-6.2.22.tar.gz
[apple/icu.git] / icuSources / i18n / unicode / translit.h
CommitLineData
b75a7d8f
A
1/*
2**********************************************************************
374ca955 3* Copyright (C) 1999-2004, International Business Machines
b75a7d8f
A
4* Corporation and others. All Rights Reserved.
5**********************************************************************
6* Date Name Description
7* 11/17/99 aliu Creation.
8**********************************************************************
9*/
10#ifndef TRANSLIT_H
11#define TRANSLIT_H
12
13#include "unicode/utypes.h"
14
15#if !UCONFIG_NO_TRANSLITERATION
16
17#include "unicode/uobject.h"
18#include "unicode/unistr.h"
19#include "unicode/parseerr.h"
20#include "unicode/utrans.h" // UTransPosition, UTransDirection
374ca955 21#include "unicode/strenum.h"
b75a7d8f
A
22
23U_NAMESPACE_BEGIN
24
25class UnicodeFilter;
26class UnicodeSet;
27class CompoundTransliterator;
28class TransliteratorParser;
29class NormalizationTransliterator;
30class TransliteratorIDParser;
31
32/**
33 * <code>Transliterator</code> is an abstract class that
34 * transliterates text from one format to another. The most common
35 * kind of transliterator is a script, or alphabet, transliterator.
36 * For example, a Russian to Latin transliterator changes Russian text
37 * written in Cyrillic characters to phonetically equivalent Latin
38 * characters. It does not <em>translate</em> Russian to English!
39 * Transliteration, unlike translation, operates on characters, without
40 * reference to the meanings of words and sentences.
41 *
42 * <p>Although script conversion is its most common use, a
43 * transliterator can actually perform a more general class of tasks.
44 * In fact, <code>Transliterator</code> defines a very general API
45 * which specifies only that a segment of the input text is replaced
46 * by new text. The particulars of this conversion are determined
47 * entirely by subclasses of <code>Transliterator</code>.
48 *
49 * <p><b>Transliterators are stateless</b>
50 *
51 * <p><code>Transliterator</code> objects are <em>stateless</em>; they
52 * retain no information between calls to
53 * <code>transliterate()</code>. (However, this does <em>not</em>
54 * mean that threads may share transliterators without synchronizing
55 * them. Transliterators are not immutable, so they must be
56 * synchronized when shared between threads.) This1 might seem to
57 * limit the complexity of the transliteration operation. In
58 * practice, subclasses perform complex transliterations by delaying
59 * the replacement of text until it is known that no other
60 * replacements are possible. In other words, although the
61 * <code>Transliterator</code> objects are stateless, the source text
62 * itself embodies all the needed information, and delayed operation
63 * allows arbitrary complexity.
64 *
65 * <p><b>Batch transliteration</b>
66 *
67 * <p>The simplest way to perform transliteration is all at once, on a
68 * string of existing text. This is referred to as <em>batch</em>
69 * transliteration. For example, given a string <code>input</code>
70 * and a transliterator <code>t</code>, the call
71 *
374ca955
A
72 * \htmlonly<blockquote>\endhtmlonly<code>String result = t.transliterate(input);
73 * </code>\htmlonly</blockquote>\endhtmlonly
b75a7d8f
A
74 *
75 * will transliterate it and return the result. Other methods allow
76 * the client to specify a substring to be transliterated and to use
374ca955 77 * {@link Replaceable } objects instead of strings, in order to
b75a7d8f
A
78 * preserve out-of-band information (such as text styles).
79 *
80 * <p><b>Keyboard transliteration</b>
81 *
82 * <p>Somewhat more involved is <em>keyboard</em>, or incremental
83 * transliteration. This is the transliteration of text that is
84 * arriving from some source (typically the user's keyboard) one
85 * character at a time, or in some other piecemeal fashion.
86 *
87 * <p>In keyboard transliteration, a <code>Replaceable</code> buffer
88 * stores the text. As text is inserted, as much as possible is
89 * transliterated on the fly. This means a GUI that displays the
90 * contents of the buffer may show text being modified as each new
91 * character arrives.
92 *
93 * <p>Consider the simple <code>RuleBasedTransliterator</code>:
94 *
374ca955 95 * \htmlonly<blockquote>\endhtmlonly<code>
b75a7d8f
A
96 * th&gt;{theta}<br>
97 * t&gt;{tau}
374ca955 98 * </code>\htmlonly</blockquote>\endhtmlonly
b75a7d8f
A
99 *
100 * When the user types 't', nothing will happen, since the
101 * transliterator is waiting to see if the next character is 'h'. To
102 * remedy this, we introduce the notion of a cursor, marked by a '|'
103 * in the output string:
104 *
374ca955 105 * \htmlonly<blockquote>\endhtmlonly<code>
b75a7d8f
A
106 * t&gt;|{tau}<br>
107 * {tau}h&gt;{theta}
374ca955 108 * </code>\htmlonly</blockquote>\endhtmlonly
b75a7d8f
A
109 *
110 * Now when the user types 't', tau appears, and if the next character
111 * is 'h', the tau changes to a theta. This is accomplished by
112 * maintaining a cursor position (independent of the insertion point,
113 * and invisible in the GUI) across calls to
114 * <code>transliterate()</code>. Typically, the cursor will
115 * be coincident with the insertion point, but in a case like the one
116 * above, it will precede the insertion point.
117 *
118 * <p>Keyboard transliteration methods maintain a set of three indices
119 * that are updated with each call to
120 * <code>transliterate()</code>, including the cursor, start,
121 * and limit. Since these indices are changed by the method, they are
122 * passed in an <code>int[]</code> array. The <code>START</code> index
123 * marks the beginning of the substring that the transliterator will
124 * look at. It is advanced as text becomes committed (but it is not
125 * the committed index; that's the <code>CURSOR</code>). The
126 * <code>CURSOR</code> index, described above, marks the point at
127 * which the transliterator last stopped, either because it reached
128 * the end, or because it required more characters to disambiguate
129 * between possible inputs. The <code>CURSOR</code> can also be
130 * explicitly set by rules in a <code>RuleBasedTransliterator</code>.
131 * Any characters before the <code>CURSOR</code> index are frozen;
132 * future keyboard transliteration calls within this input sequence
133 * will not change them. New text is inserted at the
134 * <code>LIMIT</code> index, which marks the end of the substring that
135 * the transliterator looks at.
136 *
137 * <p>Because keyboard transliteration assumes that more characters
138 * are to arrive, it is conservative in its operation. It only
139 * transliterates when it can do so unambiguously. Otherwise it waits
140 * for more characters to arrive. When the client code knows that no
141 * more characters are forthcoming, perhaps because the user has
142 * performed some input termination operation, then it should call
143 * <code>finishTransliteration()</code> to complete any
144 * pending transliterations.
145 *
146 * <p><b>Inverses</b>
147 *
148 * <p>Pairs of transliterators may be inverses of one another. For
149 * example, if transliterator <b>A</b> transliterates characters by
150 * incrementing their Unicode value (so "abc" -> "def"), and
151 * transliterator <b>B</b> decrements character values, then <b>A</b>
152 * is an inverse of <b>B</b> and vice versa. If we compose <b>A</b>
153 * with <b>B</b> in a compound transliterator, the result is the
154 * indentity transliterator, that is, a transliterator that does not
155 * change its input text.
156 *
157 * The <code>Transliterator</code> method <code>getInverse()</code>
158 * returns a transliterator's inverse, if one exists, or
159 * <code>null</code> otherwise. However, the result of
160 * <code>getInverse()</code> usually will <em>not</em> be a true
161 * mathematical inverse. This is because true inverse transliterators
162 * are difficult to formulate. For example, consider two
163 * transliterators: <b>AB</b>, which transliterates the character 'A'
164 * to 'B', and <b>BA</b>, which transliterates 'B' to 'A'. It might
165 * seem that these are exact inverses, since
166 *
374ca955
A
167 * \htmlonly<blockquote>\endhtmlonly"A" x <b>AB</b> -> "B"<br>
168 * "B" x <b>BA</b> -> "A"\htmlonly</blockquote>\endhtmlonly
b75a7d8f
A
169 *
170 * where 'x' represents transliteration. However,
171 *
374ca955
A
172 * \htmlonly<blockquote>\endhtmlonly"ABCD" x <b>AB</b> -> "BBCD"<br>
173 * "BBCD" x <b>BA</b> -> "AACD"\htmlonly</blockquote>\endhtmlonly
b75a7d8f
A
174 *
175 * so <b>AB</b> composed with <b>BA</b> is not the
176 * identity. Nonetheless, <b>BA</b> may be usefully considered to be
177 * <b>AB</b>'s inverse, and it is on this basis that
178 * <b>AB</b><code>.getInverse()</code> could legitimately return
179 * <b>BA</b>.
180 *
181 * <p><b>IDs and display names</b>
182 *
183 * <p>A transliterator is designated by a short identifier string or
184 * <em>ID</em>. IDs follow the format <em>source-destination</em>,
185 * where <em>source</em> describes the entity being replaced, and
186 * <em>destination</em> describes the entity replacing
187 * <em>source</em>. The entities may be the names of scripts,
188 * particular sequences of characters, or whatever else it is that the
189 * transliterator converts to or from. For example, a transliterator
190 * from Russian to Latin might be named "Russian-Latin". A
191 * transliterator from keyboard escape sequences to Latin-1 characters
192 * might be named "KeyboardEscape-Latin1". By convention, system
193 * entity names are in English, with the initial letters of words
194 * capitalized; user entity names may follow any format so long as
195 * they do not contain dashes.
196 *
197 * <p>In addition to programmatic IDs, transliterator objects have
198 * display names for presentation in user interfaces, returned by
374ca955 199 * {@link #getDisplayName }.
b75a7d8f
A
200 *
201 * <p><b>Factory methods and registration</b>
202 *
203 * <p>In general, client code should use the factory method
374ca955 204 * {@link #createInstance } to obtain an instance of a
b75a7d8f
A
205 * transliterator given its ID. Valid IDs may be enumerated using
206 * <code>getAvailableIDs()</code>. Since transliterators are mutable,
374ca955 207 * multiple calls to {@link #createInstance } with the same ID will
b75a7d8f
A
208 * return distinct objects.
209 *
210 * <p>In addition to the system transliterators registered at startup,
211 * user transliterators may be registered by calling
212 * <code>registerInstance()</code> at run time. A registered instance
374ca955 213 * acts a template; future calls to {@link #createInstance } with the ID
b75a7d8f
A
214 * of the registered object return clones of that object. Thus any
215 * object passed to <tt>registerInstance()</tt> must implement
216 * <tt>clone()</tt> propertly. To register a transliterator subclass
217 * without instantiating it (until it is needed), users may call
374ca955 218 * {@link #registerFactory }. In this case, the objects are
b75a7d8f
A
219 * instantiated by invoking the zero-argument public constructor of
220 * the class.
221 *
222 * <p><b>Subclassing</b>
223 *
224 * Subclasses must implement the abstract method
225 * <code>handleTransliterate()</code>. <p>Subclasses should override
226 * the <code>transliterate()</code> method taking a
227 * <code>Replaceable</code> and the <code>transliterate()</code>
228 * method taking a <code>String</code> and <code>StringBuffer</code>
229 * if the performance of these methods can be improved over the
230 * performance obtained by the default implementations in this class.
231 *
232 * @author Alan Liu
233 * @stable ICU 2.0
234 */
235class U_I18N_API Transliterator : public UObject {
236
237private:
238
239 /**
240 * Programmatic name, e.g., "Latin-Arabic".
241 */
242 UnicodeString ID;
243
244 /**
245 * This transliterator's filter. Any character for which
246 * <tt>filter.contains()</tt> returns <tt>false</tt> will not be
247 * altered by this transliterator. If <tt>filter</tt> is
248 * <tt>null</tt> then no filtering is applied.
249 */
250 UnicodeFilter* filter;
251
252 int32_t maximumContextLength;
253
254 public:
255
256 /**
257 * A context integer or pointer for a factory function, passed by
258 * value.
374ca955 259 * @stable ICU 2.4
b75a7d8f
A
260 */
261 union Token {
262 /**
263 * This token, interpreted as a 32-bit integer.
374ca955 264 * @stable ICU 2.4
b75a7d8f
A
265 */
266 int32_t integer;
267 /**
268 * This token, interpreted as a native pointer.
374ca955 269 * @stable ICU 2.4
b75a7d8f
A
270 */
271 void* pointer;
272 };
273
274 /**
275 * Return a token containing an integer.
276 * @return a token containing an integer.
374ca955 277 * @internal
b75a7d8f
A
278 */
279 inline static Token integerToken(int32_t);
280
281 /**
282 * Return a token containing a pointer.
283 * @return a token containing a pointer.
374ca955 284 * @internal
b75a7d8f
A
285 */
286 inline static Token pointerToken(void*);
287
288 /**
289 * A function that creates and returns a Transliterator. When
290 * invoked, it will be passed the ID string that is being
291 * instantiated, together with the context pointer that was passed
292 * in when the factory function was first registered. Many
293 * factory functions will ignore both parameters, however,
294 * functions that are registered to more than one ID may use the
295 * ID or the context parameter to parameterize the transliterator
296 * they create.
297 * @param ID the string identifier for this transliterator
298 * @param context a context pointer that will be stored and
299 * later passed to the factory function when an ID matching
300 * the registration ID is being instantiated with this factory.
374ca955 301 * @stable ICU 2.4
b75a7d8f 302 */
374ca955 303 typedef Transliterator* (U_EXPORT2 *Factory)(const UnicodeString& ID, Token context);
b75a7d8f
A
304
305protected:
306
307 /**
308 * Default constructor.
309 * @param ID the string identifier for this transliterator
310 * @param adoptedFilter the filter. Any character for which
311 * <tt>filter.contains()</tt> returns <tt>false</tt> will not be
312 * altered by this transliterator. If <tt>filter</tt> is
313 * <tt>null</tt> then no filtering is applied.
374ca955 314 * @stable ICU 2.4
b75a7d8f
A
315 */
316 Transliterator(const UnicodeString& ID, UnicodeFilter* adoptedFilter);
317
318 /**
319 * Copy constructor.
374ca955 320 * @stable ICU 2.4
b75a7d8f
A
321 */
322 Transliterator(const Transliterator&);
323
324 /**
325 * Assignment operator.
374ca955 326 * @stable ICU 2.4
b75a7d8f
A
327 */
328 Transliterator& operator=(const Transliterator&);
374ca955 329
b75a7d8f
A
330 /**
331 * Create a transliterator from a basic ID. This is an ID
332 * containing only the forward direction source, target, and
333 * variant.
334 * @param id a basic ID of the form S-T or S-T/V.
335 * @param canon canonical ID to assign to the object, or
336 * NULL to leave the ID unchanged
337 * @return a newly created Transliterator or null if the ID is
338 * invalid.
374ca955 339 * @stable ICU 2.4
b75a7d8f
A
340 */
341 static Transliterator* createBasicInstance(const UnicodeString& id,
342 const UnicodeString* canon);
343
344 friend class TransliteratorParser; // for parseID()
345 friend class TransliteratorIDParser; // for createBasicInstance()
346
347public:
348
349 /**
350 * Destructor.
351 * @stable ICU 2.0
352 */
353 virtual ~Transliterator();
354
355 /**
356 * Implements Cloneable.
357 * All subclasses are encouraged to implement this method if it is
358 * possible and reasonable to do so. Subclasses that are to be
374ca955 359 * registered with the system using <tt>registerInstance()</tt>
b75a7d8f
A
360 * are required to implement this method. If a subclass does not
361 * implement clone() properly and is registered with the system
362 * using registerInstance(), then the default clone() implementation
363 * will return null, and calls to createInstance() will fail.
364 *
365 * @return a copy of the object.
366 * @see #registerInstance
367 * @stable ICU 2.0
368 */
369 virtual Transliterator* clone() const { return 0; }
370
371 /**
372 * Transliterates a segment of a string, with optional filtering.
373 *
374 * @param text the string to be transliterated
375 * @param start the beginning index, inclusive; <code>0 <= start
376 * <= limit</code>.
377 * @param limit the ending index, exclusive; <code>start <= limit
378 * <= text.length()</code>.
379 * @return The new limit index. The text previously occupying <code>[start,
380 * limit)</code> has been transliterated, possibly to a string of a different
381 * length, at <code>[start, </code><em>new-limit</em><code>)</code>, where
382 * <em>new-limit</em> is the return value. If the input offsets are out of bounds,
383 * the returned value is -1 and the input string remains unchanged.
384 * @stable ICU 2.0
385 */
386 virtual int32_t transliterate(Replaceable& text,
387 int32_t start, int32_t limit) const;
388
389 /**
390 * Transliterates an entire string in place. Convenience method.
391 * @param text the string to be transliterated
392 * @stable ICU 2.0
393 */
394 virtual void transliterate(Replaceable& text) const;
395
396 /**
397 * Transliterates the portion of the text buffer that can be
398 * transliterated unambiguosly after new text has been inserted,
399 * typically as a result of a keyboard event. The new text in
400 * <code>insertion</code> will be inserted into <code>text</code>
401 * at <code>index.limit</code>, advancing
402 * <code>index.limit</code> by <code>insertion.length()</code>.
403 * Then the transliterator will try to transliterate characters of
404 * <code>text</code> between <code>index.cursor</code> and
405 * <code>index.limit</code>. Characters before
406 * <code>index.cursor</code> will not be changed.
407 *
408 * <p>Upon return, values in <code>index</code> will be updated.
409 * <code>index.start</code> will be advanced to the first
410 * character that future calls to this method will read.
411 * <code>index.cursor</code> and <code>index.limit</code> will
412 * be adjusted to delimit the range of text that future calls to
413 * this method may change.
414 *
415 * <p>Typical usage of this method begins with an initial call
416 * with <code>index.start</code> and <code>index.limit</code>
417 * set to indicate the portion of <code>text</code> to be
418 * transliterated, and <code>index.cursor == index.start</code>.
419 * Thereafter, <code>index</code> can be used without
420 * modification in future calls, provided that all changes to
421 * <code>text</code> are made via this method.
422 *
423 * <p>This method assumes that future calls may be made that will
424 * insert new text into the buffer. As a result, it only performs
425 * unambiguous transliterations. After the last call to this
426 * method, there may be untransliterated text that is waiting for
427 * more input to resolve an ambiguity. In order to perform these
428 * pending transliterations, clients should call {@link
374ca955 429 * #finishTransliteration } after the last call to this
b75a7d8f
A
430 * method has been made.
431 *
432 * @param text the buffer holding transliterated and untransliterated text
433 * @param index an array of three integers.
434 *
435 * <ul><li><code>index.start</code>: the beginning index,
436 * inclusive; <code>0 <= index.start <= index.limit</code>.
437 *
438 * <li><code>index.limit</code>: the ending index, exclusive;
439 * <code>index.start <= index.limit <= text.length()</code>.
440 * <code>insertion</code> is inserted at
441 * <code>index.limit</code>.
442 *
443 * <li><code>index.cursor</code>: the next character to be
444 * considered for transliteration; <code>index.start <=
445 * index.cursor <= index.limit</code>. Characters before
446 * <code>index.cursor</code> will not be changed by future calls
447 * to this method.</ul>
448 *
449 * @param insertion text to be inserted and possibly
450 * transliterated into the translation buffer at
451 * <code>index.limit</code>. If <code>null</code> then no text
452 * is inserted.
453 * @param status Output param to filled in with a success or an error.
454 * @see #handleTransliterate
455 * @exception IllegalArgumentException if <code>index</code>
456 * is invalid
457 * @see UTransPosition
458 * @stable ICU 2.0
459 */
460 virtual void transliterate(Replaceable& text, UTransPosition& index,
461 const UnicodeString& insertion,
462 UErrorCode& status) const;
463
464 /**
465 * Transliterates the portion of the text buffer that can be
466 * transliterated unambiguosly after a new character has been
467 * inserted, typically as a result of a keyboard event. This is a
468 * convenience method; see {@link
374ca955
A
469 * #transliterate(Replaceable&, UTransPosition&, const UnicodeString&, UErrorCode&) const}
470 * for details.
b75a7d8f
A
471 * @param text the buffer holding transliterated and
472 * untransliterated text
473 * @param index an array of three integers. See {@link
374ca955 474 * #transliterate(Replaceable&, UTransPosition&, const UnicodeString&, UErrorCode&) const }.
b75a7d8f
A
475 * @param insertion text to be inserted and possibly
476 * transliterated into the translation buffer at
477 * <code>index.limit</code>.
478 * @param status Output param to filled in with a success or an error.
374ca955 479 * @see #transliterate(Replaceable&, UTransPosition&, const UnicodeString&, UErrorCode&) const
b75a7d8f
A
480 * @stable ICU 2.0
481 */
482 virtual void transliterate(Replaceable& text, UTransPosition& index,
483 UChar32 insertion,
484 UErrorCode& status) const;
485
486 /**
487 * Transliterates the portion of the text buffer that can be
488 * transliterated unambiguosly. This is a convenience method; see
374ca955
A
489 * {@link
490 * #transliterate(Replaceable&, UTransPosition&, const UnicodeString&, UErrorCode&) const }
491 * for details.
b75a7d8f
A
492 * @param text the buffer holding transliterated and
493 * untransliterated text
494 * @param index an array of three integers. See {@link
374ca955 495 * #transliterate(Replaceable&, UTransPosition&, const UnicodeString&, UErrorCode&) const }.
b75a7d8f
A
496 * @param status Output param to filled in with a success or an error.
497 * @see #transliterate(Replaceable, int[], String)
498 * @stable ICU 2.0
499 */
500 virtual void transliterate(Replaceable& text, UTransPosition& index,
501 UErrorCode& status) const;
502
503 /**
504 * Finishes any pending transliterations that were waiting for
505 * more characters. Clients should call this method as the last
506 * call after a sequence of one or more calls to
507 * <code>transliterate()</code>.
508 * @param text the buffer holding transliterated and
509 * untransliterated text.
510 * @param index the array of indices previously passed to {@link
374ca955 511 * #transliterate }
b75a7d8f
A
512 * @stable ICU 2.0
513 */
514 virtual void finishTransliteration(Replaceable& text,
515 UTransPosition& index) const;
516
517private:
518
519 /**
520 * This internal method does incremental transliteration. If the
521 * 'insertion' is non-null then we append it to 'text' before
522 * proceeding. This method calls through to the pure virtual
523 * framework method handleTransliterate() to do the actual
524 * work.
525 * @param text the buffer holding transliterated and
526 * untransliterated text
527 * @param index an array of three integers. See {@link
528 * #transliterate(Replaceable, int[], String)}.
529 * @param insertion text to be inserted and possibly
530 * transliterated into the translation buffer at
531 * <code>index.limit</code>.
532 * @param status Output param to filled in with a success or an error.
533 */
534 void _transliterate(Replaceable& text,
535 UTransPosition& index,
536 const UnicodeString* insertion,
537 UErrorCode &status) const;
538
539protected:
540
541 /**
542 * Abstract method that concrete subclasses define to implement
543 * their transliteration algorithm. This method handles both
544 * incremental and non-incremental transliteration. Let
545 * <code>originalStart</code> refer to the value of
546 * <code>pos.start</code> upon entry.
374ca955 547 *
b75a7d8f
A
548 * <ul>
549 * <li>If <code>incremental</code> is false, then this method
550 * should transliterate all characters between
551 * <code>pos.start</code> and <code>pos.limit</code>. Upon return
552 * <code>pos.start</code> must == <code> pos.limit</code>.</li>
553 *
554 * <li>If <code>incremental</code> is true, then this method
555 * should transliterate all characters between
556 * <code>pos.start</code> and <code>pos.limit</code> that can be
557 * unambiguously transliterated, regardless of future insertions
558 * of text at <code>pos.limit</code>. Upon return,
559 * <code>pos.start</code> should be in the range
560 * [<code>originalStart</code>, <code>pos.limit</code>).
561 * <code>pos.start</code> should be positioned such that
562 * characters [<code>originalStart</code>, <code>
563 * pos.start</code>) will not be changed in the future by this
564 * transliterator and characters [<code>pos.start</code>,
565 * <code>pos.limit</code>) are unchanged.</li>
566 * </ul>
374ca955 567 *
b75a7d8f
A
568 * <p>Implementations of this method should also obey the
569 * following invariants:</p>
570 *
571 * <ul>
572 * <li> <code>pos.limit</code> and <code>pos.contextLimit</code>
573 * should be updated to reflect changes in length of the text
574 * between <code>pos.start</code> and <code>pos.limit</code>. The
575 * difference <code> pos.contextLimit - pos.limit</code> should
576 * not change.</li>
577 *
578 * <li><code>pos.contextStart</code> should not change.</li>
579 *
580 * <li>Upon return, neither <code>pos.start</code> nor
581 * <code>pos.limit</code> should be less than
582 * <code>originalStart</code>.</li>
583 *
584 * <li>Text before <code>originalStart</code> and text after
585 * <code>pos.limit</code> should not change.</li>
586 *
587 * <li>Text before <code>pos.contextStart</code> and text after
588 * <code> pos.contextLimit</code> should be ignored.</li>
589 * </ul>
374ca955 590 *
b75a7d8f
A
591 * <p>Subclasses may safely assume that all characters in
592 * [<code>pos.start</code>, <code>pos.limit</code>) are filtered.
593 * In other words, the filter has already been applied by the time
594 * this method is called. See
595 * <code>filteredTransliterate()</code>.
374ca955 596 *
b75a7d8f
A
597 * <p>This method is <b>not</b> for public consumption. Calling
598 * this method directly will transliterate
599 * [<code>pos.start</code>, <code>pos.limit</code>) without
600 * applying the filter. End user code should call <code>
601 * transliterate()</code> instead of this method. Subclass code
602 * should call <code>filteredTransliterate()</code> instead of
603 * this method.<p>
374ca955 604 *
b75a7d8f
A
605 * @param text the buffer holding transliterated and
606 * untransliterated text
374ca955 607 *
b75a7d8f
A
608 * @param pos the indices indicating the start, limit, context
609 * start, and context limit of the text.
374ca955 610 *
b75a7d8f
A
611 * @param incremental if true, assume more text may be inserted at
612 * <code>pos.limit</code> and act accordingly. Otherwise,
613 * transliterate all text between <code>pos.start</code> and
614 * <code>pos.limit</code> and move <code>pos.start</code> up to
615 * <code>pos.limit</code>.
374ca955 616 *
b75a7d8f 617 * @see #transliterate
374ca955 618 * @stable ICU 2.4
b75a7d8f
A
619 */
620 virtual void handleTransliterate(Replaceable& text,
621 UTransPosition& pos,
622 UBool incremental) const = 0;
623
624 /**
625 * Transliterate a substring of text, as specified by index, taking filters
626 * into account. This method is for subclasses that need to delegate to
627 * another transliterator, such as CompoundTransliterator.
628 * @param text the text to be transliterated
629 * @param index the position indices
630 * @param incremental if TRUE, then assume more characters may be inserted
631 * at index.limit, and postpone processing to accomodate future incoming
632 * characters
374ca955 633 * @stable ICU 2.4
b75a7d8f
A
634 */
635 virtual void filteredTransliterate(Replaceable& text,
636 UTransPosition& index,
637 UBool incremental) const;
638
639 friend class CompoundTransliterator; // for filteredTransliterate()
640 friend class AnyTransliterator; // for filteredTransliterate()
641
642private:
643
644 /**
645 * Top-level transliteration method, handling filtering, incremental and
646 * non-incremental transliteration, and rollback. All transliteration
647 * public API methods eventually call this method with a rollback argument
648 * of TRUE. Other entities may call this method but rollback should be
649 * FALSE.
374ca955 650 *
b75a7d8f
A
651 * <p>If this transliterator has a filter, break up the input text into runs
652 * of unfiltered characters. Pass each run to
653 * <subclass>.handleTransliterate().
654 *
655 * <p>In incremental mode, if rollback is TRUE, perform a special
656 * incremental procedure in which several passes are made over the input
657 * text, adding one character at a time, and committing successful
658 * transliterations as they occur. Unsuccessful transliterations are rolled
659 * back and retried with additional characters to give correct results.
660 *
661 * @param text the text to be transliterated
662 * @param index the position indices
663 * @param incremental if TRUE, then assume more characters may be inserted
664 * at index.limit, and postpone processing to accomodate future incoming
665 * characters
666 * @param rollback if TRUE and if incremental is TRUE, then perform special
667 * incremental processing, as described above, and undo partial
668 * transliterations where necessary. If incremental is FALSE then this
669 * parameter is ignored.
670 */
671 virtual void filteredTransliterate(Replaceable& text,
672 UTransPosition& index,
673 UBool incremental,
674 UBool rollback) const;
675
676public:
677
678 /**
679 * Returns the length of the longest context required by this transliterator.
680 * This is <em>preceding</em> context. The default implementation supplied
681 * by <code>Transliterator</code> returns zero; subclasses
682 * that use preceding context should override this method to return the
683 * correct value. For example, if a transliterator translates "ddd" (where
684 * d is any digit) to "555" when preceded by "(ddd)", then the preceding
685 * context length is 5, the length of "(ddd)".
686 *
687 * @return The maximum number of preceding context characters this
688 * transliterator needs to examine
689 * @stable ICU 2.0
690 */
691 int32_t getMaximumContextLength(void) const;
692
693protected:
694
695 /**
696 * Method for subclasses to use to set the maximum context length.
697 * @param maxContextLength the new value to be set.
698 * @see #getMaximumContextLength
374ca955 699 * @stable ICU 2.4
b75a7d8f
A
700 */
701 void setMaximumContextLength(int32_t maxContextLength);
702
703public:
704
705 /**
706 * Returns a programmatic identifier for this transliterator.
707 * If this identifier is passed to <code>createInstance()</code>, it
708 * will return this object, if it has been registered.
709 * @return a programmatic identifier for this transliterator.
710 * @see #registerInstance
374ca955 711 * @see #registerFactory
b75a7d8f
A
712 * @see #getAvailableIDs
713 * @stable ICU 2.0
714 */
715 virtual const UnicodeString& getID(void) const;
716
717 /**
718 * Returns a name for this transliterator that is appropriate for
719 * display to the user in the default locale. See {@link
374ca955 720 * #getDisplayName } for details.
b75a7d8f
A
721 * @param ID the string identifier for this transliterator
722 * @param result Output param to receive the display name
723 * @return A reference to 'result'.
724 * @stable ICU 2.0
725 */
374ca955 726 static UnicodeString& U_EXPORT2 getDisplayName(const UnicodeString& ID,
b75a7d8f
A
727 UnicodeString& result);
728
729 /**
730 * Returns a name for this transliterator that is appropriate for
731 * display to the user in the given locale. This name is taken
732 * from the locale resource data in the standard manner of the
733 * <code>java.text</code> package.
734 *
735 * <p>If no localized names exist in the system resource bundles,
736 * a name is synthesized using a localized
737 * <code>MessageFormat</code> pattern from the resource data. The
738 * arguments to this pattern are an integer followed by one or two
739 * strings. The integer is the number of strings, either 1 or 2.
740 * The strings are formed by splitting the ID for this
741 * transliterator at the first '-'. If there is no '-', then the
742 * entire ID forms the only string.
743 * @param ID the string identifier for this transliterator
744 * @param inLocale the Locale in which the display name should be
745 * localized.
746 * @param result Output param to receive the display name
747 * @return A reference to 'result'.
748 * @stable ICU 2.0
749 */
374ca955 750 static UnicodeString& U_EXPORT2 getDisplayName(const UnicodeString& ID,
b75a7d8f
A
751 const Locale& inLocale,
752 UnicodeString& result);
753
754 /**
755 * Returns the filter used by this transliterator, or <tt>NULL</tt>
756 * if this transliterator uses no filter.
757 * @return the filter used by this transliterator, or <tt>NULL</tt>
758 * if this transliterator uses no filter.
759 * @stable ICU 2.0
760 */
761 const UnicodeFilter* getFilter(void) const;
762
763 /**
764 * Returns the filter used by this transliterator, or <tt>NULL</tt> if this
765 * transliterator uses no filter. The caller must eventually delete the
766 * result. After this call, this transliterator's filter is set to
767 * <tt>NULL</tt>.
768 * @return the filter used by this transliterator, or <tt>NULL</tt> if this
769 * transliterator uses no filter.
374ca955 770 * @stable ICU 2.4
b75a7d8f
A
771 */
772 UnicodeFilter* orphanFilter(void);
773
774 /**
775 * Changes the filter used by this transliterator. If the filter
776 * is set to <tt>null</tt> then no filtering will occur.
777 *
778 * <p>Callers must take care if a transliterator is in use by
779 * multiple threads. The filter should not be changed by one
780 * thread while another thread may be transliterating.
781 * @param adoptedFilter the new filter to be adopted.
782 * @stable ICU 2.0
783 */
784 void adoptFilter(UnicodeFilter* adoptedFilter);
785
786 /**
787 * Returns this transliterator's inverse. See the class
788 * documentation for details. This implementation simply inverts
789 * the two entities in the ID and attempts to retrieve the
790 * resulting transliterator. That is, if <code>getID()</code>
791 * returns "A-B", then this method will return the result of
792 * <code>createInstance("B-A")</code>, or <code>null</code> if that
793 * call fails.
794 *
795 * <p>Subclasses with knowledge of their inverse may wish to
796 * override this method.
797 *
798 * @param status Output param to filled in with a success or an error.
799 * @return a transliterator that is an inverse, not necessarily
800 * exact, of this transliterator, or <code>null</code> if no such
801 * transliterator is registered.
802 * @see #registerInstance
803 * @stable ICU 2.0
804 */
805 Transliterator* createInverse(UErrorCode& status) const;
806
807 /**
808 * Returns a <code>Transliterator</code> object given its ID.
809 * The ID must be either a system transliterator ID or a ID registered
810 * using <code>registerInstance()</code>.
811 *
812 * @param ID a valid ID, as enumerated by <code>getAvailableIDs()</code>
813 * @param dir either FORWARD or REVERSE.
374ca955 814 * @param parseError Struct to recieve information on position
b75a7d8f
A
815 * of error if an error is encountered
816 * @param status Output param to filled in with a success or an error.
817 * @return A <code>Transliterator</code> object with the given ID
818 * @see #registerInstance
819 * @see #getAvailableIDs
820 * @see #getID
821 * @stable ICU 2.0
822 */
374ca955 823 static Transliterator* U_EXPORT2 createInstance(const UnicodeString& ID,
b75a7d8f
A
824 UTransDirection dir,
825 UParseError& parseError,
826 UErrorCode& status);
827
828 /**
829 * Returns a <code>Transliterator</code> object given its ID.
830 * The ID must be either a system transliterator ID or a ID registered
831 * using <code>registerInstance()</code>.
832 * @param ID a valid ID, as enumerated by <code>getAvailableIDs()</code>
833 * @param dir either FORWARD or REVERSE.
834 * @param status Output param to filled in with a success or an error.
835 * @return A <code>Transliterator</code> object with the given ID
836 * @stable ICU 2.0
837 */
374ca955 838 static Transliterator* U_EXPORT2 createInstance(const UnicodeString& ID,
b75a7d8f
A
839 UTransDirection dir,
840 UErrorCode& status);
374ca955 841
b75a7d8f
A
842 /**
843 * Returns a <code>Transliterator</code> object constructed from
844 * the given rule string. This will be a RuleBasedTransliterator,
845 * if the rule string contains only rules, or a
846 * CompoundTransliterator, if it contains ID blocks, or a
847 * NullTransliterator, if it contains ID blocks which parse as
848 * empty for the given direction.
849 * @param ID the id for the transliterator.
850 * @param rules rules, separated by ';'
851 * @param dir either FORWARD or REVERSE.
374ca955 852 * @param parseError Struct to recieve information on position
b75a7d8f
A
853 * of error if an error is encountered
854 * @param status Output param set to success/failure code.
855 * @stable ICU 2.0
856 */
374ca955 857 static Transliterator* U_EXPORT2 createFromRules(const UnicodeString& ID,
b75a7d8f
A
858 const UnicodeString& rules,
859 UTransDirection dir,
860 UParseError& parseError,
861 UErrorCode& status);
862
863 /**
864 * Create a rule string that can be passed to createFromRules()
865 * to recreate this transliterator.
866 * @param result the string to receive the rules. Previous
867 * contents will be deleted.
868 * @param escapeUnprintable if TRUE then convert unprintable
374ca955
A
869 * character to their hex escape representations, \\uxxxx or
870 * \\Uxxxxxxxx. Unprintable characters are those other than
b75a7d8f
A
871 * U+000A, U+0020..U+007E.
872 * @stable ICU 2.0
873 */
874 virtual UnicodeString& toRules(UnicodeString& result,
875 UBool escapeUnprintable) const;
876
374ca955
A
877 /**
878 * Return the number of elements that make up this transliterator.
879 * For example, if the transliterator "NFD;Jamo-Latin;Latin-Greek"
880 * were created, the return value of this method would be 3.
881 *
882 * <p>If this transliterator is not composed of other
883 * transliterators, then this method returns 1.
884 * @return the number of transliterators that compose this
885 * transliterator, or 1 if this transliterator is not composed of
886 * multiple transliterators
887 * @draft ICU 3.0
888 */
889 int32_t countElements() const;
890
891 /**
892 * Return an element that makes up this transliterator. For
893 * example, if the transliterator "NFD;Jamo-Latin;Latin-Greek"
894 * were created, the return value of this method would be one
895 * of the three transliterator objects that make up that
896 * transliterator: [NFD, Jamo-Latin, Latin-Greek].
897 *
898 * <p>If this transliterator is not composed of other
899 * transliterators, then this method will return a reference to
900 * this transliterator when given the index 0.
901 * @param index a value from 0..countElements()-1 indicating the
902 * transliterator to return
903 * @param ec input-output error code
904 * @return one of the transliterators that makes up this
905 * transliterator, if this transliterator is made up of multiple
906 * transliterators, otherwise a reference to this object if given
907 * an index of 0
908 * @draft ICU 3.0
909 */
910 const Transliterator& getElement(int32_t index, UErrorCode& ec) const;
911
b75a7d8f
A
912 /**
913 * Returns the set of all characters that may be modified in the
914 * input text by this Transliterator. This incorporates this
915 * object's current filter; if the filter is changed, the return
916 * value of this function will change. The default implementation
917 * returns an empty set. Some subclasses may override {@link
374ca955 918 * #handleGetSourceSet } to return a more precise result. The
b75a7d8f
A
919 * return result is approximate in any case and is intended for
920 * use by tests, tools, or utilities.
921 * @param result receives result set; previous contents lost
922 * @return a reference to result
923 * @see #getTargetSet
924 * @see #handleGetSourceSet
374ca955 925 * @stable ICU 2.4
b75a7d8f
A
926 */
927 UnicodeSet& getSourceSet(UnicodeSet& result) const;
928
929 /**
930 * Framework method that returns the set of all characters that
931 * may be modified in the input text by this Transliterator,
932 * ignoring the effect of this object's filter. The base class
933 * implementation returns the empty set. Subclasses that wish to
934 * implement this should override this method.
935 * @return the set of characters that this transliterator may
936 * modify. The set may be modified, so subclasses should return a
937 * newly-created object.
938 * @param result receives result set; previous contents lost
939 * @see #getSourceSet
940 * @see #getTargetSet
374ca955 941 * @stable ICU 2.4
b75a7d8f
A
942 */
943 virtual void handleGetSourceSet(UnicodeSet& result) const;
944
945 /**
946 * Returns the set of all characters that may be generated as
947 * replacement text by this transliterator. The default
948 * implementation returns the empty set. Some subclasses may
949 * override this method to return a more precise result. The
950 * return result is approximate in any case and is intended for
951 * use by tests, tools, or utilities requiring such
952 * meta-information.
953 * @param result receives result set; previous contents lost
954 * @return a reference to result
955 * @see #getTargetSet
374ca955 956 * @stable ICU 2.4
b75a7d8f
A
957 */
958 virtual UnicodeSet& getTargetSet(UnicodeSet& result) const;
959
960public:
961
962 /**
963 * Registers a factory function that creates transliterators of
964 * a given ID.
965 * @param id the ID being registered
966 * @param factory a function pointer that will be copied and
967 * called later when the given ID is passed to createInstance()
968 * @param context a context pointer that will be stored and
969 * later passed to the factory function when an ID matching
970 * the registration ID is being instantiated with this factory.
971 * @stable ICU 2.0
972 */
374ca955 973 static void U_EXPORT2 registerFactory(const UnicodeString& id,
b75a7d8f
A
974 Factory factory,
975 Token context);
976
977 /**
978 * Registers a instance <tt>obj</tt> of a subclass of
979 * <code>Transliterator</code> with the system. When
980 * <tt>createInstance()</tt> is called with an ID string that is
981 * equal to <tt>obj->getID()</tt>, then <tt>obj->clone()</tt> is
982 * returned.
983 *
984 * After this call the Transliterator class owns the adoptedObj
985 * and will delete it.
986 *
987 * @param adoptedObj an instance of subclass of
988 * <code>Transliterator</code> that defines <tt>clone()</tt>
989 * @see #createInstance
374ca955 990 * @see #registerFactory
b75a7d8f
A
991 * @see #unregister
992 * @stable ICU 2.0
993 */
374ca955 994 static void U_EXPORT2 registerInstance(Transliterator* adoptedObj);
b75a7d8f
A
995
996protected:
997
998 /**
999 * @internal
1000 * @param id the ID being registered
1001 * @param factory a function pointer that will be copied and
1002 * called later when the given ID is passed to createInstance()
1003 * @param context a context pointer that will be stored and
1004 * later passed to the factory function when an ID matching
1005 * the registration ID is being instantiated with this factory.
1006 */
1007 static void _registerFactory(const UnicodeString& id,
1008 Factory factory,
1009 Token context);
1010
1011 /**
1012 * @internal
1013 */
1014 static void _registerInstance(Transliterator* adoptedObj);
1015
1016 /**
1017 * Register two targets as being inverses of one another. For
1018 * example, calling registerSpecialInverse("NFC", "NFD", true) causes
1019 * Transliterator to form the following inverse relationships:
1020 *
1021 * <pre>NFC => NFD
1022 * Any-NFC => Any-NFD
1023 * NFD => NFC
1024 * Any-NFD => Any-NFC</pre>
1025 *
1026 * (Without the special inverse registration, the inverse of NFC
1027 * would be NFC-Any.) Note that NFD is shorthand for Any-NFD, but
1028 * that the presence or absence of "Any-" is preserved.
1029 *
1030 * <p>The relationship is symmetrical; registering (a, b) is
1031 * equivalent to registering (b, a).
1032 *
1033 * <p>The relevant IDs must still be registered separately as
1034 * factories or classes.
1035 *
1036 * <p>Only the targets are specified. Special inverses always
1037 * have the form Any-Target1 <=> Any-Target2. The target should
1038 * have canonical casing (the casing desired to be produced when
1039 * an inverse is formed) and should contain no whitespace or other
1040 * extraneous characters.
1041 *
1042 * @param target the target against which to register the inverse
1043 * @param inverseTarget the inverse of target, that is
1044 * Any-target.getInverse() => Any-inverseTarget
1045 * @param bidirectional if true, register the reverse relation
1046 * as well, that is, Any-inverseTarget.getInverse() => Any-target
1047 * @internal
1048 */
1049 static void _registerSpecialInverse(const UnicodeString& target,
1050 const UnicodeString& inverseTarget,
1051 UBool bidirectional);
1052
1053public:
1054
1055 /**
1056 * Unregisters a transliterator or class. This may be either
1057 * a system transliterator or a user transliterator or class.
1058 * Any attempt to construct an unregistered transliterator based
1059 * on its ID will fail.
1060 *
1061 * @param ID the ID of the transliterator or class
1062 * @return the <code>Object</code> that was registered with
1063 * <code>ID</code>, or <code>null</code> if none was
1064 * @see #registerInstance
374ca955 1065 * @see #registerFactory
b75a7d8f
A
1066 * @stable ICU 2.0
1067 */
374ca955 1068 static void U_EXPORT2 unregister(const UnicodeString& ID);
b75a7d8f
A
1069
1070public:
1071
1072 /**
374ca955
A
1073 * Return a StringEnumeration over the IDs available at the time of the
1074 * call, including user-registered IDs.
1075 * @param ec input-output error code
1076 * @return a newly-created StringEnumeration over the transliterators
1077 * available at the time of the call. The caller should delete this object
1078 * when done using it.
1079 * @draft ICU 3.0
b75a7d8f 1080 */
374ca955 1081 static StringEnumeration* U_EXPORT2 getAvailableIDs(UErrorCode& ec);
b75a7d8f
A
1082
1083 /**
1084 * Return the number of registered source specifiers.
1085 * @return the number of registered source specifiers.
1086 * @stable ICU 2.0
1087 */
374ca955
A
1088 static int32_t U_EXPORT2 countAvailableSources(void);
1089
b75a7d8f
A
1090 /**
1091 * Return a registered source specifier.
1092 * @param index which specifier to return, from 0 to n-1, where
1093 * n = countAvailableSources()
1094 * @param result fill-in paramter to receive the source specifier.
1095 * If index is out of range, result will be empty.
1096 * @return reference to result
1097 * @stable ICU 2.0
1098 */
374ca955 1099 static UnicodeString& U_EXPORT2 getAvailableSource(int32_t index,
b75a7d8f 1100 UnicodeString& result);
374ca955 1101
b75a7d8f
A
1102 /**
1103 * Return the number of registered target specifiers for a given
1104 * source specifier.
1105 * @param source the given source specifier.
1106 * @return the number of registered target specifiers for a given
1107 * source specifier.
1108 * @stable ICU 2.0
1109 */
374ca955
A
1110 static int32_t U_EXPORT2 countAvailableTargets(const UnicodeString& source);
1111
b75a7d8f
A
1112 /**
1113 * Return a registered target specifier for a given source.
1114 * @param index which specifier to return, from 0 to n-1, where
1115 * n = countAvailableTargets(source)
1116 * @param source the source specifier
1117 * @param result fill-in paramter to receive the target specifier.
1118 * If source is invalid or if index is out of range, result will
1119 * be empty.
1120 * @return reference to result
1121 * @stable ICU 2.0
1122 */
374ca955 1123 static UnicodeString& U_EXPORT2 getAvailableTarget(int32_t index,
b75a7d8f
A
1124 const UnicodeString& source,
1125 UnicodeString& result);
374ca955 1126
b75a7d8f
A
1127 /**
1128 * Return the number of registered variant specifiers for a given
1129 * source-target pair.
1130 * @param source the source specifiers.
1131 * @param target the target specifiers.
1132 * @stable ICU 2.0
1133 */
374ca955 1134 static int32_t U_EXPORT2 countAvailableVariants(const UnicodeString& source,
b75a7d8f 1135 const UnicodeString& target);
374ca955 1136
b75a7d8f
A
1137 /**
1138 * Return a registered variant specifier for a given source-target
1139 * pair.
1140 * @param index which specifier to return, from 0 to n-1, where
1141 * n = countAvailableVariants(source, target)
1142 * @param source the source specifier
1143 * @param target the target specifier
1144 * @param result fill-in paramter to receive the variant
1145 * specifier. If source is invalid or if target is invalid or if
1146 * index is out of range, result will be empty.
1147 * @return reference to result
1148 * @stable ICU 2.0
1149 */
374ca955 1150 static UnicodeString& U_EXPORT2 getAvailableVariant(int32_t index,
b75a7d8f
A
1151 const UnicodeString& source,
1152 const UnicodeString& target,
1153 UnicodeString& result);
1154
1155protected:
1156
1157 /**
1158 * Non-mutexed internal method
1159 * @internal
1160 */
1161 static int32_t _countAvailableSources(void);
374ca955 1162
b75a7d8f
A
1163 /**
1164 * Non-mutexed internal method
1165 * @internal
1166 */
1167 static UnicodeString& _getAvailableSource(int32_t index,
374ca955
A
1168 UnicodeString& result);
1169
b75a7d8f
A
1170 /**
1171 * Non-mutexed internal method
1172 * @internal
1173 */
1174 static int32_t _countAvailableTargets(const UnicodeString& source);
374ca955 1175
b75a7d8f
A
1176 /**
1177 * Non-mutexed internal method
1178 * @internal
1179 */
1180 static UnicodeString& _getAvailableTarget(int32_t index,
374ca955
A
1181 const UnicodeString& source,
1182 UnicodeString& result);
1183
b75a7d8f
A
1184 /**
1185 * Non-mutexed internal method
1186 * @internal
1187 */
1188 static int32_t _countAvailableVariants(const UnicodeString& source,
374ca955
A
1189 const UnicodeString& target);
1190
b75a7d8f
A
1191 /**
1192 * Non-mutexed internal method
1193 * @internal
1194 */
1195 static UnicodeString& _getAvailableVariant(int32_t index,
374ca955
A
1196 const UnicodeString& source,
1197 const UnicodeString& target,
1198 UnicodeString& result);
b75a7d8f
A
1199
1200protected:
1201
1202 /**
1203 * Set the ID of this transliterators. Subclasses shouldn't do
1204 * this, unless the underlying script behavior has changed.
1205 * @param id the new id t to be set.
374ca955 1206 * @stable ICU 2.4
b75a7d8f
A
1207 */
1208 void setID(const UnicodeString& id);
1209
1210public:
1211
1212 /**
1213 * Return the class ID for this class. This is useful only for
374ca955
A
1214 * comparing to a return value from getDynamicClassID().
1215 * Note that Transliterator is an abstract base class, and therefor
1216 * no fully constructed object will have a dynamic
1217 * UCLassID that equals the UClassID returned from
1218 * TRansliterator::getStaticClassID().
1219 * @return The class ID for class Transliterator.
b75a7d8f
A
1220 * @stable ICU 2.0
1221 */
374ca955 1222 static UClassID U_EXPORT2 getStaticClassID(void);
b75a7d8f
A
1223
1224 /**
1225 * Returns a unique class ID <b>polymorphically</b>. This method
1226 * is to implement a simple version of RTTI, since not all C++
1227 * compilers support genuine RTTI. Polymorphic operator==() and
1228 * clone() methods call this method.
b75a7d8f 1229 *
374ca955
A
1230 * <p>Concrete subclasses of Transliterator must use the
1231 * UOBJECT_DEFINE_RTTI_IMPLEMENTATION macro from
1232 * uobject.h to provide the RTTI functions.
b75a7d8f
A
1233 *
1234 * @return The class ID for this object. All objects of a given
1235 * class have the same class ID. Objects of other classes have
1236 * different class IDs.
1237 * @stable ICU 2.0
1238 */
1239 virtual UClassID getDynamicClassID(void) const = 0;
1240
1241private:
374ca955 1242 static UBool initializeRegistry(void);
b75a7d8f 1243
374ca955 1244public:
b75a7d8f 1245 /**
374ca955
A
1246 * Return the number of IDs currently registered with the system.
1247 * To retrieve the actual IDs, call getAvailableID(i) with
1248 * i from 0 to countAvailableIDs() - 1.
1249 * @return the number of IDs currently registered with the system.
1250 * @obsolete ICU 3.4 use getAvailableIDs() instead
b75a7d8f 1251 */
374ca955 1252 static int32_t U_EXPORT2 countAvailableIDs(void);
b75a7d8f 1253
374ca955
A
1254 /**
1255 * Return the index-th available ID. index must be between 0
1256 * and countAvailableIDs() - 1, inclusive. If index is out of
1257 * range, the result of getAvailableID(0) is returned.
1258 * @param index the given ID index.
1259 * @return the index-th available ID. index must be between 0
1260 * and countAvailableIDs() - 1, inclusive. If index is out of
1261 * range, the result of getAvailableID(0) is returned.
1262 * @obsolete ICU 3.4 use getAvailableIDs() instead; this function
1263 * is not thread safe, since it returns a reference to storage that
1264 * may become invalid if another thread calls unregister
1265 */
1266 static const UnicodeString& U_EXPORT2 getAvailableID(int32_t index);
b75a7d8f
A
1267};
1268
b75a7d8f
A
1269inline int32_t Transliterator::getMaximumContextLength(void) const {
1270 return maximumContextLength;
1271}
1272
1273inline void Transliterator::setID(const UnicodeString& id) {
1274 ID = id;
374ca955
A
1275 // NUL-terminate the ID string
1276 ID.getTerminatedBuffer();
b75a7d8f
A
1277}
1278
1279inline Transliterator::Token Transliterator::integerToken(int32_t i) {
1280 Token t;
1281 t.integer = i;
1282 return t;
1283}
1284
1285inline Transliterator::Token Transliterator::pointerToken(void* p) {
1286 Token t;
1287 t.pointer = p;
1288 return t;
1289}
1290
1291U_NAMESPACE_END
1292
1293#endif /* #if !UCONFIG_NO_TRANSLITERATION */
1294
1295#endif