1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /*
4*0e209d39SAndroid Build Coastguard Worker ******************************************************************************
5*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 1997-2014, International Business Machines
6*0e209d39SAndroid Build Coastguard Worker * Corporation and others. All Rights Reserved.
7*0e209d39SAndroid Build Coastguard Worker ******************************************************************************
8*0e209d39SAndroid Build Coastguard Worker */
9*0e209d39SAndroid Build Coastguard Worker
10*0e209d39SAndroid Build Coastguard Worker /**
11*0e209d39SAndroid Build Coastguard Worker * \file
12*0e209d39SAndroid Build Coastguard Worker * \brief C++ API: Collation Element Iterator.
13*0e209d39SAndroid Build Coastguard Worker */
14*0e209d39SAndroid Build Coastguard Worker
15*0e209d39SAndroid Build Coastguard Worker /**
16*0e209d39SAndroid Build Coastguard Worker * File coleitr.h
17*0e209d39SAndroid Build Coastguard Worker *
18*0e209d39SAndroid Build Coastguard Worker * Created by: Helena Shih
19*0e209d39SAndroid Build Coastguard Worker *
20*0e209d39SAndroid Build Coastguard Worker * Modification History:
21*0e209d39SAndroid Build Coastguard Worker *
22*0e209d39SAndroid Build Coastguard Worker * Date Name Description
23*0e209d39SAndroid Build Coastguard Worker *
24*0e209d39SAndroid Build Coastguard Worker * 8/18/97 helena Added internal API documentation.
25*0e209d39SAndroid Build Coastguard Worker * 08/03/98 erm Synched with 1.2 version CollationElementIterator.java
26*0e209d39SAndroid Build Coastguard Worker * 12/10/99 aliu Ported Thai collation support from Java.
27*0e209d39SAndroid Build Coastguard Worker * 01/25/01 swquek Modified into a C++ wrapper calling C APIs (ucoliter.h)
28*0e209d39SAndroid Build Coastguard Worker * 02/19/01 swquek Removed CollationElementsIterator() since it is
29*0e209d39SAndroid Build Coastguard Worker * private constructor and no calls are made to it
30*0e209d39SAndroid Build Coastguard Worker * 2012-2014 markus Rewritten in C++ again.
31*0e209d39SAndroid Build Coastguard Worker */
32*0e209d39SAndroid Build Coastguard Worker
33*0e209d39SAndroid Build Coastguard Worker #ifndef COLEITR_H
34*0e209d39SAndroid Build Coastguard Worker #define COLEITR_H
35*0e209d39SAndroid Build Coastguard Worker
36*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
37*0e209d39SAndroid Build Coastguard Worker
38*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API
39*0e209d39SAndroid Build Coastguard Worker
40*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_COLLATION
41*0e209d39SAndroid Build Coastguard Worker
42*0e209d39SAndroid Build Coastguard Worker #include "unicode/unistr.h"
43*0e209d39SAndroid Build Coastguard Worker #include "unicode/uobject.h"
44*0e209d39SAndroid Build Coastguard Worker
45*0e209d39SAndroid Build Coastguard Worker struct UCollationElements;
46*0e209d39SAndroid Build Coastguard Worker struct UHashtable;
47*0e209d39SAndroid Build Coastguard Worker
48*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
49*0e209d39SAndroid Build Coastguard Worker
50*0e209d39SAndroid Build Coastguard Worker struct CollationData;
51*0e209d39SAndroid Build Coastguard Worker
52*0e209d39SAndroid Build Coastguard Worker class CharacterIterator;
53*0e209d39SAndroid Build Coastguard Worker class CollationIterator;
54*0e209d39SAndroid Build Coastguard Worker class RuleBasedCollator;
55*0e209d39SAndroid Build Coastguard Worker class UCollationPCE;
56*0e209d39SAndroid Build Coastguard Worker class UVector32;
57*0e209d39SAndroid Build Coastguard Worker
58*0e209d39SAndroid Build Coastguard Worker /**
59*0e209d39SAndroid Build Coastguard Worker * The CollationElementIterator class is used as an iterator to walk through
60*0e209d39SAndroid Build Coastguard Worker * each character of an international string. Use the iterator to return the
61*0e209d39SAndroid Build Coastguard Worker * ordering priority of the positioned character. The ordering priority of a
62*0e209d39SAndroid Build Coastguard Worker * character, which we refer to as a key, defines how a character is collated in
63*0e209d39SAndroid Build Coastguard Worker * the given collation object.
64*0e209d39SAndroid Build Coastguard Worker * For example, consider the following in Slovak and in traditional Spanish collation:
65*0e209d39SAndroid Build Coastguard Worker * <pre>
66*0e209d39SAndroid Build Coastguard Worker * "ca" -> the first key is key('c') and second key is key('a').
67*0e209d39SAndroid Build Coastguard Worker * "cha" -> the first key is key('ch') and second key is key('a').</pre>
68*0e209d39SAndroid Build Coastguard Worker * And in German phonebook collation,
69*0e209d39SAndroid Build Coastguard Worker * <pre> \htmlonly "æb"-> the first key is key('a'), the second key is key('e'), and
70*0e209d39SAndroid Build Coastguard Worker * the third key is key('b'). \endhtmlonly </pre>
71*0e209d39SAndroid Build Coastguard Worker * The key of a character, is an integer composed of primary order(short),
72*0e209d39SAndroid Build Coastguard Worker * secondary order(char), and tertiary order(char). Java strictly defines the
73*0e209d39SAndroid Build Coastguard Worker * size and signedness of its primitive data types. Therefore, the static
74*0e209d39SAndroid Build Coastguard Worker * functions primaryOrder(), secondaryOrder(), and tertiaryOrder() return
75*0e209d39SAndroid Build Coastguard Worker * int32_t to ensure the correctness of the key value.
76*0e209d39SAndroid Build Coastguard Worker * <p>Example of the iterator usage: (without error checking)
77*0e209d39SAndroid Build Coastguard Worker * <pre>
78*0e209d39SAndroid Build Coastguard Worker * \code
79*0e209d39SAndroid Build Coastguard Worker * void CollationElementIterator_Example()
80*0e209d39SAndroid Build Coastguard Worker * {
81*0e209d39SAndroid Build Coastguard Worker * UnicodeString str = "This is a test";
82*0e209d39SAndroid Build Coastguard Worker * UErrorCode success = U_ZERO_ERROR;
83*0e209d39SAndroid Build Coastguard Worker * RuleBasedCollator* rbc =
84*0e209d39SAndroid Build Coastguard Worker * (RuleBasedCollator*) RuleBasedCollator::createInstance(success);
85*0e209d39SAndroid Build Coastguard Worker * CollationElementIterator* c =
86*0e209d39SAndroid Build Coastguard Worker * rbc->createCollationElementIterator( str );
87*0e209d39SAndroid Build Coastguard Worker * int32_t order = c->next(success);
88*0e209d39SAndroid Build Coastguard Worker * c->reset();
89*0e209d39SAndroid Build Coastguard Worker * order = c->previous(success);
90*0e209d39SAndroid Build Coastguard Worker * delete c;
91*0e209d39SAndroid Build Coastguard Worker * delete rbc;
92*0e209d39SAndroid Build Coastguard Worker * }
93*0e209d39SAndroid Build Coastguard Worker * \endcode
94*0e209d39SAndroid Build Coastguard Worker * </pre>
95*0e209d39SAndroid Build Coastguard Worker * <p>
96*0e209d39SAndroid Build Coastguard Worker * The method next() returns the collation order of the next character based on
97*0e209d39SAndroid Build Coastguard Worker * the comparison level of the collator. The method previous() returns the
98*0e209d39SAndroid Build Coastguard Worker * collation order of the previous character based on the comparison level of
99*0e209d39SAndroid Build Coastguard Worker * the collator. The Collation Element Iterator moves only in one direction
100*0e209d39SAndroid Build Coastguard Worker * between calls to reset(), setOffset(), or setText(). That is, next()
101*0e209d39SAndroid Build Coastguard Worker * and previous() can not be inter-used. Whenever previous() is to be called after
102*0e209d39SAndroid Build Coastguard Worker * next() or vice versa, reset(), setOffset() or setText() has to be called first
103*0e209d39SAndroid Build Coastguard Worker * to reset the status, shifting pointers to either the end or the start of
104*0e209d39SAndroid Build Coastguard Worker * the string (reset() or setText()), or the specified position (setOffset()).
105*0e209d39SAndroid Build Coastguard Worker * Hence at the next call of next() or previous(), the first or last collation order,
106*0e209d39SAndroid Build Coastguard Worker * or collation order at the specified position will be returned. If a change of
107*0e209d39SAndroid Build Coastguard Worker * direction is done without one of these calls, the result is undefined.
108*0e209d39SAndroid Build Coastguard Worker * <p>
109*0e209d39SAndroid Build Coastguard Worker * The result of a forward iterate (next()) and reversed result of the backward
110*0e209d39SAndroid Build Coastguard Worker * iterate (previous()) on the same string are equivalent, if collation orders
111*0e209d39SAndroid Build Coastguard Worker * with the value 0 are ignored.
112*0e209d39SAndroid Build Coastguard Worker * Character based on the comparison level of the collator. A collation order
113*0e209d39SAndroid Build Coastguard Worker * consists of primary order, secondary order and tertiary order. The data
114*0e209d39SAndroid Build Coastguard Worker * type of the collation order is <strong>int32_t</strong>.
115*0e209d39SAndroid Build Coastguard Worker *
116*0e209d39SAndroid Build Coastguard Worker * Note, CollationElementIterator should not be subclassed.
117*0e209d39SAndroid Build Coastguard Worker * @see Collator
118*0e209d39SAndroid Build Coastguard Worker * @see RuleBasedCollator
119*0e209d39SAndroid Build Coastguard Worker * @version 1.8 Jan 16 2001
120*0e209d39SAndroid Build Coastguard Worker */
121*0e209d39SAndroid Build Coastguard Worker class U_I18N_API CollationElementIterator final : public UObject {
122*0e209d39SAndroid Build Coastguard Worker public:
123*0e209d39SAndroid Build Coastguard Worker
124*0e209d39SAndroid Build Coastguard Worker // CollationElementIterator public data member ------------------------------
125*0e209d39SAndroid Build Coastguard Worker
126*0e209d39SAndroid Build Coastguard Worker enum {
127*0e209d39SAndroid Build Coastguard Worker /**
128*0e209d39SAndroid Build Coastguard Worker * NULLORDER indicates that an error has occurred while processing
129*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
130*0e209d39SAndroid Build Coastguard Worker */
131*0e209d39SAndroid Build Coastguard Worker NULLORDER = (int32_t)0xffffffff
132*0e209d39SAndroid Build Coastguard Worker };
133*0e209d39SAndroid Build Coastguard Worker
134*0e209d39SAndroid Build Coastguard Worker // CollationElementIterator public constructor/destructor -------------------
135*0e209d39SAndroid Build Coastguard Worker
136*0e209d39SAndroid Build Coastguard Worker /**
137*0e209d39SAndroid Build Coastguard Worker * Copy constructor.
138*0e209d39SAndroid Build Coastguard Worker *
139*0e209d39SAndroid Build Coastguard Worker * @param other the object to be copied from
140*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
141*0e209d39SAndroid Build Coastguard Worker */
142*0e209d39SAndroid Build Coastguard Worker CollationElementIterator(const CollationElementIterator& other);
143*0e209d39SAndroid Build Coastguard Worker
144*0e209d39SAndroid Build Coastguard Worker /**
145*0e209d39SAndroid Build Coastguard Worker * Destructor
146*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
147*0e209d39SAndroid Build Coastguard Worker */
148*0e209d39SAndroid Build Coastguard Worker virtual ~CollationElementIterator();
149*0e209d39SAndroid Build Coastguard Worker
150*0e209d39SAndroid Build Coastguard Worker // CollationElementIterator public methods ----------------------------------
151*0e209d39SAndroid Build Coastguard Worker
152*0e209d39SAndroid Build Coastguard Worker /**
153*0e209d39SAndroid Build Coastguard Worker * Returns true if "other" is the same as "this"
154*0e209d39SAndroid Build Coastguard Worker *
155*0e209d39SAndroid Build Coastguard Worker * @param other the object to be compared
156*0e209d39SAndroid Build Coastguard Worker * @return true if "other" is the same as "this"
157*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
158*0e209d39SAndroid Build Coastguard Worker */
159*0e209d39SAndroid Build Coastguard Worker bool operator==(const CollationElementIterator& other) const;
160*0e209d39SAndroid Build Coastguard Worker
161*0e209d39SAndroid Build Coastguard Worker /**
162*0e209d39SAndroid Build Coastguard Worker * Returns true if "other" is not the same as "this".
163*0e209d39SAndroid Build Coastguard Worker *
164*0e209d39SAndroid Build Coastguard Worker * @param other the object to be compared
165*0e209d39SAndroid Build Coastguard Worker * @return true if "other" is not the same as "this"
166*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
167*0e209d39SAndroid Build Coastguard Worker */
168*0e209d39SAndroid Build Coastguard Worker bool operator!=(const CollationElementIterator& other) const;
169*0e209d39SAndroid Build Coastguard Worker
170*0e209d39SAndroid Build Coastguard Worker /**
171*0e209d39SAndroid Build Coastguard Worker * Resets the cursor to the beginning of the string.
172*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
173*0e209d39SAndroid Build Coastguard Worker */
174*0e209d39SAndroid Build Coastguard Worker void reset();
175*0e209d39SAndroid Build Coastguard Worker
176*0e209d39SAndroid Build Coastguard Worker /**
177*0e209d39SAndroid Build Coastguard Worker * Gets the ordering priority of the next character in the string.
178*0e209d39SAndroid Build Coastguard Worker * @param status the error code status.
179*0e209d39SAndroid Build Coastguard Worker * @return the next character's ordering. otherwise returns NULLORDER if an
180*0e209d39SAndroid Build Coastguard Worker * error has occurred or if the end of string has been reached
181*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
182*0e209d39SAndroid Build Coastguard Worker */
183*0e209d39SAndroid Build Coastguard Worker int32_t next(UErrorCode& status);
184*0e209d39SAndroid Build Coastguard Worker
185*0e209d39SAndroid Build Coastguard Worker /**
186*0e209d39SAndroid Build Coastguard Worker * Get the ordering priority of the previous collation element in the string.
187*0e209d39SAndroid Build Coastguard Worker * @param status the error code status.
188*0e209d39SAndroid Build Coastguard Worker * @return the previous element's ordering. otherwise returns NULLORDER if an
189*0e209d39SAndroid Build Coastguard Worker * error has occurred or if the start of string has been reached
190*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
191*0e209d39SAndroid Build Coastguard Worker */
192*0e209d39SAndroid Build Coastguard Worker int32_t previous(UErrorCode& status);
193*0e209d39SAndroid Build Coastguard Worker
194*0e209d39SAndroid Build Coastguard Worker /**
195*0e209d39SAndroid Build Coastguard Worker * Gets the primary order of a collation order.
196*0e209d39SAndroid Build Coastguard Worker * @param order the collation order
197*0e209d39SAndroid Build Coastguard Worker * @return the primary order of a collation order.
198*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
199*0e209d39SAndroid Build Coastguard Worker */
200*0e209d39SAndroid Build Coastguard Worker static inline int32_t primaryOrder(int32_t order);
201*0e209d39SAndroid Build Coastguard Worker
202*0e209d39SAndroid Build Coastguard Worker /**
203*0e209d39SAndroid Build Coastguard Worker * Gets the secondary order of a collation order.
204*0e209d39SAndroid Build Coastguard Worker * @param order the collation order
205*0e209d39SAndroid Build Coastguard Worker * @return the secondary order of a collation order.
206*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
207*0e209d39SAndroid Build Coastguard Worker */
208*0e209d39SAndroid Build Coastguard Worker static inline int32_t secondaryOrder(int32_t order);
209*0e209d39SAndroid Build Coastguard Worker
210*0e209d39SAndroid Build Coastguard Worker /**
211*0e209d39SAndroid Build Coastguard Worker * Gets the tertiary order of a collation order.
212*0e209d39SAndroid Build Coastguard Worker * @param order the collation order
213*0e209d39SAndroid Build Coastguard Worker * @return the tertiary order of a collation order.
214*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
215*0e209d39SAndroid Build Coastguard Worker */
216*0e209d39SAndroid Build Coastguard Worker static inline int32_t tertiaryOrder(int32_t order);
217*0e209d39SAndroid Build Coastguard Worker
218*0e209d39SAndroid Build Coastguard Worker /**
219*0e209d39SAndroid Build Coastguard Worker * Return the maximum length of any expansion sequences that end with the
220*0e209d39SAndroid Build Coastguard Worker * specified comparison order.
221*0e209d39SAndroid Build Coastguard Worker * @param order a collation order returned by previous or next.
222*0e209d39SAndroid Build Coastguard Worker * @return maximum size of the expansion sequences ending with the collation
223*0e209d39SAndroid Build Coastguard Worker * element or 1 if collation element does not occur at the end of any
224*0e209d39SAndroid Build Coastguard Worker * expansion sequence
225*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
226*0e209d39SAndroid Build Coastguard Worker */
227*0e209d39SAndroid Build Coastguard Worker int32_t getMaxExpansion(int32_t order) const;
228*0e209d39SAndroid Build Coastguard Worker
229*0e209d39SAndroid Build Coastguard Worker /**
230*0e209d39SAndroid Build Coastguard Worker * Gets the comparison order in the desired strength. Ignore the other
231*0e209d39SAndroid Build Coastguard Worker * differences.
232*0e209d39SAndroid Build Coastguard Worker * @param order The order value
233*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
234*0e209d39SAndroid Build Coastguard Worker */
235*0e209d39SAndroid Build Coastguard Worker int32_t strengthOrder(int32_t order) const;
236*0e209d39SAndroid Build Coastguard Worker
237*0e209d39SAndroid Build Coastguard Worker /**
238*0e209d39SAndroid Build Coastguard Worker * Sets the source string.
239*0e209d39SAndroid Build Coastguard Worker * @param str the source string.
240*0e209d39SAndroid Build Coastguard Worker * @param status the error code status.
241*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
242*0e209d39SAndroid Build Coastguard Worker */
243*0e209d39SAndroid Build Coastguard Worker void setText(const UnicodeString& str, UErrorCode& status);
244*0e209d39SAndroid Build Coastguard Worker
245*0e209d39SAndroid Build Coastguard Worker /**
246*0e209d39SAndroid Build Coastguard Worker * Sets the source string.
247*0e209d39SAndroid Build Coastguard Worker * @param str the source character iterator.
248*0e209d39SAndroid Build Coastguard Worker * @param status the error code status.
249*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
250*0e209d39SAndroid Build Coastguard Worker */
251*0e209d39SAndroid Build Coastguard Worker void setText(CharacterIterator& str, UErrorCode& status);
252*0e209d39SAndroid Build Coastguard Worker
253*0e209d39SAndroid Build Coastguard Worker /**
254*0e209d39SAndroid Build Coastguard Worker * Checks if a comparison order is ignorable.
255*0e209d39SAndroid Build Coastguard Worker * @param order the collation order.
256*0e209d39SAndroid Build Coastguard Worker * @return true if a character is ignorable, false otherwise.
257*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
258*0e209d39SAndroid Build Coastguard Worker */
259*0e209d39SAndroid Build Coastguard Worker static inline UBool isIgnorable(int32_t order);
260*0e209d39SAndroid Build Coastguard Worker
261*0e209d39SAndroid Build Coastguard Worker /**
262*0e209d39SAndroid Build Coastguard Worker * Gets the offset of the currently processed character in the source string.
263*0e209d39SAndroid Build Coastguard Worker * @return the offset of the character.
264*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
265*0e209d39SAndroid Build Coastguard Worker */
266*0e209d39SAndroid Build Coastguard Worker int32_t getOffset() const;
267*0e209d39SAndroid Build Coastguard Worker
268*0e209d39SAndroid Build Coastguard Worker /**
269*0e209d39SAndroid Build Coastguard Worker * Sets the offset of the currently processed character in the source string.
270*0e209d39SAndroid Build Coastguard Worker * @param newOffset the new offset.
271*0e209d39SAndroid Build Coastguard Worker * @param status the error code status.
272*0e209d39SAndroid Build Coastguard Worker * @return the offset of the character.
273*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
274*0e209d39SAndroid Build Coastguard Worker */
275*0e209d39SAndroid Build Coastguard Worker void setOffset(int32_t newOffset, UErrorCode& status);
276*0e209d39SAndroid Build Coastguard Worker
277*0e209d39SAndroid Build Coastguard Worker /**
278*0e209d39SAndroid Build Coastguard Worker * ICU "poor man's RTTI", returns a UClassID for the actual class.
279*0e209d39SAndroid Build Coastguard Worker *
280*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.2
281*0e209d39SAndroid Build Coastguard Worker */
282*0e209d39SAndroid Build Coastguard Worker virtual UClassID getDynamicClassID() const override;
283*0e209d39SAndroid Build Coastguard Worker
284*0e209d39SAndroid Build Coastguard Worker /**
285*0e209d39SAndroid Build Coastguard Worker * ICU "poor man's RTTI", returns a UClassID for this class.
286*0e209d39SAndroid Build Coastguard Worker *
287*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.2
288*0e209d39SAndroid Build Coastguard Worker */
289*0e209d39SAndroid Build Coastguard Worker static UClassID U_EXPORT2 getStaticClassID();
290*0e209d39SAndroid Build Coastguard Worker
291*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
292*0e209d39SAndroid Build Coastguard Worker /** @internal */
fromUCollationElements(UCollationElements * uc)293*0e209d39SAndroid Build Coastguard Worker static inline CollationElementIterator *fromUCollationElements(UCollationElements *uc) {
294*0e209d39SAndroid Build Coastguard Worker return reinterpret_cast<CollationElementIterator *>(uc);
295*0e209d39SAndroid Build Coastguard Worker }
296*0e209d39SAndroid Build Coastguard Worker /** @internal */
fromUCollationElements(const UCollationElements * uc)297*0e209d39SAndroid Build Coastguard Worker static inline const CollationElementIterator *fromUCollationElements(const UCollationElements *uc) {
298*0e209d39SAndroid Build Coastguard Worker return reinterpret_cast<const CollationElementIterator *>(uc);
299*0e209d39SAndroid Build Coastguard Worker }
300*0e209d39SAndroid Build Coastguard Worker /** @internal */
toUCollationElements()301*0e209d39SAndroid Build Coastguard Worker inline UCollationElements *toUCollationElements() {
302*0e209d39SAndroid Build Coastguard Worker return reinterpret_cast<UCollationElements *>(this);
303*0e209d39SAndroid Build Coastguard Worker }
304*0e209d39SAndroid Build Coastguard Worker /** @internal */
toUCollationElements()305*0e209d39SAndroid Build Coastguard Worker inline const UCollationElements *toUCollationElements() const {
306*0e209d39SAndroid Build Coastguard Worker return reinterpret_cast<const UCollationElements *>(this);
307*0e209d39SAndroid Build Coastguard Worker }
308*0e209d39SAndroid Build Coastguard Worker #endif // U_HIDE_INTERNAL_API
309*0e209d39SAndroid Build Coastguard Worker
310*0e209d39SAndroid Build Coastguard Worker private:
311*0e209d39SAndroid Build Coastguard Worker friend class RuleBasedCollator;
312*0e209d39SAndroid Build Coastguard Worker friend class UCollationPCE;
313*0e209d39SAndroid Build Coastguard Worker
314*0e209d39SAndroid Build Coastguard Worker /**
315*0e209d39SAndroid Build Coastguard Worker * CollationElementIterator constructor. This takes the source string and the
316*0e209d39SAndroid Build Coastguard Worker * collation object. The cursor will walk thru the source string based on the
317*0e209d39SAndroid Build Coastguard Worker * predefined collation rules. If the source string is empty, NULLORDER will
318*0e209d39SAndroid Build Coastguard Worker * be returned on the calls to next().
319*0e209d39SAndroid Build Coastguard Worker * @param sourceText the source string.
320*0e209d39SAndroid Build Coastguard Worker * @param order the collation object.
321*0e209d39SAndroid Build Coastguard Worker * @param status the error code status.
322*0e209d39SAndroid Build Coastguard Worker */
323*0e209d39SAndroid Build Coastguard Worker CollationElementIterator(const UnicodeString& sourceText,
324*0e209d39SAndroid Build Coastguard Worker const RuleBasedCollator* order, UErrorCode& status);
325*0e209d39SAndroid Build Coastguard Worker // Note: The constructors should take settings & tailoring, not a collator,
326*0e209d39SAndroid Build Coastguard Worker // to avoid circular dependencies.
327*0e209d39SAndroid Build Coastguard Worker // However, for operator==() we would need to be able to compare tailoring data for equality
328*0e209d39SAndroid Build Coastguard Worker // without making CollationData or CollationTailoring depend on TailoredSet.
329*0e209d39SAndroid Build Coastguard Worker // (See the implementation of RuleBasedCollator::operator==().)
330*0e209d39SAndroid Build Coastguard Worker // That might require creating an intermediate class that would be used
331*0e209d39SAndroid Build Coastguard Worker // by both CollationElementIterator and RuleBasedCollator
332*0e209d39SAndroid Build Coastguard Worker // but only contain the part of RBC== related to data and rules.
333*0e209d39SAndroid Build Coastguard Worker
334*0e209d39SAndroid Build Coastguard Worker /**
335*0e209d39SAndroid Build Coastguard Worker * CollationElementIterator constructor. This takes the source string and the
336*0e209d39SAndroid Build Coastguard Worker * collation object. The cursor will walk thru the source string based on the
337*0e209d39SAndroid Build Coastguard Worker * predefined collation rules. If the source string is empty, NULLORDER will
338*0e209d39SAndroid Build Coastguard Worker * be returned on the calls to next().
339*0e209d39SAndroid Build Coastguard Worker * @param sourceText the source string.
340*0e209d39SAndroid Build Coastguard Worker * @param order the collation object.
341*0e209d39SAndroid Build Coastguard Worker * @param status the error code status.
342*0e209d39SAndroid Build Coastguard Worker */
343*0e209d39SAndroid Build Coastguard Worker CollationElementIterator(const CharacterIterator& sourceText,
344*0e209d39SAndroid Build Coastguard Worker const RuleBasedCollator* order, UErrorCode& status);
345*0e209d39SAndroid Build Coastguard Worker
346*0e209d39SAndroid Build Coastguard Worker /**
347*0e209d39SAndroid Build Coastguard Worker * Assignment operator
348*0e209d39SAndroid Build Coastguard Worker *
349*0e209d39SAndroid Build Coastguard Worker * @param other the object to be copied
350*0e209d39SAndroid Build Coastguard Worker */
351*0e209d39SAndroid Build Coastguard Worker const CollationElementIterator&
352*0e209d39SAndroid Build Coastguard Worker operator=(const CollationElementIterator& other);
353*0e209d39SAndroid Build Coastguard Worker
354*0e209d39SAndroid Build Coastguard Worker CollationElementIterator() = delete; // default constructor not implemented
355*0e209d39SAndroid Build Coastguard Worker
356*0e209d39SAndroid Build Coastguard Worker /** Normalizes dir_=1 (just after setOffset()) to dir_=0 (just after reset()). */
normalizeDir()357*0e209d39SAndroid Build Coastguard Worker inline int8_t normalizeDir() const { return dir_ == 1 ? 0 : dir_; }
358*0e209d39SAndroid Build Coastguard Worker
359*0e209d39SAndroid Build Coastguard Worker static UHashtable *computeMaxExpansions(const CollationData *data, UErrorCode &errorCode);
360*0e209d39SAndroid Build Coastguard Worker
361*0e209d39SAndroid Build Coastguard Worker static int32_t getMaxExpansion(const UHashtable *maxExpansions, int32_t order);
362*0e209d39SAndroid Build Coastguard Worker
363*0e209d39SAndroid Build Coastguard Worker // CollationElementIterator private data members ----------------------------
364*0e209d39SAndroid Build Coastguard Worker
365*0e209d39SAndroid Build Coastguard Worker CollationIterator *iter_; // owned
366*0e209d39SAndroid Build Coastguard Worker const RuleBasedCollator *rbc_; // aliased
367*0e209d39SAndroid Build Coastguard Worker uint32_t otherHalf_;
368*0e209d39SAndroid Build Coastguard Worker /**
369*0e209d39SAndroid Build Coastguard Worker * <0: backwards; 0: just after reset() (previous() begins from end);
370*0e209d39SAndroid Build Coastguard Worker * 1: just after setOffset(); >1: forward
371*0e209d39SAndroid Build Coastguard Worker */
372*0e209d39SAndroid Build Coastguard Worker int8_t dir_;
373*0e209d39SAndroid Build Coastguard Worker /**
374*0e209d39SAndroid Build Coastguard Worker * Stores offsets from expansions and from unsafe-backwards iteration,
375*0e209d39SAndroid Build Coastguard Worker * so that getOffset() returns intermediate offsets for the CEs
376*0e209d39SAndroid Build Coastguard Worker * that are consistent with forward iteration.
377*0e209d39SAndroid Build Coastguard Worker */
378*0e209d39SAndroid Build Coastguard Worker UVector32 *offsets_;
379*0e209d39SAndroid Build Coastguard Worker
380*0e209d39SAndroid Build Coastguard Worker UnicodeString string_;
381*0e209d39SAndroid Build Coastguard Worker };
382*0e209d39SAndroid Build Coastguard Worker
383*0e209d39SAndroid Build Coastguard Worker // CollationElementIterator inline method definitions --------------------------
384*0e209d39SAndroid Build Coastguard Worker
primaryOrder(int32_t order)385*0e209d39SAndroid Build Coastguard Worker inline int32_t CollationElementIterator::primaryOrder(int32_t order)
386*0e209d39SAndroid Build Coastguard Worker {
387*0e209d39SAndroid Build Coastguard Worker return (order >> 16) & 0xffff;
388*0e209d39SAndroid Build Coastguard Worker }
389*0e209d39SAndroid Build Coastguard Worker
secondaryOrder(int32_t order)390*0e209d39SAndroid Build Coastguard Worker inline int32_t CollationElementIterator::secondaryOrder(int32_t order)
391*0e209d39SAndroid Build Coastguard Worker {
392*0e209d39SAndroid Build Coastguard Worker return (order >> 8) & 0xff;
393*0e209d39SAndroid Build Coastguard Worker }
394*0e209d39SAndroid Build Coastguard Worker
tertiaryOrder(int32_t order)395*0e209d39SAndroid Build Coastguard Worker inline int32_t CollationElementIterator::tertiaryOrder(int32_t order)
396*0e209d39SAndroid Build Coastguard Worker {
397*0e209d39SAndroid Build Coastguard Worker return order & 0xff;
398*0e209d39SAndroid Build Coastguard Worker }
399*0e209d39SAndroid Build Coastguard Worker
isIgnorable(int32_t order)400*0e209d39SAndroid Build Coastguard Worker inline UBool CollationElementIterator::isIgnorable(int32_t order)
401*0e209d39SAndroid Build Coastguard Worker {
402*0e209d39SAndroid Build Coastguard Worker return (order & 0xffff0000) == 0;
403*0e209d39SAndroid Build Coastguard Worker }
404*0e209d39SAndroid Build Coastguard Worker
405*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
406*0e209d39SAndroid Build Coastguard Worker
407*0e209d39SAndroid Build Coastguard Worker #endif /* #if !UCONFIG_NO_COLLATION */
408*0e209d39SAndroid Build Coastguard Worker
409*0e209d39SAndroid Build Coastguard Worker #endif /* U_SHOW_CPLUSPLUS_API */
410*0e209d39SAndroid Build Coastguard Worker
411*0e209d39SAndroid Build Coastguard Worker #endif
412