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