xref: /aosp_15_r20/external/icu/libandroidicu/include/unicode/uiter.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
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 *
6*0e209d39SAndroid Build Coastguard Worker *   Copyright (C) 2002-2011 International Business Machines
7*0e209d39SAndroid Build Coastguard Worker *   Corporation and others.  All Rights Reserved.
8*0e209d39SAndroid Build Coastguard Worker *
9*0e209d39SAndroid Build Coastguard Worker *******************************************************************************
10*0e209d39SAndroid Build Coastguard Worker *   file name:  uiter.h
11*0e209d39SAndroid Build Coastguard Worker *   encoding:   UTF-8
12*0e209d39SAndroid Build Coastguard Worker *   tab size:   8 (not used)
13*0e209d39SAndroid Build Coastguard Worker *   indentation:4
14*0e209d39SAndroid Build Coastguard Worker *
15*0e209d39SAndroid Build Coastguard Worker *   created on: 2002jan18
16*0e209d39SAndroid Build Coastguard Worker *   created by: Markus W. Scherer
17*0e209d39SAndroid Build Coastguard Worker */
18*0e209d39SAndroid Build Coastguard Worker 
19*0e209d39SAndroid Build Coastguard Worker #ifndef __UITER_H__
20*0e209d39SAndroid Build Coastguard Worker #define __UITER_H__
21*0e209d39SAndroid Build Coastguard Worker 
22*0e209d39SAndroid Build Coastguard Worker /**
23*0e209d39SAndroid Build Coastguard Worker  * \file
24*0e209d39SAndroid Build Coastguard Worker  * \brief C API: Unicode Character Iteration
25*0e209d39SAndroid Build Coastguard Worker  *
26*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
27*0e209d39SAndroid Build Coastguard Worker  */
28*0e209d39SAndroid Build Coastguard Worker 
29*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
30*0e209d39SAndroid Build Coastguard Worker 
31*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API
32*0e209d39SAndroid Build Coastguard Worker     U_NAMESPACE_BEGIN
33*0e209d39SAndroid Build Coastguard Worker 
34*0e209d39SAndroid Build Coastguard Worker     class CharacterIterator;
35*0e209d39SAndroid Build Coastguard Worker     class Replaceable;
36*0e209d39SAndroid Build Coastguard Worker 
37*0e209d39SAndroid Build Coastguard Worker     U_NAMESPACE_END
38*0e209d39SAndroid Build Coastguard Worker #endif
39*0e209d39SAndroid Build Coastguard Worker 
40*0e209d39SAndroid Build Coastguard Worker U_CDECL_BEGIN
41*0e209d39SAndroid Build Coastguard Worker 
42*0e209d39SAndroid Build Coastguard Worker struct UCharIterator;
43*0e209d39SAndroid Build Coastguard Worker typedef struct UCharIterator UCharIterator; /**< C typedef for struct UCharIterator. @stable ICU 2.1 */
44*0e209d39SAndroid Build Coastguard Worker 
45*0e209d39SAndroid Build Coastguard Worker /**
46*0e209d39SAndroid Build Coastguard Worker  * Origin constants for UCharIterator.getIndex() and UCharIterator.move().
47*0e209d39SAndroid Build Coastguard Worker  * @see UCharIteratorMove
48*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
49*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.1
50*0e209d39SAndroid Build Coastguard Worker  */
51*0e209d39SAndroid Build Coastguard Worker typedef enum UCharIteratorOrigin {
52*0e209d39SAndroid Build Coastguard Worker     UITER_START, UITER_CURRENT, UITER_LIMIT, UITER_ZERO, UITER_LENGTH
53*0e209d39SAndroid Build Coastguard Worker } UCharIteratorOrigin;
54*0e209d39SAndroid Build Coastguard Worker 
55*0e209d39SAndroid Build Coastguard Worker /** Constants for UCharIterator. @stable ICU 2.6 */
56*0e209d39SAndroid Build Coastguard Worker enum {
57*0e209d39SAndroid Build Coastguard Worker     /**
58*0e209d39SAndroid Build Coastguard Worker      * Constant value that may be returned by UCharIteratorMove
59*0e209d39SAndroid Build Coastguard Worker      * indicating that the final UTF-16 index is not known, but that the move succeeded.
60*0e209d39SAndroid Build Coastguard Worker      * This can occur when moving relative to limit or length, or
61*0e209d39SAndroid Build Coastguard Worker      * when moving relative to the current index after a setState()
62*0e209d39SAndroid Build Coastguard Worker      * when the current UTF-16 index is not known.
63*0e209d39SAndroid Build Coastguard Worker      *
64*0e209d39SAndroid Build Coastguard Worker      * It would be very inefficient to have to count from the beginning of the text
65*0e209d39SAndroid Build Coastguard Worker      * just to get the current/limit/length index after moving relative to it.
66*0e209d39SAndroid Build Coastguard Worker      * The actual index can be determined with getIndex(UITER_CURRENT)
67*0e209d39SAndroid Build Coastguard Worker      * which will count the UChars if necessary.
68*0e209d39SAndroid Build Coastguard Worker      *
69*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.6
70*0e209d39SAndroid Build Coastguard Worker      */
71*0e209d39SAndroid Build Coastguard Worker     UITER_UNKNOWN_INDEX=-2
72*0e209d39SAndroid Build Coastguard Worker };
73*0e209d39SAndroid Build Coastguard Worker 
74*0e209d39SAndroid Build Coastguard Worker 
75*0e209d39SAndroid Build Coastguard Worker /**
76*0e209d39SAndroid Build Coastguard Worker  * Constant for UCharIterator getState() indicating an error or
77*0e209d39SAndroid Build Coastguard Worker  * an unknown state.
78*0e209d39SAndroid Build Coastguard Worker  * Returned by uiter_getState()/UCharIteratorGetState
79*0e209d39SAndroid Build Coastguard Worker  * when an error occurs.
80*0e209d39SAndroid Build Coastguard Worker  * Also, some UCharIterator implementations may not be able to return
81*0e209d39SAndroid Build Coastguard Worker  * a valid state for each position. This will be clearly documented
82*0e209d39SAndroid Build Coastguard Worker  * for each such iterator (none of the public ones here).
83*0e209d39SAndroid Build Coastguard Worker  *
84*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.6
85*0e209d39SAndroid Build Coastguard Worker  */
86*0e209d39SAndroid Build Coastguard Worker #define UITER_NO_STATE ((uint32_t)0xffffffff)
87*0e209d39SAndroid Build Coastguard Worker 
88*0e209d39SAndroid Build Coastguard Worker /**
89*0e209d39SAndroid Build Coastguard Worker  * Function type declaration for UCharIterator.getIndex().
90*0e209d39SAndroid Build Coastguard Worker  *
91*0e209d39SAndroid Build Coastguard Worker  * Gets the current position, or the start or limit of the
92*0e209d39SAndroid Build Coastguard Worker  * iteration range.
93*0e209d39SAndroid Build Coastguard Worker  *
94*0e209d39SAndroid Build Coastguard Worker  * This function may perform slowly for UITER_CURRENT after setState() was called,
95*0e209d39SAndroid Build Coastguard Worker  * or for UITER_LENGTH, because an iterator implementation may have to count
96*0e209d39SAndroid Build Coastguard Worker  * UChars if the underlying storage is not UTF-16.
97*0e209d39SAndroid Build Coastguard Worker  *
98*0e209d39SAndroid Build Coastguard Worker  * @param iter the UCharIterator structure ("this pointer")
99*0e209d39SAndroid Build Coastguard Worker  * @param origin get the 0, start, limit, length, or current index
100*0e209d39SAndroid Build Coastguard Worker  * @return the requested index, or U_SENTINEL in an error condition
101*0e209d39SAndroid Build Coastguard Worker  *
102*0e209d39SAndroid Build Coastguard Worker  * @see UCharIteratorOrigin
103*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
104*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.1
105*0e209d39SAndroid Build Coastguard Worker  */
106*0e209d39SAndroid Build Coastguard Worker typedef int32_t U_CALLCONV
107*0e209d39SAndroid Build Coastguard Worker UCharIteratorGetIndex(UCharIterator *iter, UCharIteratorOrigin origin);
108*0e209d39SAndroid Build Coastguard Worker 
109*0e209d39SAndroid Build Coastguard Worker /**
110*0e209d39SAndroid Build Coastguard Worker  * Function type declaration for UCharIterator.move().
111*0e209d39SAndroid Build Coastguard Worker  *
112*0e209d39SAndroid Build Coastguard Worker  * Use iter->move(iter, index, UITER_ZERO) like CharacterIterator::setIndex(index).
113*0e209d39SAndroid Build Coastguard Worker  *
114*0e209d39SAndroid Build Coastguard Worker  * Moves the current position relative to the start or limit of the
115*0e209d39SAndroid Build Coastguard Worker  * iteration range, or relative to the current position itself.
116*0e209d39SAndroid Build Coastguard Worker  * The movement is expressed in numbers of code units forward
117*0e209d39SAndroid Build Coastguard Worker  * or backward by specifying a positive or negative delta.
118*0e209d39SAndroid Build Coastguard Worker  * Out of bounds movement will be pinned to the start or limit.
119*0e209d39SAndroid Build Coastguard Worker  *
120*0e209d39SAndroid Build Coastguard Worker  * This function may perform slowly for moving relative to UITER_LENGTH
121*0e209d39SAndroid Build Coastguard Worker  * because an iterator implementation may have to count the rest of the
122*0e209d39SAndroid Build Coastguard Worker  * UChars if the native storage is not UTF-16.
123*0e209d39SAndroid Build Coastguard Worker  *
124*0e209d39SAndroid Build Coastguard Worker  * When moving relative to the limit or length, or
125*0e209d39SAndroid Build Coastguard Worker  * relative to the current position after setState() was called,
126*0e209d39SAndroid Build Coastguard Worker  * move() may return UITER_UNKNOWN_INDEX (-2) to avoid an inefficient
127*0e209d39SAndroid Build Coastguard Worker  * determination of the actual UTF-16 index.
128*0e209d39SAndroid Build Coastguard Worker  * The actual index can be determined with getIndex(UITER_CURRENT)
129*0e209d39SAndroid Build Coastguard Worker  * which will count the UChars if necessary.
130*0e209d39SAndroid Build Coastguard Worker  * See UITER_UNKNOWN_INDEX for details.
131*0e209d39SAndroid Build Coastguard Worker  *
132*0e209d39SAndroid Build Coastguard Worker  * @param iter the UCharIterator structure ("this pointer")
133*0e209d39SAndroid Build Coastguard Worker  * @param delta can be positive, zero, or negative
134*0e209d39SAndroid Build Coastguard Worker  * @param origin move relative to the 0, start, limit, length, or current index
135*0e209d39SAndroid Build Coastguard Worker  * @return the new index, or U_SENTINEL on an error condition,
136*0e209d39SAndroid Build Coastguard Worker  *         or UITER_UNKNOWN_INDEX when the index is not known.
137*0e209d39SAndroid Build Coastguard Worker  *
138*0e209d39SAndroid Build Coastguard Worker  * @see UCharIteratorOrigin
139*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
140*0e209d39SAndroid Build Coastguard Worker  * @see UITER_UNKNOWN_INDEX
141*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.1
142*0e209d39SAndroid Build Coastguard Worker  */
143*0e209d39SAndroid Build Coastguard Worker typedef int32_t U_CALLCONV
144*0e209d39SAndroid Build Coastguard Worker UCharIteratorMove(UCharIterator *iter, int32_t delta, UCharIteratorOrigin origin);
145*0e209d39SAndroid Build Coastguard Worker 
146*0e209d39SAndroid Build Coastguard Worker /**
147*0e209d39SAndroid Build Coastguard Worker  * Function type declaration for UCharIterator.hasNext().
148*0e209d39SAndroid Build Coastguard Worker  *
149*0e209d39SAndroid Build Coastguard Worker  * Check if current() and next() can still
150*0e209d39SAndroid Build Coastguard Worker  * return another code unit.
151*0e209d39SAndroid Build Coastguard Worker  *
152*0e209d39SAndroid Build Coastguard Worker  * @param iter the UCharIterator structure ("this pointer")
153*0e209d39SAndroid Build Coastguard Worker  * @return boolean value for whether current() and next() can still return another code unit
154*0e209d39SAndroid Build Coastguard Worker  *
155*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
156*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.1
157*0e209d39SAndroid Build Coastguard Worker  */
158*0e209d39SAndroid Build Coastguard Worker typedef UBool U_CALLCONV
159*0e209d39SAndroid Build Coastguard Worker UCharIteratorHasNext(UCharIterator *iter);
160*0e209d39SAndroid Build Coastguard Worker 
161*0e209d39SAndroid Build Coastguard Worker /**
162*0e209d39SAndroid Build Coastguard Worker  * Function type declaration for UCharIterator.hasPrevious().
163*0e209d39SAndroid Build Coastguard Worker  *
164*0e209d39SAndroid Build Coastguard Worker  * Check if previous() can still return another code unit.
165*0e209d39SAndroid Build Coastguard Worker  *
166*0e209d39SAndroid Build Coastguard Worker  * @param iter the UCharIterator structure ("this pointer")
167*0e209d39SAndroid Build Coastguard Worker  * @return boolean value for whether previous() can still return another code unit
168*0e209d39SAndroid Build Coastguard Worker  *
169*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
170*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.1
171*0e209d39SAndroid Build Coastguard Worker  */
172*0e209d39SAndroid Build Coastguard Worker typedef UBool U_CALLCONV
173*0e209d39SAndroid Build Coastguard Worker UCharIteratorHasPrevious(UCharIterator *iter);
174*0e209d39SAndroid Build Coastguard Worker 
175*0e209d39SAndroid Build Coastguard Worker /**
176*0e209d39SAndroid Build Coastguard Worker  * Function type declaration for UCharIterator.current().
177*0e209d39SAndroid Build Coastguard Worker  *
178*0e209d39SAndroid Build Coastguard Worker  * Return the code unit at the current position,
179*0e209d39SAndroid Build Coastguard Worker  * or U_SENTINEL if there is none (index is at the limit).
180*0e209d39SAndroid Build Coastguard Worker  *
181*0e209d39SAndroid Build Coastguard Worker  * @param iter the UCharIterator structure ("this pointer")
182*0e209d39SAndroid Build Coastguard Worker  * @return the current code unit
183*0e209d39SAndroid Build Coastguard Worker  *
184*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
185*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.1
186*0e209d39SAndroid Build Coastguard Worker  */
187*0e209d39SAndroid Build Coastguard Worker typedef UChar32 U_CALLCONV
188*0e209d39SAndroid Build Coastguard Worker UCharIteratorCurrent(UCharIterator *iter);
189*0e209d39SAndroid Build Coastguard Worker 
190*0e209d39SAndroid Build Coastguard Worker /**
191*0e209d39SAndroid Build Coastguard Worker  * Function type declaration for UCharIterator.next().
192*0e209d39SAndroid Build Coastguard Worker  *
193*0e209d39SAndroid Build Coastguard Worker  * Return the code unit at the current index and increment
194*0e209d39SAndroid Build Coastguard Worker  * the index (post-increment, like s[i++]),
195*0e209d39SAndroid Build Coastguard Worker  * or return U_SENTINEL if there is none (index is at the limit).
196*0e209d39SAndroid Build Coastguard Worker  *
197*0e209d39SAndroid Build Coastguard Worker  * @param iter the UCharIterator structure ("this pointer")
198*0e209d39SAndroid Build Coastguard Worker  * @return the current code unit (and post-increment the current index)
199*0e209d39SAndroid Build Coastguard Worker  *
200*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
201*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.1
202*0e209d39SAndroid Build Coastguard Worker  */
203*0e209d39SAndroid Build Coastguard Worker typedef UChar32 U_CALLCONV
204*0e209d39SAndroid Build Coastguard Worker UCharIteratorNext(UCharIterator *iter);
205*0e209d39SAndroid Build Coastguard Worker 
206*0e209d39SAndroid Build Coastguard Worker /**
207*0e209d39SAndroid Build Coastguard Worker  * Function type declaration for UCharIterator.previous().
208*0e209d39SAndroid Build Coastguard Worker  *
209*0e209d39SAndroid Build Coastguard Worker  * Decrement the index and return the code unit from there
210*0e209d39SAndroid Build Coastguard Worker  * (pre-decrement, like s[--i]),
211*0e209d39SAndroid Build Coastguard Worker  * or return U_SENTINEL if there is none (index is at the start).
212*0e209d39SAndroid Build Coastguard Worker  *
213*0e209d39SAndroid Build Coastguard Worker  * @param iter the UCharIterator structure ("this pointer")
214*0e209d39SAndroid Build Coastguard Worker  * @return the previous code unit (after pre-decrementing the current index)
215*0e209d39SAndroid Build Coastguard Worker  *
216*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
217*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.1
218*0e209d39SAndroid Build Coastguard Worker  */
219*0e209d39SAndroid Build Coastguard Worker typedef UChar32 U_CALLCONV
220*0e209d39SAndroid Build Coastguard Worker UCharIteratorPrevious(UCharIterator *iter);
221*0e209d39SAndroid Build Coastguard Worker 
222*0e209d39SAndroid Build Coastguard Worker /**
223*0e209d39SAndroid Build Coastguard Worker  * Function type declaration for UCharIterator.reservedFn().
224*0e209d39SAndroid Build Coastguard Worker  * Reserved for future use.
225*0e209d39SAndroid Build Coastguard Worker  *
226*0e209d39SAndroid Build Coastguard Worker  * @param iter the UCharIterator structure ("this pointer")
227*0e209d39SAndroid Build Coastguard Worker  * @param something some integer argument
228*0e209d39SAndroid Build Coastguard Worker  * @return some integer
229*0e209d39SAndroid Build Coastguard Worker  *
230*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
231*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.1
232*0e209d39SAndroid Build Coastguard Worker  */
233*0e209d39SAndroid Build Coastguard Worker typedef int32_t U_CALLCONV
234*0e209d39SAndroid Build Coastguard Worker UCharIteratorReserved(UCharIterator *iter, int32_t something);
235*0e209d39SAndroid Build Coastguard Worker 
236*0e209d39SAndroid Build Coastguard Worker /**
237*0e209d39SAndroid Build Coastguard Worker  * Function type declaration for UCharIterator.getState().
238*0e209d39SAndroid Build Coastguard Worker  *
239*0e209d39SAndroid Build Coastguard Worker  * Get the "state" of the iterator in the form of a single 32-bit word.
240*0e209d39SAndroid Build Coastguard Worker  * It is recommended that the state value be calculated to be as small as
241*0e209d39SAndroid Build Coastguard Worker  * is feasible. For strings with limited lengths, fewer than 32 bits may
242*0e209d39SAndroid Build Coastguard Worker  * be sufficient.
243*0e209d39SAndroid Build Coastguard Worker  *
244*0e209d39SAndroid Build Coastguard Worker  * This is used together with setState()/UCharIteratorSetState
245*0e209d39SAndroid Build Coastguard Worker  * to save and restore the iterator position more efficiently than with
246*0e209d39SAndroid Build Coastguard Worker  * getIndex()/move().
247*0e209d39SAndroid Build Coastguard Worker  *
248*0e209d39SAndroid Build Coastguard Worker  * The iterator state is defined as a uint32_t value because it is designed
249*0e209d39SAndroid Build Coastguard Worker  * for use in ucol_nextSortKeyPart() which provides 32 bits to store the state
250*0e209d39SAndroid Build Coastguard Worker  * of the character iterator.
251*0e209d39SAndroid Build Coastguard Worker  *
252*0e209d39SAndroid Build Coastguard Worker  * With some UCharIterator implementations (e.g., UTF-8),
253*0e209d39SAndroid Build Coastguard Worker  * getting and setting the UTF-16 index with existing functions
254*0e209d39SAndroid Build Coastguard Worker  * (getIndex(UITER_CURRENT) followed by move(pos, UITER_ZERO)) is possible but
255*0e209d39SAndroid Build Coastguard Worker  * relatively slow because the iterator has to "walk" from a known index
256*0e209d39SAndroid Build Coastguard Worker  * to the requested one.
257*0e209d39SAndroid Build Coastguard Worker  * This takes more time the farther it needs to go.
258*0e209d39SAndroid Build Coastguard Worker  *
259*0e209d39SAndroid Build Coastguard Worker  * An opaque state value allows an iterator implementation to provide
260*0e209d39SAndroid Build Coastguard Worker  * an internal index (UTF-8: the source byte array index) for
261*0e209d39SAndroid Build Coastguard Worker  * fast, constant-time restoration.
262*0e209d39SAndroid Build Coastguard Worker  *
263*0e209d39SAndroid Build Coastguard Worker  * After calling setState(), a getIndex(UITER_CURRENT) may be slow because
264*0e209d39SAndroid Build Coastguard Worker  * the UTF-16 index may not be restored as well, but the iterator can deliver
265*0e209d39SAndroid Build Coastguard Worker  * the correct text contents and move relative to the current position
266*0e209d39SAndroid Build Coastguard Worker  * without performance degradation.
267*0e209d39SAndroid Build Coastguard Worker  *
268*0e209d39SAndroid Build Coastguard Worker  * Some UCharIterator implementations may not be able to return
269*0e209d39SAndroid Build Coastguard Worker  * a valid state for each position, in which case they return UITER_NO_STATE instead.
270*0e209d39SAndroid Build Coastguard Worker  * This will be clearly documented for each such iterator (none of the public ones here).
271*0e209d39SAndroid Build Coastguard Worker  *
272*0e209d39SAndroid Build Coastguard Worker  * @param iter the UCharIterator structure ("this pointer")
273*0e209d39SAndroid Build Coastguard Worker  * @return the state word
274*0e209d39SAndroid Build Coastguard Worker  *
275*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
276*0e209d39SAndroid Build Coastguard Worker  * @see UCharIteratorSetState
277*0e209d39SAndroid Build Coastguard Worker  * @see UITER_NO_STATE
278*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.6
279*0e209d39SAndroid Build Coastguard Worker  */
280*0e209d39SAndroid Build Coastguard Worker typedef uint32_t U_CALLCONV
281*0e209d39SAndroid Build Coastguard Worker UCharIteratorGetState(const UCharIterator *iter);
282*0e209d39SAndroid Build Coastguard Worker 
283*0e209d39SAndroid Build Coastguard Worker /**
284*0e209d39SAndroid Build Coastguard Worker  * Function type declaration for UCharIterator.setState().
285*0e209d39SAndroid Build Coastguard Worker  *
286*0e209d39SAndroid Build Coastguard Worker  * Restore the "state" of the iterator using a state word from a getState() call.
287*0e209d39SAndroid Build Coastguard Worker  * The iterator object need not be the same one as for which getState() was called,
288*0e209d39SAndroid Build Coastguard Worker  * but it must be of the same type (set up using the same uiter_setXYZ function)
289*0e209d39SAndroid Build Coastguard Worker  * and it must iterate over the same string
290*0e209d39SAndroid Build Coastguard Worker  * (binary identical regardless of memory address).
291*0e209d39SAndroid Build Coastguard Worker  * For more about the state word see UCharIteratorGetState.
292*0e209d39SAndroid Build Coastguard Worker  *
293*0e209d39SAndroid Build Coastguard Worker  * After calling setState(), a getIndex(UITER_CURRENT) may be slow because
294*0e209d39SAndroid Build Coastguard Worker  * the UTF-16 index may not be restored as well, but the iterator can deliver
295*0e209d39SAndroid Build Coastguard Worker  * the correct text contents and move relative to the current position
296*0e209d39SAndroid Build Coastguard Worker  * without performance degradation.
297*0e209d39SAndroid Build Coastguard Worker  *
298*0e209d39SAndroid Build Coastguard Worker  * @param iter the UCharIterator structure ("this pointer")
299*0e209d39SAndroid Build Coastguard Worker  * @param state the state word from a getState() call
300*0e209d39SAndroid Build Coastguard Worker  *              on a same-type, same-string iterator
301*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode Must be a valid pointer to an error code value,
302*0e209d39SAndroid Build Coastguard Worker  *                   which must not indicate a failure before the function call.
303*0e209d39SAndroid Build Coastguard Worker  *
304*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
305*0e209d39SAndroid Build Coastguard Worker  * @see UCharIteratorGetState
306*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.6
307*0e209d39SAndroid Build Coastguard Worker  */
308*0e209d39SAndroid Build Coastguard Worker typedef void U_CALLCONV
309*0e209d39SAndroid Build Coastguard Worker UCharIteratorSetState(UCharIterator *iter, uint32_t state, UErrorCode *pErrorCode);
310*0e209d39SAndroid Build Coastguard Worker 
311*0e209d39SAndroid Build Coastguard Worker 
312*0e209d39SAndroid Build Coastguard Worker /**
313*0e209d39SAndroid Build Coastguard Worker  * C API for code unit iteration.
314*0e209d39SAndroid Build Coastguard Worker  * This can be used as a C wrapper around
315*0e209d39SAndroid Build Coastguard Worker  * CharacterIterator, Replaceable, or implemented using simple strings, etc.
316*0e209d39SAndroid Build Coastguard Worker  *
317*0e209d39SAndroid Build Coastguard Worker  * There are two roles for using UCharIterator:
318*0e209d39SAndroid Build Coastguard Worker  *
319*0e209d39SAndroid Build Coastguard Worker  * A "provider" sets the necessary function pointers and controls the "protected"
320*0e209d39SAndroid Build Coastguard Worker  * fields of the UCharIterator structure. A "provider" passes a UCharIterator
321*0e209d39SAndroid Build Coastguard Worker  * into C APIs that need a UCharIterator as an abstract, flexible string interface.
322*0e209d39SAndroid Build Coastguard Worker  *
323*0e209d39SAndroid Build Coastguard Worker  * Implementations of such C APIs are "callers" of UCharIterator functions;
324*0e209d39SAndroid Build Coastguard Worker  * they only use the "public" function pointers and never access the "protected"
325*0e209d39SAndroid Build Coastguard Worker  * fields directly.
326*0e209d39SAndroid Build Coastguard Worker  *
327*0e209d39SAndroid Build Coastguard Worker  * The current() and next() functions only check the current index against the
328*0e209d39SAndroid Build Coastguard Worker  * limit, and previous() only checks the current index against the start,
329*0e209d39SAndroid Build Coastguard Worker  * to see if the iterator already reached the end of the iteration range.
330*0e209d39SAndroid Build Coastguard Worker  *
331*0e209d39SAndroid Build Coastguard Worker  * The assumption - in all iterators - is that the index is moved via the API,
332*0e209d39SAndroid Build Coastguard Worker  * which means it won't go out of bounds, or the index is modified by
333*0e209d39SAndroid Build Coastguard Worker  * user code that knows enough about the iterator implementation to set valid
334*0e209d39SAndroid Build Coastguard Worker  * index values.
335*0e209d39SAndroid Build Coastguard Worker  *
336*0e209d39SAndroid Build Coastguard Worker  * UCharIterator functions return code unit values 0..0xffff,
337*0e209d39SAndroid Build Coastguard Worker  * or U_SENTINEL if the iteration bounds are reached.
338*0e209d39SAndroid Build Coastguard Worker  *
339*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.1
340*0e209d39SAndroid Build Coastguard Worker  */
341*0e209d39SAndroid Build Coastguard Worker struct UCharIterator {
342*0e209d39SAndroid Build Coastguard Worker     /**
343*0e209d39SAndroid Build Coastguard Worker      * (protected) Pointer to string or wrapped object or similar.
344*0e209d39SAndroid Build Coastguard Worker      * Not used by caller.
345*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.1
346*0e209d39SAndroid Build Coastguard Worker      */
347*0e209d39SAndroid Build Coastguard Worker     const void *context;
348*0e209d39SAndroid Build Coastguard Worker 
349*0e209d39SAndroid Build Coastguard Worker     /**
350*0e209d39SAndroid Build Coastguard Worker      * (protected) Length of string or similar.
351*0e209d39SAndroid Build Coastguard Worker      * Not used by caller.
352*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.1
353*0e209d39SAndroid Build Coastguard Worker      */
354*0e209d39SAndroid Build Coastguard Worker     int32_t length;
355*0e209d39SAndroid Build Coastguard Worker 
356*0e209d39SAndroid Build Coastguard Worker     /**
357*0e209d39SAndroid Build Coastguard Worker      * (protected) Start index or similar.
358*0e209d39SAndroid Build Coastguard Worker      * Not used by caller.
359*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.1
360*0e209d39SAndroid Build Coastguard Worker      */
361*0e209d39SAndroid Build Coastguard Worker     int32_t start;
362*0e209d39SAndroid Build Coastguard Worker 
363*0e209d39SAndroid Build Coastguard Worker     /**
364*0e209d39SAndroid Build Coastguard Worker      * (protected) Current index or similar.
365*0e209d39SAndroid Build Coastguard Worker      * Not used by caller.
366*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.1
367*0e209d39SAndroid Build Coastguard Worker      */
368*0e209d39SAndroid Build Coastguard Worker     int32_t index;
369*0e209d39SAndroid Build Coastguard Worker 
370*0e209d39SAndroid Build Coastguard Worker     /**
371*0e209d39SAndroid Build Coastguard Worker      * (protected) Limit index or similar.
372*0e209d39SAndroid Build Coastguard Worker      * Not used by caller.
373*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.1
374*0e209d39SAndroid Build Coastguard Worker      */
375*0e209d39SAndroid Build Coastguard Worker     int32_t limit;
376*0e209d39SAndroid Build Coastguard Worker 
377*0e209d39SAndroid Build Coastguard Worker     /**
378*0e209d39SAndroid Build Coastguard Worker      * (protected) Used by UTF-8 iterators and possibly others.
379*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.1
380*0e209d39SAndroid Build Coastguard Worker      */
381*0e209d39SAndroid Build Coastguard Worker     int32_t reservedField;
382*0e209d39SAndroid Build Coastguard Worker 
383*0e209d39SAndroid Build Coastguard Worker     /**
384*0e209d39SAndroid Build Coastguard Worker      * (public) Returns the current position or the
385*0e209d39SAndroid Build Coastguard Worker      * start or limit index of the iteration range.
386*0e209d39SAndroid Build Coastguard Worker      *
387*0e209d39SAndroid Build Coastguard Worker      * @see UCharIteratorGetIndex
388*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.1
389*0e209d39SAndroid Build Coastguard Worker      */
390*0e209d39SAndroid Build Coastguard Worker     UCharIteratorGetIndex *getIndex;
391*0e209d39SAndroid Build Coastguard Worker 
392*0e209d39SAndroid Build Coastguard Worker     /**
393*0e209d39SAndroid Build Coastguard Worker      * (public) Moves the current position relative to the start or limit of the
394*0e209d39SAndroid Build Coastguard Worker      * iteration range, or relative to the current position itself.
395*0e209d39SAndroid Build Coastguard Worker      * The movement is expressed in numbers of code units forward
396*0e209d39SAndroid Build Coastguard Worker      * or backward by specifying a positive or negative delta.
397*0e209d39SAndroid Build Coastguard Worker      *
398*0e209d39SAndroid Build Coastguard Worker      * @see UCharIteratorMove
399*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.1
400*0e209d39SAndroid Build Coastguard Worker      */
401*0e209d39SAndroid Build Coastguard Worker     UCharIteratorMove *move;
402*0e209d39SAndroid Build Coastguard Worker 
403*0e209d39SAndroid Build Coastguard Worker     /**
404*0e209d39SAndroid Build Coastguard Worker      * (public) Check if current() and next() can still
405*0e209d39SAndroid Build Coastguard Worker      * return another code unit.
406*0e209d39SAndroid Build Coastguard Worker      *
407*0e209d39SAndroid Build Coastguard Worker      * @see UCharIteratorHasNext
408*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.1
409*0e209d39SAndroid Build Coastguard Worker      */
410*0e209d39SAndroid Build Coastguard Worker     UCharIteratorHasNext *hasNext;
411*0e209d39SAndroid Build Coastguard Worker 
412*0e209d39SAndroid Build Coastguard Worker     /**
413*0e209d39SAndroid Build Coastguard Worker      * (public) Check if previous() can still return another code unit.
414*0e209d39SAndroid Build Coastguard Worker      *
415*0e209d39SAndroid Build Coastguard Worker      * @see UCharIteratorHasPrevious
416*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.1
417*0e209d39SAndroid Build Coastguard Worker      */
418*0e209d39SAndroid Build Coastguard Worker     UCharIteratorHasPrevious *hasPrevious;
419*0e209d39SAndroid Build Coastguard Worker 
420*0e209d39SAndroid Build Coastguard Worker     /**
421*0e209d39SAndroid Build Coastguard Worker      * (public) Return the code unit at the current position,
422*0e209d39SAndroid Build Coastguard Worker      * or U_SENTINEL if there is none (index is at the limit).
423*0e209d39SAndroid Build Coastguard Worker      *
424*0e209d39SAndroid Build Coastguard Worker      * @see UCharIteratorCurrent
425*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.1
426*0e209d39SAndroid Build Coastguard Worker      */
427*0e209d39SAndroid Build Coastguard Worker     UCharIteratorCurrent *current;
428*0e209d39SAndroid Build Coastguard Worker 
429*0e209d39SAndroid Build Coastguard Worker     /**
430*0e209d39SAndroid Build Coastguard Worker      * (public) Return the code unit at the current index and increment
431*0e209d39SAndroid Build Coastguard Worker      * the index (post-increment, like s[i++]),
432*0e209d39SAndroid Build Coastguard Worker      * or return U_SENTINEL if there is none (index is at the limit).
433*0e209d39SAndroid Build Coastguard Worker      *
434*0e209d39SAndroid Build Coastguard Worker      * @see UCharIteratorNext
435*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.1
436*0e209d39SAndroid Build Coastguard Worker      */
437*0e209d39SAndroid Build Coastguard Worker     UCharIteratorNext *next;
438*0e209d39SAndroid Build Coastguard Worker 
439*0e209d39SAndroid Build Coastguard Worker     /**
440*0e209d39SAndroid Build Coastguard Worker      * (public) Decrement the index and return the code unit from there
441*0e209d39SAndroid Build Coastguard Worker      * (pre-decrement, like s[--i]),
442*0e209d39SAndroid Build Coastguard Worker      * or return U_SENTINEL if there is none (index is at the start).
443*0e209d39SAndroid Build Coastguard Worker      *
444*0e209d39SAndroid Build Coastguard Worker      * @see UCharIteratorPrevious
445*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.1
446*0e209d39SAndroid Build Coastguard Worker      */
447*0e209d39SAndroid Build Coastguard Worker     UCharIteratorPrevious *previous;
448*0e209d39SAndroid Build Coastguard Worker 
449*0e209d39SAndroid Build Coastguard Worker     /**
450*0e209d39SAndroid Build Coastguard Worker      * (public) Reserved for future use. Currently NULL.
451*0e209d39SAndroid Build Coastguard Worker      *
452*0e209d39SAndroid Build Coastguard Worker      * @see UCharIteratorReserved
453*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.1
454*0e209d39SAndroid Build Coastguard Worker      */
455*0e209d39SAndroid Build Coastguard Worker     UCharIteratorReserved *reservedFn;
456*0e209d39SAndroid Build Coastguard Worker 
457*0e209d39SAndroid Build Coastguard Worker     /**
458*0e209d39SAndroid Build Coastguard Worker      * (public) Return the state of the iterator, to be restored later with setState().
459*0e209d39SAndroid Build Coastguard Worker      * This function pointer is NULL if the iterator does not implement it.
460*0e209d39SAndroid Build Coastguard Worker      *
461*0e209d39SAndroid Build Coastguard Worker      * @see UCharIteratorGet
462*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.6
463*0e209d39SAndroid Build Coastguard Worker      */
464*0e209d39SAndroid Build Coastguard Worker     UCharIteratorGetState *getState;
465*0e209d39SAndroid Build Coastguard Worker 
466*0e209d39SAndroid Build Coastguard Worker     /**
467*0e209d39SAndroid Build Coastguard Worker      * (public) Restore the iterator state from the state word from a call
468*0e209d39SAndroid Build Coastguard Worker      * to getState().
469*0e209d39SAndroid Build Coastguard Worker      * This function pointer is NULL if the iterator does not implement it.
470*0e209d39SAndroid Build Coastguard Worker      *
471*0e209d39SAndroid Build Coastguard Worker      * @see UCharIteratorSet
472*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.6
473*0e209d39SAndroid Build Coastguard Worker      */
474*0e209d39SAndroid Build Coastguard Worker     UCharIteratorSetState *setState;
475*0e209d39SAndroid Build Coastguard Worker };
476*0e209d39SAndroid Build Coastguard Worker 
477*0e209d39SAndroid Build Coastguard Worker /**
478*0e209d39SAndroid Build Coastguard Worker  * Helper function for UCharIterator to get the code point
479*0e209d39SAndroid Build Coastguard Worker  * at the current index.
480*0e209d39SAndroid Build Coastguard Worker  *
481*0e209d39SAndroid Build Coastguard Worker  * Return the code point that includes the code unit at the current position,
482*0e209d39SAndroid Build Coastguard Worker  * or U_SENTINEL if there is none (index is at the limit).
483*0e209d39SAndroid Build Coastguard Worker  * If the current code unit is a lead or trail surrogate,
484*0e209d39SAndroid Build Coastguard Worker  * then the following or preceding surrogate is used to form
485*0e209d39SAndroid Build Coastguard Worker  * the code point value.
486*0e209d39SAndroid Build Coastguard Worker  *
487*0e209d39SAndroid Build Coastguard Worker  * @param iter the UCharIterator structure ("this pointer")
488*0e209d39SAndroid Build Coastguard Worker  * @return the current code point
489*0e209d39SAndroid Build Coastguard Worker  *
490*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
491*0e209d39SAndroid Build Coastguard Worker  * @see U16_GET
492*0e209d39SAndroid Build Coastguard Worker  * @see UnicodeString::char32At()
493*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.1
494*0e209d39SAndroid Build Coastguard Worker  */
495*0e209d39SAndroid Build Coastguard Worker U_CAPI UChar32 U_EXPORT2
496*0e209d39SAndroid Build Coastguard Worker uiter_current32(UCharIterator *iter);
497*0e209d39SAndroid Build Coastguard Worker 
498*0e209d39SAndroid Build Coastguard Worker /**
499*0e209d39SAndroid Build Coastguard Worker  * Helper function for UCharIterator to get the next code point.
500*0e209d39SAndroid Build Coastguard Worker  *
501*0e209d39SAndroid Build Coastguard Worker  * Return the code point at the current index and increment
502*0e209d39SAndroid Build Coastguard Worker  * the index (post-increment, like s[i++]),
503*0e209d39SAndroid Build Coastguard Worker  * or return U_SENTINEL if there is none (index is at the limit).
504*0e209d39SAndroid Build Coastguard Worker  *
505*0e209d39SAndroid Build Coastguard Worker  * @param iter the UCharIterator structure ("this pointer")
506*0e209d39SAndroid Build Coastguard Worker  * @return the current code point (and post-increment the current index)
507*0e209d39SAndroid Build Coastguard Worker  *
508*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
509*0e209d39SAndroid Build Coastguard Worker  * @see U16_NEXT
510*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.1
511*0e209d39SAndroid Build Coastguard Worker  */
512*0e209d39SAndroid Build Coastguard Worker U_CAPI UChar32 U_EXPORT2
513*0e209d39SAndroid Build Coastguard Worker uiter_next32(UCharIterator *iter);
514*0e209d39SAndroid Build Coastguard Worker 
515*0e209d39SAndroid Build Coastguard Worker /**
516*0e209d39SAndroid Build Coastguard Worker  * Helper function for UCharIterator to get the previous code point.
517*0e209d39SAndroid Build Coastguard Worker  *
518*0e209d39SAndroid Build Coastguard Worker  * Decrement the index and return the code point from there
519*0e209d39SAndroid Build Coastguard Worker  * (pre-decrement, like s[--i]),
520*0e209d39SAndroid Build Coastguard Worker  * or return U_SENTINEL if there is none (index is at the start).
521*0e209d39SAndroid Build Coastguard Worker  *
522*0e209d39SAndroid Build Coastguard Worker  * @param iter the UCharIterator structure ("this pointer")
523*0e209d39SAndroid Build Coastguard Worker  * @return the previous code point (after pre-decrementing the current index)
524*0e209d39SAndroid Build Coastguard Worker  *
525*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
526*0e209d39SAndroid Build Coastguard Worker  * @see U16_PREV
527*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.1
528*0e209d39SAndroid Build Coastguard Worker  */
529*0e209d39SAndroid Build Coastguard Worker U_CAPI UChar32 U_EXPORT2
530*0e209d39SAndroid Build Coastguard Worker uiter_previous32(UCharIterator *iter);
531*0e209d39SAndroid Build Coastguard Worker 
532*0e209d39SAndroid Build Coastguard Worker /**
533*0e209d39SAndroid Build Coastguard Worker  * Get the "state" of the iterator in the form of a single 32-bit word.
534*0e209d39SAndroid Build Coastguard Worker  * This is a convenience function that calls iter->getState(iter)
535*0e209d39SAndroid Build Coastguard Worker  * if iter->getState is not NULL;
536*0e209d39SAndroid Build Coastguard Worker  * if it is NULL or any other error occurs, then UITER_NO_STATE is returned.
537*0e209d39SAndroid Build Coastguard Worker  *
538*0e209d39SAndroid Build Coastguard Worker  * Some UCharIterator implementations may not be able to return
539*0e209d39SAndroid Build Coastguard Worker  * a valid state for each position, in which case they return UITER_NO_STATE instead.
540*0e209d39SAndroid Build Coastguard Worker  * This will be clearly documented for each such iterator (none of the public ones here).
541*0e209d39SAndroid Build Coastguard Worker  *
542*0e209d39SAndroid Build Coastguard Worker  * @param iter the UCharIterator structure ("this pointer")
543*0e209d39SAndroid Build Coastguard Worker  * @return the state word
544*0e209d39SAndroid Build Coastguard Worker  *
545*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
546*0e209d39SAndroid Build Coastguard Worker  * @see UCharIteratorGetState
547*0e209d39SAndroid Build Coastguard Worker  * @see UITER_NO_STATE
548*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.6
549*0e209d39SAndroid Build Coastguard Worker  */
550*0e209d39SAndroid Build Coastguard Worker U_CAPI uint32_t U_EXPORT2
551*0e209d39SAndroid Build Coastguard Worker uiter_getState(const UCharIterator *iter);
552*0e209d39SAndroid Build Coastguard Worker 
553*0e209d39SAndroid Build Coastguard Worker /**
554*0e209d39SAndroid Build Coastguard Worker  * Restore the "state" of the iterator using a state word from a getState() call.
555*0e209d39SAndroid Build Coastguard Worker  * This is a convenience function that calls iter->setState(iter, state, pErrorCode)
556*0e209d39SAndroid Build Coastguard Worker  * if iter->setState is not NULL; if it is NULL, then U_UNSUPPORTED_ERROR is set.
557*0e209d39SAndroid Build Coastguard Worker  *
558*0e209d39SAndroid Build Coastguard Worker  * @param iter the UCharIterator structure ("this pointer")
559*0e209d39SAndroid Build Coastguard Worker  * @param state the state word from a getState() call
560*0e209d39SAndroid Build Coastguard Worker  *              on a same-type, same-string iterator
561*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode Must be a valid pointer to an error code value,
562*0e209d39SAndroid Build Coastguard Worker  *                   which must not indicate a failure before the function call.
563*0e209d39SAndroid Build Coastguard Worker  *
564*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
565*0e209d39SAndroid Build Coastguard Worker  * @see UCharIteratorSetState
566*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.6
567*0e209d39SAndroid Build Coastguard Worker  */
568*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
569*0e209d39SAndroid Build Coastguard Worker uiter_setState(UCharIterator *iter, uint32_t state, UErrorCode *pErrorCode);
570*0e209d39SAndroid Build Coastguard Worker 
571*0e209d39SAndroid Build Coastguard Worker /**
572*0e209d39SAndroid Build Coastguard Worker  * Set up a UCharIterator to iterate over a string.
573*0e209d39SAndroid Build Coastguard Worker  *
574*0e209d39SAndroid Build Coastguard Worker  * Sets the UCharIterator function pointers for iteration over the string s
575*0e209d39SAndroid Build Coastguard Worker  * with iteration boundaries start=index=0 and length=limit=string length.
576*0e209d39SAndroid Build Coastguard Worker  * The "provider" may set the start, index, and limit values at any time
577*0e209d39SAndroid Build Coastguard Worker  * within the range 0..length.
578*0e209d39SAndroid Build Coastguard Worker  * The length field will be ignored.
579*0e209d39SAndroid Build Coastguard Worker  *
580*0e209d39SAndroid Build Coastguard Worker  * The string pointer s is set into UCharIterator.context without copying
581*0e209d39SAndroid Build Coastguard Worker  * or reallocating the string contents.
582*0e209d39SAndroid Build Coastguard Worker  *
583*0e209d39SAndroid Build Coastguard Worker  * getState() simply returns the current index.
584*0e209d39SAndroid Build Coastguard Worker  * move() will always return the final index.
585*0e209d39SAndroid Build Coastguard Worker  *
586*0e209d39SAndroid Build Coastguard Worker  * @param iter UCharIterator structure to be set for iteration
587*0e209d39SAndroid Build Coastguard Worker  * @param s String to iterate over
588*0e209d39SAndroid Build Coastguard Worker  * @param length Length of s, or -1 if NUL-terminated
589*0e209d39SAndroid Build Coastguard Worker  *
590*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
591*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.1
592*0e209d39SAndroid Build Coastguard Worker  */
593*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
594*0e209d39SAndroid Build Coastguard Worker uiter_setString(UCharIterator *iter, const UChar *s, int32_t length);
595*0e209d39SAndroid Build Coastguard Worker 
596*0e209d39SAndroid Build Coastguard Worker /**
597*0e209d39SAndroid Build Coastguard Worker  * Set up a UCharIterator to iterate over a UTF-16BE string
598*0e209d39SAndroid Build Coastguard Worker  * (byte vector with a big-endian pair of bytes per UChar).
599*0e209d39SAndroid Build Coastguard Worker  *
600*0e209d39SAndroid Build Coastguard Worker  * Everything works just like with a normal UChar iterator (uiter_setString),
601*0e209d39SAndroid Build Coastguard Worker  * except that UChars are assembled from byte pairs,
602*0e209d39SAndroid Build Coastguard Worker  * and that the length argument here indicates an even number of bytes.
603*0e209d39SAndroid Build Coastguard Worker  *
604*0e209d39SAndroid Build Coastguard Worker  * getState() simply returns the current index.
605*0e209d39SAndroid Build Coastguard Worker  * move() will always return the final index.
606*0e209d39SAndroid Build Coastguard Worker  *
607*0e209d39SAndroid Build Coastguard Worker  * @param iter UCharIterator structure to be set for iteration
608*0e209d39SAndroid Build Coastguard Worker  * @param s UTF-16BE string to iterate over
609*0e209d39SAndroid Build Coastguard Worker  * @param length Length of s as an even number of bytes, or -1 if NUL-terminated
610*0e209d39SAndroid Build Coastguard Worker  *               (NUL means pair of 0 bytes at even index from s)
611*0e209d39SAndroid Build Coastguard Worker  *
612*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
613*0e209d39SAndroid Build Coastguard Worker  * @see uiter_setString
614*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.6
615*0e209d39SAndroid Build Coastguard Worker  */
616*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
617*0e209d39SAndroid Build Coastguard Worker uiter_setUTF16BE(UCharIterator *iter, const char *s, int32_t length);
618*0e209d39SAndroid Build Coastguard Worker 
619*0e209d39SAndroid Build Coastguard Worker /**
620*0e209d39SAndroid Build Coastguard Worker  * Set up a UCharIterator to iterate over a UTF-8 string.
621*0e209d39SAndroid Build Coastguard Worker  *
622*0e209d39SAndroid Build Coastguard Worker  * Sets the UCharIterator function pointers for iteration over the UTF-8 string s
623*0e209d39SAndroid Build Coastguard Worker  * with UTF-8 iteration boundaries 0 and length.
624*0e209d39SAndroid Build Coastguard Worker  * The implementation counts the UTF-16 index on the fly and
625*0e209d39SAndroid Build Coastguard Worker  * lazily evaluates the UTF-16 length of the text.
626*0e209d39SAndroid Build Coastguard Worker  *
627*0e209d39SAndroid Build Coastguard Worker  * The start field is used as the UTF-8 offset, the limit field as the UTF-8 length.
628*0e209d39SAndroid Build Coastguard Worker  * When the reservedField is not 0, then it contains a supplementary code point
629*0e209d39SAndroid Build Coastguard Worker  * and the UTF-16 index is between the two corresponding surrogates.
630*0e209d39SAndroid Build Coastguard Worker  * At that point, the UTF-8 index is behind that code point.
631*0e209d39SAndroid Build Coastguard Worker  *
632*0e209d39SAndroid Build Coastguard Worker  * The UTF-8 string pointer s is set into UCharIterator.context without copying
633*0e209d39SAndroid Build Coastguard Worker  * or reallocating the string contents.
634*0e209d39SAndroid Build Coastguard Worker  *
635*0e209d39SAndroid Build Coastguard Worker  * getState() returns a state value consisting of
636*0e209d39SAndroid Build Coastguard Worker  * - the current UTF-8 source byte index (bits 31..1)
637*0e209d39SAndroid Build Coastguard Worker  * - a flag (bit 0) that indicates whether the UChar position is in the middle
638*0e209d39SAndroid Build Coastguard Worker  *   of a surrogate pair
639*0e209d39SAndroid Build Coastguard Worker  *   (from a 4-byte UTF-8 sequence for the corresponding supplementary code point)
640*0e209d39SAndroid Build Coastguard Worker  *
641*0e209d39SAndroid Build Coastguard Worker  * getState() cannot also encode the UTF-16 index in the state value.
642*0e209d39SAndroid Build Coastguard Worker  * move(relative to limit or length), or
643*0e209d39SAndroid Build Coastguard Worker  * move(relative to current) after setState(), may return UITER_UNKNOWN_INDEX.
644*0e209d39SAndroid Build Coastguard Worker  *
645*0e209d39SAndroid Build Coastguard Worker  * @param iter UCharIterator structure to be set for iteration
646*0e209d39SAndroid Build Coastguard Worker  * @param s UTF-8 string to iterate over
647*0e209d39SAndroid Build Coastguard Worker  * @param length Length of s in bytes, or -1 if NUL-terminated
648*0e209d39SAndroid Build Coastguard Worker  *
649*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
650*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.6
651*0e209d39SAndroid Build Coastguard Worker  */
652*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
653*0e209d39SAndroid Build Coastguard Worker uiter_setUTF8(UCharIterator *iter, const char *s, int32_t length);
654*0e209d39SAndroid Build Coastguard Worker 
655*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API
656*0e209d39SAndroid Build Coastguard Worker 
657*0e209d39SAndroid Build Coastguard Worker /**
658*0e209d39SAndroid Build Coastguard Worker  * Set up a UCharIterator to wrap around a C++ CharacterIterator.
659*0e209d39SAndroid Build Coastguard Worker  *
660*0e209d39SAndroid Build Coastguard Worker  * Sets the UCharIterator function pointers for iteration using the
661*0e209d39SAndroid Build Coastguard Worker  * CharacterIterator charIter.
662*0e209d39SAndroid Build Coastguard Worker  *
663*0e209d39SAndroid Build Coastguard Worker  * The CharacterIterator pointer charIter is set into UCharIterator.context
664*0e209d39SAndroid Build Coastguard Worker  * without copying or cloning the CharacterIterator object.
665*0e209d39SAndroid Build Coastguard Worker  * The other "protected" UCharIterator fields are set to 0 and will be ignored.
666*0e209d39SAndroid Build Coastguard Worker  * The iteration index and boundaries are controlled by the CharacterIterator.
667*0e209d39SAndroid Build Coastguard Worker  *
668*0e209d39SAndroid Build Coastguard Worker  * getState() simply returns the current index.
669*0e209d39SAndroid Build Coastguard Worker  * move() will always return the final index.
670*0e209d39SAndroid Build Coastguard Worker  *
671*0e209d39SAndroid Build Coastguard Worker  * @param iter UCharIterator structure to be set for iteration
672*0e209d39SAndroid Build Coastguard Worker  * @param charIter CharacterIterator to wrap
673*0e209d39SAndroid Build Coastguard Worker  *
674*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
675*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.1
676*0e209d39SAndroid Build Coastguard Worker  */
677*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
678*0e209d39SAndroid Build Coastguard Worker uiter_setCharacterIterator(UCharIterator *iter, icu::CharacterIterator *charIter);
679*0e209d39SAndroid Build Coastguard Worker 
680*0e209d39SAndroid Build Coastguard Worker /**
681*0e209d39SAndroid Build Coastguard Worker  * Set up a UCharIterator to iterate over a C++ Replaceable.
682*0e209d39SAndroid Build Coastguard Worker  *
683*0e209d39SAndroid Build Coastguard Worker  * Sets the UCharIterator function pointers for iteration over the
684*0e209d39SAndroid Build Coastguard Worker  * Replaceable rep with iteration boundaries start=index=0 and
685*0e209d39SAndroid Build Coastguard Worker  * length=limit=rep->length().
686*0e209d39SAndroid Build Coastguard Worker  * The "provider" may set the start, index, and limit values at any time
687*0e209d39SAndroid Build Coastguard Worker  * within the range 0..length=rep->length().
688*0e209d39SAndroid Build Coastguard Worker  * The length field will be ignored.
689*0e209d39SAndroid Build Coastguard Worker  *
690*0e209d39SAndroid Build Coastguard Worker  * The Replaceable pointer rep is set into UCharIterator.context without copying
691*0e209d39SAndroid Build Coastguard Worker  * or cloning/reallocating the Replaceable object.
692*0e209d39SAndroid Build Coastguard Worker  *
693*0e209d39SAndroid Build Coastguard Worker  * getState() simply returns the current index.
694*0e209d39SAndroid Build Coastguard Worker  * move() will always return the final index.
695*0e209d39SAndroid Build Coastguard Worker  *
696*0e209d39SAndroid Build Coastguard Worker  * @param iter UCharIterator structure to be set for iteration
697*0e209d39SAndroid Build Coastguard Worker  * @param rep Replaceable to iterate over
698*0e209d39SAndroid Build Coastguard Worker  *
699*0e209d39SAndroid Build Coastguard Worker  * @see UCharIterator
700*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.1
701*0e209d39SAndroid Build Coastguard Worker  */
702*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
703*0e209d39SAndroid Build Coastguard Worker uiter_setReplaceable(UCharIterator *iter, const icu::Replaceable *rep);
704*0e209d39SAndroid Build Coastguard Worker 
705*0e209d39SAndroid Build Coastguard Worker #endif
706*0e209d39SAndroid Build Coastguard Worker 
707*0e209d39SAndroid Build Coastguard Worker U_CDECL_END
708*0e209d39SAndroid Build Coastguard Worker 
709*0e209d39SAndroid Build Coastguard Worker #endif
710