sl@0
|
1 |
/*
|
sl@0
|
2 |
**********************************************************************
|
sl@0
|
3 |
* Copyright (C) 1998-2005, International Business Machines
|
sl@0
|
4 |
* Corporation and others. All Rights Reserved.
|
sl@0
|
5 |
**********************************************************************
|
sl@0
|
6 |
*/
|
sl@0
|
7 |
|
sl@0
|
8 |
#ifndef UCHRITER_H
|
sl@0
|
9 |
#define UCHRITER_H
|
sl@0
|
10 |
|
sl@0
|
11 |
#include "unicode/utypes.h"
|
sl@0
|
12 |
#include "unicode/chariter.h"
|
sl@0
|
13 |
|
sl@0
|
14 |
/**
|
sl@0
|
15 |
* \file
|
sl@0
|
16 |
* \brief C++ API: UChar Character Iterator
|
sl@0
|
17 |
*/
|
sl@0
|
18 |
|
sl@0
|
19 |
U_NAMESPACE_BEGIN
|
sl@0
|
20 |
|
sl@0
|
21 |
/**
|
sl@0
|
22 |
* A concrete subclass of CharacterIterator that iterates over the
|
sl@0
|
23 |
* characters (code units or code points) in a UChar array.
|
sl@0
|
24 |
* It's possible not only to create an
|
sl@0
|
25 |
* iterator that iterates over an entire UChar array, but also to
|
sl@0
|
26 |
* create one that iterates over only a subrange of a UChar array
|
sl@0
|
27 |
* (iterators over different subranges of the same UChar array don't
|
sl@0
|
28 |
* compare equal).
|
sl@0
|
29 |
* @see CharacterIterator
|
sl@0
|
30 |
* @see ForwardCharacterIterator
|
sl@0
|
31 |
* @stable ICU 2.0
|
sl@0
|
32 |
*/
|
sl@0
|
33 |
class U_COMMON_API UCharCharacterIterator : public CharacterIterator {
|
sl@0
|
34 |
public:
|
sl@0
|
35 |
/**
|
sl@0
|
36 |
* Create an iterator over the UChar array referred to by "textPtr".
|
sl@0
|
37 |
* The iteration range is 0 to <code>length-1</code>.
|
sl@0
|
38 |
* text is only aliased, not adopted (the
|
sl@0
|
39 |
* destructor will not delete it).
|
sl@0
|
40 |
* @param textPtr The UChar array to be iterated over
|
sl@0
|
41 |
* @param length The length of the UChar array
|
sl@0
|
42 |
* @stable ICU 2.0
|
sl@0
|
43 |
*/
|
sl@0
|
44 |
UCharCharacterIterator(const UChar* textPtr, int32_t length);
|
sl@0
|
45 |
|
sl@0
|
46 |
/**
|
sl@0
|
47 |
* Create an iterator over the UChar array referred to by "textPtr".
|
sl@0
|
48 |
* The iteration range is 0 to <code>length-1</code>.
|
sl@0
|
49 |
* text is only aliased, not adopted (the
|
sl@0
|
50 |
* destructor will not delete it).
|
sl@0
|
51 |
* The starting
|
sl@0
|
52 |
* position is specified by "position". If "position" is outside the valid
|
sl@0
|
53 |
* iteration range, the behavior of this object is undefined.
|
sl@0
|
54 |
* @param textPtr The UChar array to be iteratd over
|
sl@0
|
55 |
* @param length The length of the UChar array
|
sl@0
|
56 |
* @param position The starting position of the iteration
|
sl@0
|
57 |
* @stable ICU 2.0
|
sl@0
|
58 |
*/
|
sl@0
|
59 |
UCharCharacterIterator(const UChar* textPtr, int32_t length,
|
sl@0
|
60 |
int32_t position);
|
sl@0
|
61 |
|
sl@0
|
62 |
/**
|
sl@0
|
63 |
* Create an iterator over the UChar array referred to by "textPtr".
|
sl@0
|
64 |
* The iteration range is 0 to <code>end-1</code>.
|
sl@0
|
65 |
* text is only aliased, not adopted (the
|
sl@0
|
66 |
* destructor will not delete it).
|
sl@0
|
67 |
* The starting
|
sl@0
|
68 |
* position is specified by "position". If begin and end do not
|
sl@0
|
69 |
* form a valid iteration range or "position" is outside the valid
|
sl@0
|
70 |
* iteration range, the behavior of this object is undefined.
|
sl@0
|
71 |
* @param textPtr The UChar array to be iterated over
|
sl@0
|
72 |
* @param length The length of the UChar array
|
sl@0
|
73 |
* @param textBegin The begin position of the iteration range
|
sl@0
|
74 |
* @param textEnd The end position of the iteration range
|
sl@0
|
75 |
* @param position The starting position of the iteration
|
sl@0
|
76 |
* @stable ICU 2.0
|
sl@0
|
77 |
*/
|
sl@0
|
78 |
UCharCharacterIterator(const UChar* textPtr, int32_t length,
|
sl@0
|
79 |
int32_t textBegin,
|
sl@0
|
80 |
int32_t textEnd,
|
sl@0
|
81 |
int32_t position);
|
sl@0
|
82 |
|
sl@0
|
83 |
/**
|
sl@0
|
84 |
* Copy constructor. The new iterator iterates over the same range
|
sl@0
|
85 |
* of the same string as "that", and its initial position is the
|
sl@0
|
86 |
* same as "that"'s current position.
|
sl@0
|
87 |
* @param that The UCharCharacterIterator to be copied
|
sl@0
|
88 |
* @stable ICU 2.0
|
sl@0
|
89 |
*/
|
sl@0
|
90 |
UCharCharacterIterator(const UCharCharacterIterator& that);
|
sl@0
|
91 |
|
sl@0
|
92 |
/**
|
sl@0
|
93 |
* Destructor.
|
sl@0
|
94 |
* @stable ICU 2.0
|
sl@0
|
95 |
*/
|
sl@0
|
96 |
virtual ~UCharCharacterIterator();
|
sl@0
|
97 |
|
sl@0
|
98 |
/**
|
sl@0
|
99 |
* Assignment operator. *this is altered to iterate over the sane
|
sl@0
|
100 |
* range of the same string as "that", and refers to the same
|
sl@0
|
101 |
* character within that string as "that" does.
|
sl@0
|
102 |
* @param that The object to be copied
|
sl@0
|
103 |
* @return the newly created object
|
sl@0
|
104 |
* @stable ICU 2.0
|
sl@0
|
105 |
*/
|
sl@0
|
106 |
UCharCharacterIterator&
|
sl@0
|
107 |
operator=(const UCharCharacterIterator& that);
|
sl@0
|
108 |
|
sl@0
|
109 |
/**
|
sl@0
|
110 |
* Returns true if the iterators iterate over the same range of the
|
sl@0
|
111 |
* same string and are pointing at the same character.
|
sl@0
|
112 |
* @param that The ForwardCharacterIterator used to be compared for equality
|
sl@0
|
113 |
* @return true if the iterators iterate over the same range of the
|
sl@0
|
114 |
* same string and are pointing at the same character.
|
sl@0
|
115 |
* @stable ICU 2.0
|
sl@0
|
116 |
*/
|
sl@0
|
117 |
virtual UBool operator==(const ForwardCharacterIterator& that) const;
|
sl@0
|
118 |
|
sl@0
|
119 |
/**
|
sl@0
|
120 |
* Generates a hash code for this iterator.
|
sl@0
|
121 |
* @return the hash code.
|
sl@0
|
122 |
* @stable ICU 2.0
|
sl@0
|
123 |
*/
|
sl@0
|
124 |
virtual int32_t hashCode(void) const;
|
sl@0
|
125 |
|
sl@0
|
126 |
/**
|
sl@0
|
127 |
* Returns a new UCharCharacterIterator referring to the same
|
sl@0
|
128 |
* character in the same range of the same string as this one. The
|
sl@0
|
129 |
* caller must delete the new iterator.
|
sl@0
|
130 |
* @return the CharacterIterator newly created
|
sl@0
|
131 |
* @stable ICU 2.0
|
sl@0
|
132 |
*/
|
sl@0
|
133 |
virtual CharacterIterator* clone(void) const;
|
sl@0
|
134 |
|
sl@0
|
135 |
/**
|
sl@0
|
136 |
* Sets the iterator to refer to the first code unit in its
|
sl@0
|
137 |
* iteration range, and returns that code unit.
|
sl@0
|
138 |
* This can be used to begin an iteration with next().
|
sl@0
|
139 |
* @return the first code unit in its iteration range.
|
sl@0
|
140 |
* @stable ICU 2.0
|
sl@0
|
141 |
*/
|
sl@0
|
142 |
virtual UChar first(void);
|
sl@0
|
143 |
|
sl@0
|
144 |
/**
|
sl@0
|
145 |
* Sets the iterator to refer to the first code unit in its
|
sl@0
|
146 |
* iteration range, returns that code unit, and moves the position
|
sl@0
|
147 |
* to the second code unit. This is an alternative to setToStart()
|
sl@0
|
148 |
* for forward iteration with nextPostInc().
|
sl@0
|
149 |
* @return the first code unit in its iteration range
|
sl@0
|
150 |
* @stable ICU 2.0
|
sl@0
|
151 |
*/
|
sl@0
|
152 |
virtual UChar firstPostInc(void);
|
sl@0
|
153 |
|
sl@0
|
154 |
/**
|
sl@0
|
155 |
* Sets the iterator to refer to the first code point in its
|
sl@0
|
156 |
* iteration range, and returns that code unit,
|
sl@0
|
157 |
* This can be used to begin an iteration with next32().
|
sl@0
|
158 |
* Note that an iteration with next32PostInc(), beginning with,
|
sl@0
|
159 |
* e.g., setToStart() or firstPostInc(), is more efficient.
|
sl@0
|
160 |
* @return the first code point in its iteration range
|
sl@0
|
161 |
* @stable ICU 2.0
|
sl@0
|
162 |
*/
|
sl@0
|
163 |
virtual UChar32 first32(void);
|
sl@0
|
164 |
|
sl@0
|
165 |
/**
|
sl@0
|
166 |
* Sets the iterator to refer to the first code point in its
|
sl@0
|
167 |
* iteration range, returns that code point, and moves the position
|
sl@0
|
168 |
* to the second code point. This is an alternative to setToStart()
|
sl@0
|
169 |
* for forward iteration with next32PostInc().
|
sl@0
|
170 |
* @return the first code point in its iteration range.
|
sl@0
|
171 |
* @stable ICU 2.0
|
sl@0
|
172 |
*/
|
sl@0
|
173 |
virtual UChar32 first32PostInc(void);
|
sl@0
|
174 |
|
sl@0
|
175 |
/**
|
sl@0
|
176 |
* Sets the iterator to refer to the last code unit in its
|
sl@0
|
177 |
* iteration range, and returns that code unit.
|
sl@0
|
178 |
* This can be used to begin an iteration with previous().
|
sl@0
|
179 |
* @return the last code unit in its iteration range.
|
sl@0
|
180 |
* @stable ICU 2.0
|
sl@0
|
181 |
*/
|
sl@0
|
182 |
virtual UChar last(void);
|
sl@0
|
183 |
|
sl@0
|
184 |
/**
|
sl@0
|
185 |
* Sets the iterator to refer to the last code point in its
|
sl@0
|
186 |
* iteration range, and returns that code unit.
|
sl@0
|
187 |
* This can be used to begin an iteration with previous32().
|
sl@0
|
188 |
* @return the last code point in its iteration range.
|
sl@0
|
189 |
* @stable ICU 2.0
|
sl@0
|
190 |
*/
|
sl@0
|
191 |
virtual UChar32 last32(void);
|
sl@0
|
192 |
|
sl@0
|
193 |
/**
|
sl@0
|
194 |
* Sets the iterator to refer to the "position"-th code unit
|
sl@0
|
195 |
* in the text-storage object the iterator refers to, and
|
sl@0
|
196 |
* returns that code unit.
|
sl@0
|
197 |
* @param position the position within the text-storage object
|
sl@0
|
198 |
* @return the code unit
|
sl@0
|
199 |
* @stable ICU 2.0
|
sl@0
|
200 |
*/
|
sl@0
|
201 |
virtual UChar setIndex(int32_t position);
|
sl@0
|
202 |
|
sl@0
|
203 |
/**
|
sl@0
|
204 |
* Sets the iterator to refer to the beginning of the code point
|
sl@0
|
205 |
* that contains the "position"-th code unit
|
sl@0
|
206 |
* in the text-storage object the iterator refers to, and
|
sl@0
|
207 |
* returns that code point.
|
sl@0
|
208 |
* The current position is adjusted to the beginning of the code point
|
sl@0
|
209 |
* (its first code unit).
|
sl@0
|
210 |
* @param position the position within the text-storage object
|
sl@0
|
211 |
* @return the code unit
|
sl@0
|
212 |
* @stable ICU 2.0
|
sl@0
|
213 |
*/
|
sl@0
|
214 |
virtual UChar32 setIndex32(int32_t position);
|
sl@0
|
215 |
|
sl@0
|
216 |
/**
|
sl@0
|
217 |
* Returns the code unit the iterator currently refers to.
|
sl@0
|
218 |
* @return the code unit the iterator currently refers to.
|
sl@0
|
219 |
* @stable ICU 2.0
|
sl@0
|
220 |
*/
|
sl@0
|
221 |
virtual UChar current(void) const;
|
sl@0
|
222 |
|
sl@0
|
223 |
/**
|
sl@0
|
224 |
* Returns the code point the iterator currently refers to.
|
sl@0
|
225 |
* @return the code point the iterator currently refers to.
|
sl@0
|
226 |
* @stable ICU 2.0
|
sl@0
|
227 |
*/
|
sl@0
|
228 |
virtual UChar32 current32(void) const;
|
sl@0
|
229 |
|
sl@0
|
230 |
/**
|
sl@0
|
231 |
* Advances to the next code unit in the iteration range (toward
|
sl@0
|
232 |
* endIndex()), and returns that code unit. If there are no more
|
sl@0
|
233 |
* code units to return, returns DONE.
|
sl@0
|
234 |
* @return the next code unit in the iteration range.
|
sl@0
|
235 |
* @stable ICU 2.0
|
sl@0
|
236 |
*/
|
sl@0
|
237 |
virtual UChar next(void);
|
sl@0
|
238 |
|
sl@0
|
239 |
/**
|
sl@0
|
240 |
* Gets the current code unit for returning and advances to the next code unit
|
sl@0
|
241 |
* in the iteration range
|
sl@0
|
242 |
* (toward endIndex()). If there are
|
sl@0
|
243 |
* no more code units to return, returns DONE.
|
sl@0
|
244 |
* @return the current code unit.
|
sl@0
|
245 |
* @stable ICU 2.0
|
sl@0
|
246 |
*/
|
sl@0
|
247 |
virtual UChar nextPostInc(void);
|
sl@0
|
248 |
|
sl@0
|
249 |
/**
|
sl@0
|
250 |
* Advances to the next code point in the iteration range (toward
|
sl@0
|
251 |
* endIndex()), and returns that code point. If there are no more
|
sl@0
|
252 |
* code points to return, returns DONE.
|
sl@0
|
253 |
* Note that iteration with "pre-increment" semantics is less
|
sl@0
|
254 |
* efficient than iteration with "post-increment" semantics
|
sl@0
|
255 |
* that is provided by next32PostInc().
|
sl@0
|
256 |
* @return the next code point in the iteration range.
|
sl@0
|
257 |
* @stable ICU 2.0
|
sl@0
|
258 |
*/
|
sl@0
|
259 |
virtual UChar32 next32(void);
|
sl@0
|
260 |
|
sl@0
|
261 |
/**
|
sl@0
|
262 |
* Gets the current code point for returning and advances to the next code point
|
sl@0
|
263 |
* in the iteration range
|
sl@0
|
264 |
* (toward endIndex()). If there are
|
sl@0
|
265 |
* no more code points to return, returns DONE.
|
sl@0
|
266 |
* @return the current point.
|
sl@0
|
267 |
* @stable ICU 2.0
|
sl@0
|
268 |
*/
|
sl@0
|
269 |
virtual UChar32 next32PostInc(void);
|
sl@0
|
270 |
|
sl@0
|
271 |
/**
|
sl@0
|
272 |
* Returns FALSE if there are no more code units or code points
|
sl@0
|
273 |
* at or after the current position in the iteration range.
|
sl@0
|
274 |
* This is used with nextPostInc() or next32PostInc() in forward
|
sl@0
|
275 |
* iteration.
|
sl@0
|
276 |
* @return FALSE if there are no more code units or code points
|
sl@0
|
277 |
* at or after the current position in the iteration range.
|
sl@0
|
278 |
* @stable ICU 2.0
|
sl@0
|
279 |
*/
|
sl@0
|
280 |
virtual UBool hasNext();
|
sl@0
|
281 |
|
sl@0
|
282 |
/**
|
sl@0
|
283 |
* Advances to the previous code unit in the iteration range (toward
|
sl@0
|
284 |
* startIndex()), and returns that code unit. If there are no more
|
sl@0
|
285 |
* code units to return, returns DONE.
|
sl@0
|
286 |
* @return the previous code unit in the iteration range.
|
sl@0
|
287 |
* @stable ICU 2.0
|
sl@0
|
288 |
*/
|
sl@0
|
289 |
virtual UChar previous(void);
|
sl@0
|
290 |
|
sl@0
|
291 |
/**
|
sl@0
|
292 |
* Advances to the previous code point in the iteration range (toward
|
sl@0
|
293 |
* startIndex()), and returns that code point. If there are no more
|
sl@0
|
294 |
* code points to return, returns DONE.
|
sl@0
|
295 |
* @return the previous code point in the iteration range.
|
sl@0
|
296 |
* @stable ICU 2.0
|
sl@0
|
297 |
*/
|
sl@0
|
298 |
virtual UChar32 previous32(void);
|
sl@0
|
299 |
|
sl@0
|
300 |
/**
|
sl@0
|
301 |
* Returns FALSE if there are no more code units or code points
|
sl@0
|
302 |
* before the current position in the iteration range.
|
sl@0
|
303 |
* This is used with previous() or previous32() in backward
|
sl@0
|
304 |
* iteration.
|
sl@0
|
305 |
* @return FALSE if there are no more code units or code points
|
sl@0
|
306 |
* before the current position in the iteration range.
|
sl@0
|
307 |
* @stable ICU 2.0
|
sl@0
|
308 |
*/
|
sl@0
|
309 |
virtual UBool hasPrevious();
|
sl@0
|
310 |
|
sl@0
|
311 |
/**
|
sl@0
|
312 |
* Moves the current position relative to the start or end of the
|
sl@0
|
313 |
* iteration range, or relative to the current position itself.
|
sl@0
|
314 |
* The movement is expressed in numbers of code units forward
|
sl@0
|
315 |
* or backward by specifying a positive or negative delta.
|
sl@0
|
316 |
* @param delta the position relative to origin. A positive delta means forward;
|
sl@0
|
317 |
* a negative delta means backward.
|
sl@0
|
318 |
* @param origin Origin enumeration {kStart, kCurrent, kEnd}
|
sl@0
|
319 |
* @return the new position
|
sl@0
|
320 |
* @stable ICU 2.0
|
sl@0
|
321 |
*/
|
sl@0
|
322 |
virtual int32_t move(int32_t delta, EOrigin origin);
|
sl@0
|
323 |
|
sl@0
|
324 |
/**
|
sl@0
|
325 |
* Moves the current position relative to the start or end of the
|
sl@0
|
326 |
* iteration range, or relative to the current position itself.
|
sl@0
|
327 |
* The movement is expressed in numbers of code points forward
|
sl@0
|
328 |
* or backward by specifying a positive or negative delta.
|
sl@0
|
329 |
* @param delta the position relative to origin. A positive delta means forward;
|
sl@0
|
330 |
* a negative delta means backward.
|
sl@0
|
331 |
* @param origin Origin enumeration {kStart, kCurrent, kEnd}
|
sl@0
|
332 |
* @return the new position
|
sl@0
|
333 |
* @stable ICU 2.0
|
sl@0
|
334 |
*/
|
sl@0
|
335 |
virtual int32_t move32(int32_t delta, EOrigin origin);
|
sl@0
|
336 |
|
sl@0
|
337 |
/**
|
sl@0
|
338 |
* Sets the iterator to iterate over a new range of text
|
sl@0
|
339 |
* @stable ICU 2.0
|
sl@0
|
340 |
*/
|
sl@0
|
341 |
void setText(const UChar* newText, int32_t newTextLength);
|
sl@0
|
342 |
|
sl@0
|
343 |
/**
|
sl@0
|
344 |
* Copies the UChar array under iteration into the UnicodeString
|
sl@0
|
345 |
* referred to by "result". Even if this iterator iterates across
|
sl@0
|
346 |
* only a part of this string, the whole string is copied.
|
sl@0
|
347 |
* @param result Receives a copy of the text under iteration.
|
sl@0
|
348 |
* @stable ICU 2.0
|
sl@0
|
349 |
*/
|
sl@0
|
350 |
virtual void getText(UnicodeString& result);
|
sl@0
|
351 |
|
sl@0
|
352 |
/**
|
sl@0
|
353 |
* Return a class ID for this class (not really public)
|
sl@0
|
354 |
* @return a class ID for this class
|
sl@0
|
355 |
* @stable ICU 2.0
|
sl@0
|
356 |
*/
|
sl@0
|
357 |
static UClassID U_EXPORT2 getStaticClassID(void);
|
sl@0
|
358 |
|
sl@0
|
359 |
/**
|
sl@0
|
360 |
* Return a class ID for this object (not really public)
|
sl@0
|
361 |
* @return a class ID for this object.
|
sl@0
|
362 |
* @stable ICU 2.0
|
sl@0
|
363 |
*/
|
sl@0
|
364 |
virtual UClassID getDynamicClassID(void) const;
|
sl@0
|
365 |
|
sl@0
|
366 |
protected:
|
sl@0
|
367 |
/**
|
sl@0
|
368 |
* Protected constructor
|
sl@0
|
369 |
* @stable ICU 2.0
|
sl@0
|
370 |
*/
|
sl@0
|
371 |
UCharCharacterIterator();
|
sl@0
|
372 |
/**
|
sl@0
|
373 |
* Protected member text
|
sl@0
|
374 |
* @stable ICU 2.0
|
sl@0
|
375 |
*/
|
sl@0
|
376 |
const UChar* text;
|
sl@0
|
377 |
|
sl@0
|
378 |
};
|
sl@0
|
379 |
|
sl@0
|
380 |
U_NAMESPACE_END
|
sl@0
|
381 |
#endif
|