1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/common/unicode/chariter.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,722 @@ 1.4 +/* 1.5 +******************************************************************** 1.6 +* 1.7 +* Copyright (C) 1997-2011, International Business Machines 1.8 +* Corporation and others. All Rights Reserved. 1.9 +* 1.10 +******************************************************************** 1.11 +*/ 1.12 + 1.13 +#ifndef CHARITER_H 1.14 +#define CHARITER_H 1.15 + 1.16 +#include "unicode/utypes.h" 1.17 +#include "unicode/uobject.h" 1.18 +#include "unicode/unistr.h" 1.19 +/** 1.20 + * \file 1.21 + * \brief C++ API: Character Iterator 1.22 + */ 1.23 + 1.24 +U_NAMESPACE_BEGIN 1.25 +/** 1.26 + * Abstract class that defines an API for forward-only iteration 1.27 + * on text objects. 1.28 + * This is a minimal interface for iteration without random access 1.29 + * or backwards iteration. It is especially useful for wrapping 1.30 + * streams with converters into an object for collation or 1.31 + * normalization. 1.32 + * 1.33 + * <p>Characters can be accessed in two ways: as code units or as 1.34 + * code points. 1.35 + * Unicode code points are 21-bit integers and are the scalar values 1.36 + * of Unicode characters. ICU uses the type UChar32 for them. 1.37 + * Unicode code units are the storage units of a given 1.38 + * Unicode/UCS Transformation Format (a character encoding scheme). 1.39 + * With UTF-16, all code points can be represented with either one 1.40 + * or two code units ("surrogates"). 1.41 + * String storage is typically based on code units, while properties 1.42 + * of characters are typically determined using code point values. 1.43 + * Some processes may be designed to work with sequences of code units, 1.44 + * or it may be known that all characters that are important to an 1.45 + * algorithm can be represented with single code units. 1.46 + * Other processes will need to use the code point access functions.</p> 1.47 + * 1.48 + * <p>ForwardCharacterIterator provides nextPostInc() to access 1.49 + * a code unit and advance an internal position into the text object, 1.50 + * similar to a <code>return text[position++]</code>.<br> 1.51 + * It provides next32PostInc() to access a code point and advance an internal 1.52 + * position.</p> 1.53 + * 1.54 + * <p>next32PostInc() assumes that the current position is that of 1.55 + * the beginning of a code point, i.e., of its first code unit. 1.56 + * After next32PostInc(), this will be true again. 1.57 + * In general, access to code units and code points in the same 1.58 + * iteration loop should not be mixed. In UTF-16, if the current position 1.59 + * is on a second code unit (Low Surrogate), then only that code unit 1.60 + * is returned even by next32PostInc().</p> 1.61 + * 1.62 + * <p>For iteration with either function, there are two ways to 1.63 + * check for the end of the iteration. When there are no more 1.64 + * characters in the text object: 1.65 + * <ul> 1.66 + * <li>The hasNext() function returns FALSE.</li> 1.67 + * <li>nextPostInc() and next32PostInc() return DONE 1.68 + * when one attempts to read beyond the end of the text object.</li> 1.69 + * </ul> 1.70 + * 1.71 + * Example: 1.72 + * \code 1.73 + * void function1(ForwardCharacterIterator &it) { 1.74 + * UChar32 c; 1.75 + * while(it.hasNext()) { 1.76 + * c=it.next32PostInc(); 1.77 + * // use c 1.78 + * } 1.79 + * } 1.80 + * 1.81 + * void function1(ForwardCharacterIterator &it) { 1.82 + * UChar c; 1.83 + * while((c=it.nextPostInc())!=ForwardCharacterIterator::DONE) { 1.84 + * // use c 1.85 + * } 1.86 + * } 1.87 + * \endcode 1.88 + * </p> 1.89 + * 1.90 + * @stable ICU 2.0 1.91 + */ 1.92 +class U_COMMON_API ForwardCharacterIterator : public UObject { 1.93 +public: 1.94 + /** 1.95 + * Value returned by most of ForwardCharacterIterator's functions 1.96 + * when the iterator has reached the limits of its iteration. 1.97 + * @stable ICU 2.0 1.98 + */ 1.99 + enum { DONE = 0xffff }; 1.100 + 1.101 + /** 1.102 + * Destructor. 1.103 + * @stable ICU 2.0 1.104 + */ 1.105 + virtual ~ForwardCharacterIterator(); 1.106 + 1.107 + /** 1.108 + * Returns true when both iterators refer to the same 1.109 + * character in the same character-storage object. 1.110 + * @param that The ForwardCharacterIterator to be compared for equality 1.111 + * @return true when both iterators refer to the same 1.112 + * character in the same character-storage object 1.113 + * @stable ICU 2.0 1.114 + */ 1.115 + virtual UBool operator==(const ForwardCharacterIterator& that) const = 0; 1.116 + 1.117 + /** 1.118 + * Returns true when the iterators refer to different 1.119 + * text-storage objects, or to different characters in the 1.120 + * same text-storage object. 1.121 + * @param that The ForwardCharacterIterator to be compared for inequality 1.122 + * @return true when the iterators refer to different 1.123 + * text-storage objects, or to different characters in the 1.124 + * same text-storage object 1.125 + * @stable ICU 2.0 1.126 + */ 1.127 + inline UBool operator!=(const ForwardCharacterIterator& that) const; 1.128 + 1.129 + /** 1.130 + * Generates a hash code for this iterator. 1.131 + * @return the hash code. 1.132 + * @stable ICU 2.0 1.133 + */ 1.134 + virtual int32_t hashCode(void) const = 0; 1.135 + 1.136 + /** 1.137 + * Returns a UClassID for this ForwardCharacterIterator ("poor man's 1.138 + * RTTI").<P> Despite the fact that this function is public, 1.139 + * DO NOT CONSIDER IT PART OF CHARACTERITERATOR'S API! 1.140 + * @return a UClassID for this ForwardCharacterIterator 1.141 + * @stable ICU 2.0 1.142 + */ 1.143 + virtual UClassID getDynamicClassID(void) const = 0; 1.144 + 1.145 + /** 1.146 + * Gets the current code unit for returning and advances to the next code unit 1.147 + * in the iteration range 1.148 + * (toward endIndex()). If there are 1.149 + * no more code units to return, returns DONE. 1.150 + * @return the current code unit. 1.151 + * @stable ICU 2.0 1.152 + */ 1.153 + virtual UChar nextPostInc(void) = 0; 1.154 + 1.155 + /** 1.156 + * Gets the current code point for returning and advances to the next code point 1.157 + * in the iteration range 1.158 + * (toward endIndex()). If there are 1.159 + * no more code points to return, returns DONE. 1.160 + * @return the current code point. 1.161 + * @stable ICU 2.0 1.162 + */ 1.163 + virtual UChar32 next32PostInc(void) = 0; 1.164 + 1.165 + /** 1.166 + * Returns FALSE if there are no more code units or code points 1.167 + * at or after the current position in the iteration range. 1.168 + * This is used with nextPostInc() or next32PostInc() in forward 1.169 + * iteration. 1.170 + * @returns FALSE if there are no more code units or code points 1.171 + * at or after the current position in the iteration range. 1.172 + * @stable ICU 2.0 1.173 + */ 1.174 + virtual UBool hasNext() = 0; 1.175 + 1.176 +protected: 1.177 + /** Default constructor to be overridden in the implementing class. @stable ICU 2.0*/ 1.178 + ForwardCharacterIterator(); 1.179 + 1.180 + /** Copy constructor to be overridden in the implementing class. @stable ICU 2.0*/ 1.181 + ForwardCharacterIterator(const ForwardCharacterIterator &other); 1.182 + 1.183 + /** 1.184 + * Assignment operator to be overridden in the implementing class. 1.185 + * @stable ICU 2.0 1.186 + */ 1.187 + ForwardCharacterIterator &operator=(const ForwardCharacterIterator&) { return *this; } 1.188 +}; 1.189 + 1.190 +/** 1.191 + * Abstract class that defines an API for iteration 1.192 + * on text objects. 1.193 + * This is an interface for forward and backward iteration 1.194 + * and random access into a text object. 1.195 + * 1.196 + * <p>The API provides backward compatibility to the Java and older ICU 1.197 + * CharacterIterator classes but extends them significantly: 1.198 + * <ol> 1.199 + * <li>CharacterIterator is now a subclass of ForwardCharacterIterator.</li> 1.200 + * <li>While the old API functions provided forward iteration with 1.201 + * "pre-increment" semantics, the new one also provides functions 1.202 + * with "post-increment" semantics. They are more efficient and should 1.203 + * be the preferred iterator functions for new implementations. 1.204 + * The backward iteration always had "pre-decrement" semantics, which 1.205 + * are efficient.</li> 1.206 + * <li>Just like ForwardCharacterIterator, it provides access to 1.207 + * both code units and code points. Code point access versions are available 1.208 + * for the old and the new iteration semantics.</li> 1.209 + * <li>There are new functions for setting and moving the current position 1.210 + * without returning a character, for efficiency.</li> 1.211 + * </ol> 1.212 + * 1.213 + * See ForwardCharacterIterator for examples for using the new forward iteration 1.214 + * functions. For backward iteration, there is also a hasPrevious() function 1.215 + * that can be used analogously to hasNext(). 1.216 + * The old functions work as before and are shown below.</p> 1.217 + * 1.218 + * <p>Examples for some of the new functions:</p> 1.219 + * 1.220 + * Forward iteration with hasNext(): 1.221 + * \code 1.222 + * void forward1(CharacterIterator &it) { 1.223 + * UChar32 c; 1.224 + * for(it.setToStart(); it.hasNext();) { 1.225 + * c=it.next32PostInc(); 1.226 + * // use c 1.227 + * } 1.228 + * } 1.229 + * \endcode 1.230 + * Forward iteration more similar to loops with the old forward iteration, 1.231 + * showing a way to convert simple for() loops: 1.232 + * \code 1.233 + * void forward2(CharacterIterator &it) { 1.234 + * UChar c; 1.235 + * for(c=it.firstPostInc(); c!=CharacterIterator::DONE; c=it.nextPostInc()) { 1.236 + * // use c 1.237 + * } 1.238 + * } 1.239 + * \endcode 1.240 + * Backward iteration with setToEnd() and hasPrevious(): 1.241 + * \code 1.242 + * void backward1(CharacterIterator &it) { 1.243 + * UChar32 c; 1.244 + * for(it.setToEnd(); it.hasPrevious();) { 1.245 + * c=it.previous32(); 1.246 + * // use c 1.247 + * } 1.248 + * } 1.249 + * \endcode 1.250 + * Backward iteration with a more traditional for() loop: 1.251 + * \code 1.252 + * void backward2(CharacterIterator &it) { 1.253 + * UChar c; 1.254 + * for(c=it.last(); c!=CharacterIterator::DONE; c=it.previous()) { 1.255 + * // use c 1.256 + * } 1.257 + * } 1.258 + * \endcode 1.259 + * 1.260 + * Example for random access: 1.261 + * \code 1.262 + * void random(CharacterIterator &it) { 1.263 + * // set to the third code point from the beginning 1.264 + * it.move32(3, CharacterIterator::kStart); 1.265 + * // get a code point from here without moving the position 1.266 + * UChar32 c=it.current32(); 1.267 + * // get the position 1.268 + * int32_t pos=it.getIndex(); 1.269 + * // get the previous code unit 1.270 + * UChar u=it.previous(); 1.271 + * // move back one more code unit 1.272 + * it.move(-1, CharacterIterator::kCurrent); 1.273 + * // set the position back to where it was 1.274 + * // and read the same code point c and move beyond it 1.275 + * it.setIndex(pos); 1.276 + * if(c!=it.next32PostInc()) { 1.277 + * exit(1); // CharacterIterator inconsistent 1.278 + * } 1.279 + * } 1.280 + * \endcode 1.281 + * 1.282 + * <p>Examples, especially for the old API:</p> 1.283 + * 1.284 + * Function processing characters, in this example simple output 1.285 + * <pre> 1.286 + * \code 1.287 + * void processChar( UChar c ) 1.288 + * { 1.289 + * cout << " " << c; 1.290 + * } 1.291 + * \endcode 1.292 + * </pre> 1.293 + * Traverse the text from start to finish 1.294 + * <pre> 1.295 + * \code 1.296 + * void traverseForward(CharacterIterator& iter) 1.297 + * { 1.298 + * for(UChar c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) { 1.299 + * processChar(c); 1.300 + * } 1.301 + * } 1.302 + * \endcode 1.303 + * </pre> 1.304 + * Traverse the text backwards, from end to start 1.305 + * <pre> 1.306 + * \code 1.307 + * void traverseBackward(CharacterIterator& iter) 1.308 + * { 1.309 + * for(UChar c = iter.last(); c != CharacterIterator.DONE; c = iter.previous()) { 1.310 + * processChar(c); 1.311 + * } 1.312 + * } 1.313 + * \endcode 1.314 + * </pre> 1.315 + * Traverse both forward and backward from a given position in the text. 1.316 + * Calls to notBoundary() in this example represents some additional stopping criteria. 1.317 + * <pre> 1.318 + * \code 1.319 + * void traverseOut(CharacterIterator& iter, int32_t pos) 1.320 + * { 1.321 + * UChar c; 1.322 + * for (c = iter.setIndex(pos); 1.323 + * c != CharacterIterator.DONE && (Unicode::isLetter(c) || Unicode::isDigit(c)); 1.324 + * c = iter.next()) {} 1.325 + * int32_t end = iter.getIndex(); 1.326 + * for (c = iter.setIndex(pos); 1.327 + * c != CharacterIterator.DONE && (Unicode::isLetter(c) || Unicode::isDigit(c)); 1.328 + * c = iter.previous()) {} 1.329 + * int32_t start = iter.getIndex() + 1; 1.330 + * 1.331 + * cout << "start: " << start << " end: " << end << endl; 1.332 + * for (c = iter.setIndex(start); iter.getIndex() < end; c = iter.next() ) { 1.333 + * processChar(c); 1.334 + * } 1.335 + * } 1.336 + * \endcode 1.337 + * </pre> 1.338 + * Creating a StringCharacterIterator and calling the test functions 1.339 + * <pre> 1.340 + * \code 1.341 + * void CharacterIterator_Example( void ) 1.342 + * { 1.343 + * cout << endl << "===== CharacterIterator_Example: =====" << endl; 1.344 + * UnicodeString text("Ein kleiner Satz."); 1.345 + * StringCharacterIterator iterator(text); 1.346 + * cout << "----- traverseForward: -----------" << endl; 1.347 + * traverseForward( iterator ); 1.348 + * cout << endl << endl << "----- traverseBackward: ----------" << endl; 1.349 + * traverseBackward( iterator ); 1.350 + * cout << endl << endl << "----- traverseOut: ---------------" << endl; 1.351 + * traverseOut( iterator, 7 ); 1.352 + * cout << endl << endl << "-----" << endl; 1.353 + * } 1.354 + * \endcode 1.355 + * </pre> 1.356 + * 1.357 + * @stable ICU 2.0 1.358 + */ 1.359 +class U_COMMON_API CharacterIterator : public ForwardCharacterIterator { 1.360 +public: 1.361 + /** 1.362 + * Origin enumeration for the move() and move32() functions. 1.363 + * @stable ICU 2.0 1.364 + */ 1.365 + enum EOrigin { kStart, kCurrent, kEnd }; 1.366 + 1.367 + /** 1.368 + * Destructor. 1.369 + * @stable ICU 2.0 1.370 + */ 1.371 + virtual ~CharacterIterator(); 1.372 + 1.373 + /** 1.374 + * Returns a pointer to a new CharacterIterator of the same 1.375 + * concrete class as this one, and referring to the same 1.376 + * character in the same text-storage object as this one. The 1.377 + * caller is responsible for deleting the new clone. 1.378 + * @return a pointer to a new CharacterIterator 1.379 + * @stable ICU 2.0 1.380 + */ 1.381 + virtual CharacterIterator* clone(void) const = 0; 1.382 + 1.383 + /** 1.384 + * Sets the iterator to refer to the first code unit in its 1.385 + * iteration range, and returns that code unit. 1.386 + * This can be used to begin an iteration with next(). 1.387 + * @return the first code unit in its iteration range. 1.388 + * @stable ICU 2.0 1.389 + */ 1.390 + virtual UChar first(void) = 0; 1.391 + 1.392 + /** 1.393 + * Sets the iterator to refer to the first code unit in its 1.394 + * iteration range, returns that code unit, and moves the position 1.395 + * to the second code unit. This is an alternative to setToStart() 1.396 + * for forward iteration with nextPostInc(). 1.397 + * @return the first code unit in its iteration range. 1.398 + * @stable ICU 2.0 1.399 + */ 1.400 + virtual UChar firstPostInc(void); 1.401 + 1.402 + /** 1.403 + * Sets the iterator to refer to the first code point in its 1.404 + * iteration range, and returns that code unit, 1.405 + * This can be used to begin an iteration with next32(). 1.406 + * Note that an iteration with next32PostInc(), beginning with, 1.407 + * e.g., setToStart() or firstPostInc(), is more efficient. 1.408 + * @return the first code point in its iteration range. 1.409 + * @stable ICU 2.0 1.410 + */ 1.411 + virtual UChar32 first32(void) = 0; 1.412 + 1.413 + /** 1.414 + * Sets the iterator to refer to the first code point in its 1.415 + * iteration range, returns that code point, and moves the position 1.416 + * to the second code point. This is an alternative to setToStart() 1.417 + * for forward iteration with next32PostInc(). 1.418 + * @return the first code point in its iteration range. 1.419 + * @stable ICU 2.0 1.420 + */ 1.421 + virtual UChar32 first32PostInc(void); 1.422 + 1.423 + /** 1.424 + * Sets the iterator to refer to the first code unit or code point in its 1.425 + * iteration range. This can be used to begin a forward 1.426 + * iteration with nextPostInc() or next32PostInc(). 1.427 + * @return the start position of the iteration range 1.428 + * @stable ICU 2.0 1.429 + */ 1.430 + inline int32_t setToStart(); 1.431 + 1.432 + /** 1.433 + * Sets the iterator to refer to the last code unit in its 1.434 + * iteration range, and returns that code unit. 1.435 + * This can be used to begin an iteration with previous(). 1.436 + * @return the last code unit. 1.437 + * @stable ICU 2.0 1.438 + */ 1.439 + virtual UChar last(void) = 0; 1.440 + 1.441 + /** 1.442 + * Sets the iterator to refer to the last code point in its 1.443 + * iteration range, and returns that code unit. 1.444 + * This can be used to begin an iteration with previous32(). 1.445 + * @return the last code point. 1.446 + * @stable ICU 2.0 1.447 + */ 1.448 + virtual UChar32 last32(void) = 0; 1.449 + 1.450 + /** 1.451 + * Sets the iterator to the end of its iteration range, just behind 1.452 + * the last code unit or code point. This can be used to begin a backward 1.453 + * iteration with previous() or previous32(). 1.454 + * @return the end position of the iteration range 1.455 + * @stable ICU 2.0 1.456 + */ 1.457 + inline int32_t setToEnd(); 1.458 + 1.459 + /** 1.460 + * Sets the iterator to refer to the "position"-th code unit 1.461 + * in the text-storage object the iterator refers to, and 1.462 + * returns that code unit. 1.463 + * @param position the "position"-th code unit in the text-storage object 1.464 + * @return the "position"-th code unit. 1.465 + * @stable ICU 2.0 1.466 + */ 1.467 + virtual UChar setIndex(int32_t position) = 0; 1.468 + 1.469 + /** 1.470 + * Sets the iterator to refer to the beginning of the code point 1.471 + * that contains the "position"-th code unit 1.472 + * in the text-storage object the iterator refers to, and 1.473 + * returns that code point. 1.474 + * The current position is adjusted to the beginning of the code point 1.475 + * (its first code unit). 1.476 + * @param position the "position"-th code unit in the text-storage object 1.477 + * @return the "position"-th code point. 1.478 + * @stable ICU 2.0 1.479 + */ 1.480 + virtual UChar32 setIndex32(int32_t position) = 0; 1.481 + 1.482 + /** 1.483 + * Returns the code unit the iterator currently refers to. 1.484 + * @return the current code unit. 1.485 + * @stable ICU 2.0 1.486 + */ 1.487 + virtual UChar current(void) const = 0; 1.488 + 1.489 + /** 1.490 + * Returns the code point the iterator currently refers to. 1.491 + * @return the current code point. 1.492 + * @stable ICU 2.0 1.493 + */ 1.494 + virtual UChar32 current32(void) const = 0; 1.495 + 1.496 + /** 1.497 + * Advances to the next code unit in the iteration range 1.498 + * (toward endIndex()), and returns that code unit. If there are 1.499 + * no more code units to return, returns DONE. 1.500 + * @return the next code unit. 1.501 + * @stable ICU 2.0 1.502 + */ 1.503 + virtual UChar next(void) = 0; 1.504 + 1.505 + /** 1.506 + * Advances to the next code point in the iteration range 1.507 + * (toward endIndex()), and returns that code point. If there are 1.508 + * no more code points to return, returns DONE. 1.509 + * Note that iteration with "pre-increment" semantics is less 1.510 + * efficient than iteration with "post-increment" semantics 1.511 + * that is provided by next32PostInc(). 1.512 + * @return the next code point. 1.513 + * @stable ICU 2.0 1.514 + */ 1.515 + virtual UChar32 next32(void) = 0; 1.516 + 1.517 + /** 1.518 + * Advances to the previous code unit in the iteration range 1.519 + * (toward startIndex()), and returns that code unit. If there are 1.520 + * no more code units to return, returns DONE. 1.521 + * @return the previous code unit. 1.522 + * @stable ICU 2.0 1.523 + */ 1.524 + virtual UChar previous(void) = 0; 1.525 + 1.526 + /** 1.527 + * Advances to the previous code point in the iteration range 1.528 + * (toward startIndex()), and returns that code point. If there are 1.529 + * no more code points to return, returns DONE. 1.530 + * @return the previous code point. 1.531 + * @stable ICU 2.0 1.532 + */ 1.533 + virtual UChar32 previous32(void) = 0; 1.534 + 1.535 + /** 1.536 + * Returns FALSE if there are no more code units or code points 1.537 + * before the current position in the iteration range. 1.538 + * This is used with previous() or previous32() in backward 1.539 + * iteration. 1.540 + * @return FALSE if there are no more code units or code points 1.541 + * before the current position in the iteration range, return TRUE otherwise. 1.542 + * @stable ICU 2.0 1.543 + */ 1.544 + virtual UBool hasPrevious() = 0; 1.545 + 1.546 + /** 1.547 + * Returns the numeric index in the underlying text-storage 1.548 + * object of the character returned by first(). Since it's 1.549 + * possible to create an iterator that iterates across only 1.550 + * part of a text-storage object, this number isn't 1.551 + * necessarily 0. 1.552 + * @returns the numeric index in the underlying text-storage 1.553 + * object of the character returned by first(). 1.554 + * @stable ICU 2.0 1.555 + */ 1.556 + inline int32_t startIndex(void) const; 1.557 + 1.558 + /** 1.559 + * Returns the numeric index in the underlying text-storage 1.560 + * object of the position immediately BEYOND the character 1.561 + * returned by last(). 1.562 + * @return the numeric index in the underlying text-storage 1.563 + * object of the position immediately BEYOND the character 1.564 + * returned by last(). 1.565 + * @stable ICU 2.0 1.566 + */ 1.567 + inline int32_t endIndex(void) const; 1.568 + 1.569 + /** 1.570 + * Returns the numeric index in the underlying text-storage 1.571 + * object of the character the iterator currently refers to 1.572 + * (i.e., the character returned by current()). 1.573 + * @return the numberic index in the text-storage object of 1.574 + * the character the iterator currently refers to 1.575 + * @stable ICU 2.0 1.576 + */ 1.577 + inline int32_t getIndex(void) const; 1.578 + 1.579 + /** 1.580 + * Returns the length of the entire text in the underlying 1.581 + * text-storage object. 1.582 + * @return the length of the entire text in the text-storage object 1.583 + * @stable ICU 2.0 1.584 + */ 1.585 + inline int32_t getLength() const; 1.586 + 1.587 + /** 1.588 + * Moves the current position relative to the start or end of the 1.589 + * iteration range, or relative to the current position itself. 1.590 + * The movement is expressed in numbers of code units forward 1.591 + * or backward by specifying a positive or negative delta. 1.592 + * @param delta the position relative to origin. A positive delta means forward; 1.593 + * a negative delta means backward. 1.594 + * @param origin Origin enumeration {kStart, kCurrent, kEnd} 1.595 + * @return the new position 1.596 + * @stable ICU 2.0 1.597 + */ 1.598 + virtual int32_t move(int32_t delta, EOrigin origin) = 0; 1.599 + 1.600 + /** 1.601 + * Moves the current position relative to the start or end of the 1.602 + * iteration range, or relative to the current position itself. 1.603 + * The movement is expressed in numbers of code points forward 1.604 + * or backward by specifying a positive or negative delta. 1.605 + * @param delta the position relative to origin. A positive delta means forward; 1.606 + * a negative delta means backward. 1.607 + * @param origin Origin enumeration {kStart, kCurrent, kEnd} 1.608 + * @return the new position 1.609 + * @stable ICU 2.0 1.610 + */ 1.611 + virtual int32_t move32(int32_t delta, EOrigin origin) = 0; 1.612 + 1.613 + /** 1.614 + * Copies the text under iteration into the UnicodeString 1.615 + * referred to by "result". 1.616 + * @param result Receives a copy of the text under iteration. 1.617 + * @stable ICU 2.0 1.618 + */ 1.619 + virtual void getText(UnicodeString& result) = 0; 1.620 + 1.621 +protected: 1.622 + /** 1.623 + * Empty constructor. 1.624 + * @stable ICU 2.0 1.625 + */ 1.626 + CharacterIterator(); 1.627 + 1.628 + /** 1.629 + * Constructor, just setting the length field in this base class. 1.630 + * @stable ICU 2.0 1.631 + */ 1.632 + CharacterIterator(int32_t length); 1.633 + 1.634 + /** 1.635 + * Constructor, just setting the length and position fields in this base class. 1.636 + * @stable ICU 2.0 1.637 + */ 1.638 + CharacterIterator(int32_t length, int32_t position); 1.639 + 1.640 + /** 1.641 + * Constructor, just setting the length, start, end, and position fields in this base class. 1.642 + * @stable ICU 2.0 1.643 + */ 1.644 + CharacterIterator(int32_t length, int32_t textBegin, int32_t textEnd, int32_t position); 1.645 + 1.646 + /** 1.647 + * Copy constructor. 1.648 + * 1.649 + * @param that The CharacterIterator to be copied 1.650 + * @stable ICU 2.0 1.651 + */ 1.652 + CharacterIterator(const CharacterIterator &that); 1.653 + 1.654 + /** 1.655 + * Assignment operator. Sets this CharacterIterator to have the same behavior, 1.656 + * as the one passed in. 1.657 + * @param that The CharacterIterator passed in. 1.658 + * @return the newly set CharacterIterator. 1.659 + * @stable ICU 2.0 1.660 + */ 1.661 + CharacterIterator &operator=(const CharacterIterator &that); 1.662 + 1.663 + /** 1.664 + * Base class text length field. 1.665 + * Necessary this for correct getText() and hashCode(). 1.666 + * @stable ICU 2.0 1.667 + */ 1.668 + int32_t textLength; 1.669 + 1.670 + /** 1.671 + * Base class field for the current position. 1.672 + * @stable ICU 2.0 1.673 + */ 1.674 + int32_t pos; 1.675 + 1.676 + /** 1.677 + * Base class field for the start of the iteration range. 1.678 + * @stable ICU 2.0 1.679 + */ 1.680 + int32_t begin; 1.681 + 1.682 + /** 1.683 + * Base class field for the end of the iteration range. 1.684 + * @stable ICU 2.0 1.685 + */ 1.686 + int32_t end; 1.687 +}; 1.688 + 1.689 +inline UBool 1.690 +ForwardCharacterIterator::operator!=(const ForwardCharacterIterator& that) const { 1.691 + return !operator==(that); 1.692 +} 1.693 + 1.694 +inline int32_t 1.695 +CharacterIterator::setToStart() { 1.696 + return move(0, kStart); 1.697 +} 1.698 + 1.699 +inline int32_t 1.700 +CharacterIterator::setToEnd() { 1.701 + return move(0, kEnd); 1.702 +} 1.703 + 1.704 +inline int32_t 1.705 +CharacterIterator::startIndex(void) const { 1.706 + return begin; 1.707 +} 1.708 + 1.709 +inline int32_t 1.710 +CharacterIterator::endIndex(void) const { 1.711 + return end; 1.712 +} 1.713 + 1.714 +inline int32_t 1.715 +CharacterIterator::getIndex(void) const { 1.716 + return pos; 1.717 +} 1.718 + 1.719 +inline int32_t 1.720 +CharacterIterator::getLength(void) const { 1.721 + return textLength; 1.722 +} 1.723 + 1.724 +U_NAMESPACE_END 1.725 +#endif