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