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