1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru**********************************************************************
385bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho* Copyright (c) 2002-2008, International Business Machines
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Corporation and others.  All Rights Reserved.
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru**********************************************************************
6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef USETITER_H
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define USETITER_H
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h"
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uobject.h"
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/unistr.h"
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * \file
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * \brief C++ API: UnicodeSetIterator iterates over the contents of a UnicodeSet.
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_BEGIN
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass UnicodeSet;
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass UnicodeString;
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * UnicodeSetIterator iterates over the contents of a UnicodeSet.  It
27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * iterates over either code points or code point ranges.  After all
28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * code points or ranges have been returned, it returns the
2985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * multicharacter strings of the UnicodeSet, if any.
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * This class is not intended to be subclassed.  Consider any fields
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *  or methods declared as "protected" to be private.  The use of
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *  protected in this class is an artifact of history.
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>To iterate over code points and strings, use a loop like this:
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <pre>
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * UnicodeSetIterator it(set);
3885bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho * while (it.next()) {
3985bf2e2fbc60a9f938064abc8127d61da7d19882Claire Ho *     processItem(it.getString());
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * }
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * </pre>
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>Each item in the set is accessed as a string.  Set elements
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *    consisting of single code points are returned as strings containing
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *    just the one code point.
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <p>To iterate over code point ranges, instead of individual code points,
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *    use a loop like this:
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * <pre>
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * UnicodeSetIterator it(set);
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * while (it.nextRange()) {
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   if (it.isString()) {
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *     processString(it.getString());
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   } else {
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *     processCodepointRange(it.getCodepoint(), it.getCodepointEnd());
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   }
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * }
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * </pre>
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @author M. Davis
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @stable ICU 2.4
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass U_COMMON_API UnicodeSetIterator : public UObject {
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru protected:
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Value of <tt>codepoint</tt> if the iterator points to a string.
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * If <tt>codepoint == IS_STRING</tt>, then examine
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * <tt>string</tt> for the current iteration result.
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    enum { IS_STRING = -1 };
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Current code point, or the special value <tt>IS_STRING</tt>, if
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * the iterator points to a string.
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar32 codepoint;
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * When iterating over ranges using <tt>nextRange()</tt>,
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * <tt>codepointEnd</tt> contains the inclusive end of the
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * iteration range, if <tt>codepoint != IS_STRING</tt>.  If
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * iterating over code points using <tt>next()</tt>, or if
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * <tt>codepoint == IS_STRING</tt>, then the value of
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * <tt>codepointEnd</tt> is undefined.
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar32 codepointEnd;
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * If <tt>codepoint == IS_STRING</tt>, then <tt>string</tt> points
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * to the current string.  If <tt>codepoint != IS_STRING</tt>, the
94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * value of <tt>string</tt> is undefined.
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const UnicodeString* string;
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru public:
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Create an iterator over the given set.  The iterator is valid
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * only so long as <tt>set</tt> is valid.
104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @param set set to iterate over
105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeSetIterator(const UnicodeSet& set);
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Create an iterator over nothing.  <tt>next()</tt> and
111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * <tt>nextRange()</tt> return false. This is a convenience
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * constructor allowing the target to be set later.
113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeSetIterator();
116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Destructor.
119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual ~UnicodeSetIterator();
122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Returns true if the current element is a string.  If so, the
125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * caller can retrieve it with <tt>getString()</tt>.  If this
126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * method returns false, the current element is a code point or
127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * code point range, depending on whether <tt>next()</tt> or
128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * <tt>nextRange()</tt> was called.
129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Elements of types string and codepoint can both be retrieved
130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * with the function <tt>getString()</tt>.
131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Elements of type codepoint can also be retrieved with
132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * <tt>getCodepoint()</tt>.
133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * For ranges, <tt>getCodepoint()</tt> returns the starting codepoint
134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * of the range, and <tt>getCodepointEnd()</tt> returns the end
135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * of the range.
136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    inline UBool isString() const;
139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Returns the current code point, if <tt>isString()</tt> returned
142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * false.  Otherwise returns an undefined result.
143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    inline UChar32 getCodepoint() const;
146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Returns the end of the current code point range, if
149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * <tt>isString()</tt> returned false and <tt>nextRange()</tt> was
150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * called.  Otherwise returns an undefined result.
151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    inline UChar32 getCodepointEnd() const;
154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Returns the current string, if <tt>isString()</tt> returned
157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * true.  If the current iteration item is a code point, a UnicodeString
158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * containing that single code point is returned.
159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Ownership of the returned string remains with the iterator.
161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * The string is guaranteed to remain valid only until the iterator is
162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *   advanced to the next item, or until the iterator is deleted.
163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const UnicodeString& getString();
167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Advances the iteration position to the next element in the set,
170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * which can be either a single code point or a string.
171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * If there are no more elements in the set, return false.
172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * <p>
174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * If <tt>isString() == TRUE</tt>, the value is a
175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * string, otherwise the value is a
176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * single code point.  Elements of either type can be retrieved
177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * with the function <tt>getString()</tt>, while elements of
178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * consisting of a single code point can be retrieved with
179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * <tt>getCodepoint()</tt>
180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * <p>The order of iteration is all code points in sorted order,
182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * followed by all strings sorted order.    Do not mix
183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * calls to <tt>next()</tt> and <tt>nextRange()</tt> without
184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * calling <tt>reset()</tt> between them.  The results of doing so
185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * are undefined.
186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @return true if there was another element in the set.
188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool next();
191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Returns the next element in the set, either a code point range
194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * or a string.  If there are no more elements in the set, return
195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * false.  If <tt>isString() == TRUE</tt>, the value is a
196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * string and can be accessed with <tt>getString()</tt>.  Otherwise the value is a
197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * range of one or more code points from <tt>getCodepoint()</tt> to
198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * <tt>getCodepointeEnd()</tt> inclusive.
199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * <p>The order of iteration is all code points ranges in sorted
201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * order, followed by all strings sorted order.  Ranges are
202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * disjoint and non-contiguous.  The value returned from <tt>getString()</tt>
203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * is undefined unless <tt>isString() == TRUE</tt>.  Do not mix calls to
204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * <tt>next()</tt> and <tt>nextRange()</tt> without calling
205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * <tt>reset()</tt> between them.  The results of doing so are
206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * undefined.
207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @return true if there was another element in the set.
209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool nextRange();
212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Sets this iterator to visit the elements of the given set and
215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * resets it to the start of that set.  The iterator is valid only
216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * so long as <tt>set</tt> is valid.
217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @param set the set to iterate over.
218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void reset(const UnicodeSet& set);
221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * Resets this iterator to the start of the set.
224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    void reset();
227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * ICU "poor man's RTTI", returns a UClassID for this class.
230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    static UClassID U_EXPORT2 getStaticClassID();
234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * ICU "poor man's RTTI", returns a UClassID for the actual class.
237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *
238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual UClassID getDynamicClassID() const;
241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // ======================= PRIVATES ===========================
243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru protected:
245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // endElement and nextElements are really UChar32's, but we keep
247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // them as signed int32_t's so we can do comparisons with
248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    // endElement set to -1.  Leave them as int32_t's.
249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /** The set
250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const UnicodeSet* set;
253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /** End range
254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t endRange;
257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /** Range
258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t range;
261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /** End element
262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t endElement;
265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /** Next element
266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t nextElement;
269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    //UBool abbreviated;
270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /** Next string
271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t nextString;
274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /** String count
275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t stringCount;
278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /**
280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *  Points to the string to use when the caller asks for a
281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *  string and the current iteration item is a code point, not a string.
282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     *  @internal
283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeString *cpString;
285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /** Copy constructor. Disallowed.
287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeSetIterator(const UnicodeSetIterator&); // disallow
290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /** Assignment operator. Disallowed.
292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UnicodeSetIterator& operator=(const UnicodeSetIterator&); // disallow
295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    /** Load range
297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     * @stable ICU 2.4
298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru     */
299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    virtual void loadRange(int32_t range);
300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline UBool UnicodeSetIterator::isString() const {
304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return codepoint == (UChar32)IS_STRING;
305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline UChar32 UnicodeSetIterator::getCodepoint() const {
308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return codepoint;
309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
311ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruinline UChar32 UnicodeSetIterator::getCodepointEnd() const {
312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    return codepointEnd;
313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}
314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_NAMESPACE_END
317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
319