1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru**********************************************************************
385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho*   Copyright (C) 1999-2008, International Business Machines
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   Corporation and others.  All Rights Reserved.
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru**********************************************************************
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   Date        Name        Description
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*   11/17/99    aliu        Creation.
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru**********************************************************************
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h"
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_TRANSLITERATION
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/unifilt.h"
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uniset.h"
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cpdtrans.h"
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "uvector.h"
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "tridpars.h"
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "cmemory.h"
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// keep in sync with Transliterator
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru//static const UChar ID_SEP   = 0x002D; /*-*/
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic const UChar ID_DELIM = 0x003B; /*;*/
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic const UChar NEWLINE  = 10;
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru// Empty string
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic const UChar EMPTY[] = {0}; //""
29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic const UChar COLON_COLON[] = {0x3A, 0x3A, 0}; //"::"
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_BEGIN
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst UChar CompoundTransliterator::PASS_STRING[] = { 0x0025, 0x0050, 0x0061, 0x0073, 0x0073, 0 }; // "%Pass"
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUOBJECT_DEFINE_RTTI_IMPLEMENTATION(CompoundTransliterator)
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Constructs a new compound transliterator given an array of
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * transliterators.  The array of transliterators may be of any
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * length, including zero or one, however, useful compound
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * transliterators have at least two components.
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param transliterators array of <code>Transliterator</code>
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * objects
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param transliteratorCount The number of
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <code>Transliterator</code> objects in transliterators.
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param filter the filter.  Any character for which
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <tt>filter.contains()</tt> returns <tt>false</tt> will not be
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * altered by this transliterator.  If <tt>filter</tt> is
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <tt>null</tt> then no filtering is applied.
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruCompoundTransliterator::CompoundTransliterator(
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                           Transliterator* const transliterators[],
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                           int32_t transliteratorCount,
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                           UnicodeFilter* adoptedFilter) :
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator(joinIDs(transliterators, transliteratorCount), adoptedFilter),
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    trans(0), count(0), numAnonymousRBTs(0)  {
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    setTransliterators(transliterators, transliteratorCount);
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Splits an ID of the form "ID;ID;..." into a compound using each
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * of the IDs.
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param id of above form
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param forward if false, does the list in reverse order, and
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * takes the inverse of each ID.
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruCompoundTransliterator::CompoundTransliterator(const UnicodeString& id,
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                              UTransDirection direction,
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                              UnicodeFilter* adoptedFilter,
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                              UParseError& /*parseError*/,
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                              UErrorCode& status) :
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator(id, adoptedFilter),
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    trans(0), numAnonymousRBTs(0) {
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // TODO add code for parseError...currently unused, but
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // later may be used by parsing code...
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    init(id, direction, TRUE, status);
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruCompoundTransliterator::CompoundTransliterator(const UnicodeString& id,
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                              UParseError& /*parseError*/,
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                              UErrorCode& status) :
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator(id, 0), // set filter to 0 here!
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    trans(0), numAnonymousRBTs(0) {
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // TODO add code for parseError...currently unused, but
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // later may be used by parsing code...
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    init(id, UTRANS_FORWARD, TRUE, status);
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Private constructor for use of TransliteratorAlias
92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruCompoundTransliterator::CompoundTransliterator(const UnicodeString& newID,
94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                              UVector& list,
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                              UnicodeFilter* adoptedFilter,
96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                              int32_t anonymousRBTs,
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                              UParseError& /*parseError*/,
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                              UErrorCode& status) :
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator(newID, adoptedFilter),
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    trans(0), numAnonymousRBTs(anonymousRBTs)
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    init(list, UTRANS_FORWARD, FALSE, status);
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Private constructor for Transliterator from a vector of
107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * transliterators.  The caller is responsible for fixing up the
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * ID.
109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruCompoundTransliterator::CompoundTransliterator(UVector& list,
111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                               UParseError& /*parseError*/,
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                               UErrorCode& status) :
113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator(EMPTY, NULL),
114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    trans(0), numAnonymousRBTs(0)
115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // TODO add code for parseError...currently unused, but
117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // later may be used by parsing code...
118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    init(list, UTRANS_FORWARD, FALSE, status);
119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // assume caller will fixup ID
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruCompoundTransliterator::CompoundTransliterator(UVector& list,
123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                               int32_t anonymousRBTs,
124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                               UParseError& /*parseError*/,
125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                               UErrorCode& status) :
126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator(EMPTY, NULL),
127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    trans(0), numAnonymousRBTs(anonymousRBTs)
128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{
129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    init(list, UTRANS_FORWARD, FALSE, status);
130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Finish constructing a transliterator: only to be called by
134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * constructors.  Before calling init(), set trans and filter to NULL.
135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param id the id containing ';'-separated entries
136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param direction either FORWARD or REVERSE
137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param idSplitPoint the index into id at which the
138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * adoptedSplitTransliterator should be inserted, if there is one, or
139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * -1 if there is none.
140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param adoptedSplitTransliterator a transliterator to be inserted
141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * before the entry at offset idSplitPoint in the id string.  May be
142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * NULL to insert no entry.
143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param fixReverseID if TRUE, then reconstruct the ID of reverse
144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * entries by calling getID() of component entries.  Some constructors
145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * do not require this because they apply a facade ID anyway.
146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code indicating success or failure
147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid CompoundTransliterator::init(const UnicodeString& id,
149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                  UTransDirection direction,
150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                  UBool fixReverseID,
151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                  UErrorCode& status) {
152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // assert(trans == 0);
153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status)) {
155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UVector list(status);
159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeSet* compoundFilter = NULL;
160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString regenID;
161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (!TransliteratorIDParser::parseCompoundID(id, direction,
162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                      regenID, list, compoundFilter)) {
163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        status = U_INVALID_ID;
164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        delete compoundFilter;
165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    TransliteratorIDParser::instantiateList(list, status);
169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    init(list, direction, fixReverseID, status);
171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (compoundFilter != NULL) {
173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        adoptFilter(compoundFilter);
174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Finish constructing a transliterator: only to be called by
179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * constructors.  Before calling init(), set trans and filter to NULL.
180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param list a vector of transliterator objects to be adopted.  It
181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * should NOT be empty.  The list should be in declared order.  That
182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * is, it should be in the FORWARD order; if direction is REVERSE then
183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * the list order will be reversed.
184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param direction either FORWARD or REVERSE
185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param fixReverseID if TRUE, then reconstruct the ID of reverse
186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * entries by calling getID() of component entries.  Some constructors
187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * do not require this because they apply a facade ID anyway.
188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param status the error code indicating success or failure
189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid CompoundTransliterator::init(UVector& list,
191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                  UTransDirection direction,
192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                  UBool fixReverseID,
193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                  UErrorCode& status) {
194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // assert(trans == 0);
195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // Allocate array
197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_SUCCESS(status)) {
198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        count = list.size();
199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        trans = (Transliterator **)uprv_malloc(count * sizeof(Transliterator *));
200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        /* test for NULL */
201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (trans == 0) {
202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            status = U_MEMORY_ALLOCATION_ERROR;
203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            return;
204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (U_FAILURE(status) || trans == 0) {
208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru         // assert(trans == 0);
209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return;
210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // Move the transliterators from the vector into an array.
213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // Reverse the order if necessary.
214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t i;
215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (i=0; i<count; ++i) {
216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int32_t j = (direction == UTRANS_FORWARD) ? i : count - 1 - i;
217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        trans[i] = (Transliterator*) list.elementAt(j);
218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // If the direction is UTRANS_REVERSE then we may need to fix the
221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // ID.
222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (direction == UTRANS_REVERSE && fixReverseID) {
223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UnicodeString newID;
224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for (i=0; i<count; ++i) {
225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if (i > 0) {
226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                newID.append(ID_DELIM);
227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            }
228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            newID.append(trans[i]->getID());
229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        setID(newID);
231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    computeMaximumContextLength();
234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Return the IDs of the given list of transliterators, concatenated
238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * with ID_DELIM delimiting them.  Equivalent to the perlish expression
239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * join(ID_DELIM, map($_.getID(), transliterators).
240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUnicodeString CompoundTransliterator::joinIDs(Transliterator* const transliterators[],
242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                              int32_t transCount) {
243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString id;
244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (int32_t i=0; i<transCount; ++i) {
245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (i > 0) {
246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            id.append(ID_DELIM);
247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        id.append(transliterators[i]->getID());
249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return id; // Return temporary
251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Copy constructor.
255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruCompoundTransliterator::CompoundTransliterator(const CompoundTransliterator& t) :
257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator(t), trans(0), count(0), numAnonymousRBTs(-1) {
258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    *this = t;
259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Destructor
263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruCompoundTransliterator::~CompoundTransliterator() {
265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    freeTransliterators();
266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid CompoundTransliterator::freeTransliterators(void) {
269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (trans != 0) {
270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        for (int32_t i=0; i<count; ++i) {
271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            delete trans[i];
272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        uprv_free(trans);
274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    trans = 0;
276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    count = 0;
277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Assignment operator.
281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruCompoundTransliterator& CompoundTransliterator::operator=(
28385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                                             const CompoundTransliterator& t)
28485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho{
285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator::operator=(t);
28685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int32_t i = 0;
28785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UBool failed = FALSE;
28885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if (trans != NULL) {
28985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        for (i=0; i<count; ++i) {
29085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            delete trans[i];
29185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            trans[i] = 0;
29285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (t.count > count) {
29585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        if (trans != NULL) {
29685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            uprv_free(trans);
29785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        trans = (Transliterator **)uprv_malloc(t.count * sizeof(Transliterator *));
299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    count = t.count;
30185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if (trans != NULL) {
30285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        for (i=0; i<count; ++i) {
30385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            trans[i] = t.trans[i]->clone();
30485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            if (trans[i] == NULL) {
30585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                failed = TRUE;
30685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho                break;
30785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            }
30885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
30985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
31085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho
31185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    // if memory allocation failed delete backwards trans array
31285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if (failed && i > 0) {
31385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        int32_t n;
31485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        for (n = i-1; n >= 0; n--) {
31585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            uprv_free(trans[n]);
31685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            trans[n] = NULL;
31785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    numAnonymousRBTs = t.numAnonymousRBTs;
320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return *this;
321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Transliterator API.
325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruTransliterator* CompoundTransliterator::clone(void) const {
327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return new CompoundTransliterator(*this);
328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Returns the number of transliterators in this chain.
332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return number of transliterators in this chain.
333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint32_t CompoundTransliterator::getCount(void) const {
335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return count;
336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Returns the transliterator at the given index in this chain.
340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param index index into chain, from 0 to <code>getCount() - 1</code>
341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return transliterator at the given index
342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruconst Transliterator& CompoundTransliterator::getTransliterator(int32_t index) const {
344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return *trans[index];
345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid CompoundTransliterator::setTransliterators(Transliterator* const transliterators[],
348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                                int32_t transCount) {
349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    Transliterator** a = (Transliterator **)uprv_malloc(transCount * sizeof(Transliterator *));
35085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if (a == NULL) {
35185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        return;
35285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
35385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    int32_t i = 0;
35485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    UBool failed = FALSE;
35585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    for (i=0; i<transCount; ++i) {
356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        a[i] = transliterators[i]->clone();
35785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        if (a[i] == NULL) {
35885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            failed = TRUE;
35985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            break;
36085bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
36185bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    }
36285bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho    if (failed && i > 0) {
36385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        int32_t n;
36485bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        for (n = i-1; n >= 0; n--) {
36585bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            uprv_free(a[n]);
36685bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho            a[n] = NULL;
36785bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        }
36885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho        return;
369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    adoptTransliterators(a, transCount);
371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid CompoundTransliterator::adoptTransliterators(Transliterator* adoptedTransliterators[],
374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                                  int32_t transCount) {
375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // First free trans[] and set count to zero.  Once this is done,
376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // orphan the filter.  Set up the new trans[].
377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    freeTransliterators();
378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    trans = adoptedTransliterators;
379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    count = transCount;
380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    computeMaximumContextLength();
381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    setID(joinIDs(trans, count));
382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Append c to buf, unless buf is empty or buf already ends in c.
386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic void _smartAppend(UnicodeString& buf, UChar c) {
388ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (buf.length() != 0 &&
389ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        buf.charAt(buf.length() - 1) != c) {
390ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        buf.append(c);
391ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
392ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
393ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
394ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUnicodeString& CompoundTransliterator::toRules(UnicodeString& rulesSource,
395ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                               UBool escapeUnprintable) const {
396ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // We do NOT call toRules() on our component transliterators, in
397ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // general.  If we have several rule-based transliterators, this
398ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // yields a concatenation of the rules -- not what we want.  We do
399ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // handle compound RBT transliterators specially -- those for which
400ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // compoundRBTIndex >= 0.  For the transliterator at compoundRBTIndex,
401ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // we do call toRules() recursively.
402ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    rulesSource.truncate(0);
403ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (numAnonymousRBTs >= 1 && getFilter() != NULL) {
404ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // If we are a compound RBT and if we have a global
405ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // filter, then emit it at the top.
406ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UnicodeString pat;
407ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        rulesSource.append(COLON_COLON).append(getFilter()->toPattern(pat, escapeUnprintable)).append(ID_DELIM);
408ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
409ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (int32_t i=0; i<count; ++i) {
410ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UnicodeString rule;
411ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
412ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // Anonymous RuleBasedTransliterators (inline rules and
413ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // ::BEGIN/::END blocks) are given IDs that begin with
414ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // "%Pass": use toRules() to write all the rules to the output
415ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // (and insert "::Null;" if we have two in a row)
416ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (trans[i]->getID().startsWith(PASS_STRING)) {
417ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            trans[i]->toRules(rule, escapeUnprintable);
418ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            if (numAnonymousRBTs > 1 && i > 0 && trans[i - 1]->getID().startsWith(PASS_STRING))
419ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                rule = UNICODE_STRING_SIMPLE("::Null;") + rule;
420ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
421ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // we also use toRules() on CompoundTransliterators (which we
422ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // check for by looking for a semicolon in the ID)-- this gets
423ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // the list of their child transliterators output in the right
424ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // format
425ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else if (trans[i]->getID().indexOf(ID_DELIM) >= 0) {
426ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            trans[i]->toRules(rule, escapeUnprintable);
427ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
428ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // for everything else, use Transliterator::toRules()
429ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        } else {
430ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            trans[i]->Transliterator::toRules(rule, escapeUnprintable);
431ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
432ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        _smartAppend(rulesSource, NEWLINE);
433ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        rulesSource.append(rule);
434ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        _smartAppend(rulesSource, ID_DELIM);
435ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
436ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return rulesSource;
437ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
438ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
439ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
440ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Implement Transliterator framework
441ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
442ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid CompoundTransliterator::handleGetSourceSet(UnicodeSet& result) const {
443ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeSet set;
444ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    result.clear();
445ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (int32_t i=0; i<count; ++i) {
446ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    result.addAll(trans[i]->getSourceSet(set));
447ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // Take the example of Hiragana-Latin.  This is really
448ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // Hiragana-Katakana; Katakana-Latin.  The source set of
449ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // these two is roughly [:Hiragana:] and [:Katakana:].
450ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // But the source set for the entire transliterator is
451ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // actually [:Hiragana:] ONLY -- that is, the first
452ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // non-empty source set.
453ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
454ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // This is a heuristic, and not 100% reliable.
455ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (!result.isEmpty()) {
456ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        break;
457ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
458ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
459ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
460ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
461ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
462ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Override Transliterator framework
463ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
464ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruUnicodeSet& CompoundTransliterator::getTargetSet(UnicodeSet& result) const {
465ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeSet set;
466ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    result.clear();
467ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (int32_t i=0; i<count; ++i) {
468ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // This is a heuristic, and not 100% reliable.
469ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    result.addAll(trans[i]->getTargetSet(set));
470ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
471ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return result;
472ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
473ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
474ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
475ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Implements {@link Transliterator#handleTransliterate}.
476ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
477ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid CompoundTransliterator::handleTransliterate(Replaceable& text, UTransPosition& index,
478ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru                                                 UBool incremental) const {
479ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /* Call each transliterator with the same contextStart and
480ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * start, but with the limit as modified
481ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * by preceding transliterators.  The start index must be
482ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * reset for each transliterator to give each a chance to
483ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * transliterate the text.  The initial contextStart index is known
484ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * to still point to the same place after each transliterator
485ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * is called because each transliterator will not change the
486ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * text between contextStart and the initial start index.
487ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
488ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * IMPORTANT: After the first transliterator, each subsequent
489ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * transliterator only gets to transliterate text committed by
490ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * preceding transliterators; that is, the start (output
491ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * value) of transliterator i becomes the limit (input value)
492ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * of transliterator i+1.  Finally, the overall limit is fixed
493ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * up before we return.
494ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
495ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Assumptions we make here:
496ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * (1) contextStart <= start <= limit <= contextLimit <= text.length()
497ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * (2) start <= start' <= limit'  ;cursor doesn't move back
498ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * (3) start <= limit'            ;text before cursor unchanged
499ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * - start' is the value of start after calling handleKT
500ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * - limit' is the value of limit after calling handleKT
501ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
502ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
503ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
504ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Example: 3 transliterators.  This example illustrates the
505ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * mechanics we need to implement.  C, S, and L are the contextStart,
506ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * start, and limit.  gl is the globalLimit.  contextLimit is
507ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * equal to limit throughout.
508ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
509ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * 1. h-u, changes hex to Unicode
510ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
511ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *    4  7  a  d  0      4  7  a
512ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *    abc/u0061/u    =>  abca/u
513ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *    C  S       L       C   S L   gl=f->a
514ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
515ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * 2. upup, changes "x" to "XX"
516ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
517ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *    4  7  a       4  7  a
518ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *    abca/u    =>  abcAA/u
519ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *    C  SL         C    S
520ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *                       L    gl=a->b
521ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * 3. u-h, changes Unicode to hex
522ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
523ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *    4  7  a        4  7  a  d  0  3
524ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *    abcAA/u    =>  abc/u0041/u0041/u
525ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *    C  S L         C              S
526ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *                                  L   gl=b->15
527ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * 4. return
528ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
529ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *    4  7  a  d  0  3
530ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *    abc/u0041/u0041/u
531ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *    C S L
532ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
533ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
534ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    if (count < 1) {
535ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        index.start = index.limit;
536ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        return; // Short circuit for empty compound transliterators
537ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
538ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
539ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // compoundLimit is the limit value for the entire compound
540ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // operation.  We overwrite index.limit with the previous
541ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // index.start.  After each transliteration, we update
542ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // compoundLimit for insertions or deletions that have happened.
543ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t compoundLimit = index.limit;
544ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
545ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // compoundStart is the start for the entire compound
546ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // operation.
547ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t compoundStart = index.start;
548ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
549ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t delta = 0; // delta in length
550ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
551ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // Give each transliterator a crack at the run of characters.
552ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // See comments at the top of the method for more detail.
553ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (int32_t i=0; i<count; ++i) {
554ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        index.start = compoundStart; // Reset start
555ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int32_t limit = index.limit;
556ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
557ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (index.start == index.limit) {
558ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            // Short circuit for empty range
559ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            break;
560ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
561ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
562ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        trans[i]->filteredTransliterate(text, index, incremental);
563ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
564ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // In a properly written transliterator, start == limit after
565ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // handleTransliterate() returns when incremental is false.
566ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // Catch cases where the subclass doesn't do this, and throw
567ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // an exception.  (Just pinning start to limit is a bad idea,
568ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // because what's probably happening is that the subclass
569ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // isn't transliterating all the way to the end, and it should
570ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // in non-incremental mode.)
571ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (!incremental && index.start != index.limit) {
572ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            // We can't throw an exception, so just fudge things
573ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            index.start = index.limit;
574ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
575ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
576ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        // Cumulative delta for insertions/deletions
577ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        delta += index.limit - limit;
578ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
579ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (incremental) {
580ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            // In the incremental case, only allow subsequent
581ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            // transliterators to modify what has already been
582ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            // completely processed by prior transliterators.  In the
583ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            // non-incrmental case, allow each transliterator to
584ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            // process the entire text.
585ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            index.limit = index.start;
586ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
587ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
588ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
589ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    compoundLimit += delta;
590ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
591ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // Start is good where it is -- where the last transliterator left
592ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // it.  Limit needs to be put back where it was, modulo
593ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // adjustments for deletions/insertions.
594ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    index.limit = compoundLimit;
595ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
596ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
597ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
598ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Sets the length of the longest context required by this transliterator.
599ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * This is <em>preceding</em> context.
600ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
601ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid CompoundTransliterator::computeMaximumContextLength(void) {
602ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t max = 0;
603ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    for (int32_t i=0; i<count; ++i) {
604ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int32_t len = trans[i]->getMaximumContextLength();
605ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        if (len > max) {
606ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru            max = len;
607ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        }
608ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    }
609ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    setMaximumContextLength(max);
610ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
611ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
612ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_END
613ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
614ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_TRANSLITERATION */
615ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
616ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* eof */
617