chariter.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. // Copyright (C) 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. ********************************************************************
  5. *
  6. * Copyright (C) 1997-2011, International Business Machines
  7. * Corporation and others. All Rights Reserved.
  8. *
  9. ********************************************************************
  10. */
  11. #ifndef CHARITER_H
  12. #define CHARITER_H
  13. #include "unicode/utypes.h"
  14. #include "unicode/uobject.h"
  15. #include "unicode/unistr.h"
  16. /**
  17. * \file
  18. * \brief C++ API: Character Iterator
  19. */
  20. U_NAMESPACE_BEGIN
  21. /**
  22. * Abstract class that defines an API for forward-only iteration
  23. * on text objects.
  24. * This is a minimal interface for iteration without random access
  25. * or backwards iteration. It is especially useful for wrapping
  26. * streams with converters into an object for collation or
  27. * normalization.
  28. *
  29. * <p>Characters can be accessed in two ways: as code units or as
  30. * code points.
  31. * Unicode code points are 21-bit integers and are the scalar values
  32. * of Unicode characters. ICU uses the type UChar32 for them.
  33. * Unicode code units are the storage units of a given
  34. * Unicode/UCS Transformation Format (a character encoding scheme).
  35. * With UTF-16, all code points can be represented with either one
  36. * or two code units ("surrogates").
  37. * String storage is typically based on code units, while properties
  38. * of characters are typically determined using code point values.
  39. * Some processes may be designed to work with sequences of code units,
  40. * or it may be known that all characters that are important to an
  41. * algorithm can be represented with single code units.
  42. * Other processes will need to use the code point access functions.</p>
  43. *
  44. * <p>ForwardCharacterIterator provides nextPostInc() to access
  45. * a code unit and advance an internal position into the text object,
  46. * similar to a <code>return text[position++]</code>.<br>
  47. * It provides next32PostInc() to access a code point and advance an internal
  48. * position.</p>
  49. *
  50. * <p>next32PostInc() assumes that the current position is that of
  51. * the beginning of a code point, i.e., of its first code unit.
  52. * After next32PostInc(), this will be true again.
  53. * In general, access to code units and code points in the same
  54. * iteration loop should not be mixed. In UTF-16, if the current position
  55. * is on a second code unit (Low Surrogate), then only that code unit
  56. * is returned even by next32PostInc().</p>
  57. *
  58. * <p>For iteration with either function, there are two ways to
  59. * check for the end of the iteration. When there are no more
  60. * characters in the text object:
  61. * <ul>
  62. * <li>The hasNext() function returns FALSE.</li>
  63. * <li>nextPostInc() and next32PostInc() return DONE
  64. * when one attempts to read beyond the end of the text object.</li>
  65. * </ul>
  66. *
  67. * Example:
  68. * \code
  69. * void function1(ForwardCharacterIterator &it) {
  70. * UChar32 c;
  71. * while(it.hasNext()) {
  72. * c=it.next32PostInc();
  73. * // use c
  74. * }
  75. * }
  76. *
  77. * void function1(ForwardCharacterIterator &it) {
  78. * UChar c;
  79. * while((c=it.nextPostInc())!=ForwardCharacterIterator::DONE) {
  80. * // use c
  81. * }
  82. * }
  83. * \endcode
  84. * </p>
  85. *
  86. * @stable ICU 2.0
  87. */
  88. class U_COMMON_API ForwardCharacterIterator : public UObject {
  89. public:
  90. /**
  91. * Value returned by most of ForwardCharacterIterator's functions
  92. * when the iterator has reached the limits of its iteration.
  93. * @stable ICU 2.0
  94. */
  95. enum { DONE = 0xffff };
  96. /**
  97. * Destructor.
  98. * @stable ICU 2.0
  99. */
  100. virtual ~ForwardCharacterIterator();
  101. /**
  102. * Returns true when both iterators refer to the same
  103. * character in the same character-storage object.
  104. * @param that The ForwardCharacterIterator to be compared for equality
  105. * @return true when both iterators refer to the same
  106. * character in the same character-storage object
  107. * @stable ICU 2.0
  108. */
  109. virtual UBool operator==(const ForwardCharacterIterator& that) const = 0;
  110. /**
  111. * Returns true when the iterators refer to different
  112. * text-storage objects, or to different characters in the
  113. * same text-storage object.
  114. * @param that The ForwardCharacterIterator to be compared for inequality
  115. * @return true when the iterators refer to different
  116. * text-storage objects, or to different characters in the
  117. * same text-storage object
  118. * @stable ICU 2.0
  119. */
  120. inline UBool operator!=(const ForwardCharacterIterator& that) const;
  121. /**
  122. * Generates a hash code for this iterator.
  123. * @return the hash code.
  124. * @stable ICU 2.0
  125. */
  126. virtual int32_t hashCode(void) const = 0;
  127. /**
  128. * Returns a UClassID for this ForwardCharacterIterator ("poor man's
  129. * RTTI").<P> Despite the fact that this function is public,
  130. * DO NOT CONSIDER IT PART OF CHARACTERITERATOR'S API!
  131. * @return a UClassID for this ForwardCharacterIterator
  132. * @stable ICU 2.0
  133. */
  134. virtual UClassID getDynamicClassID(void) const = 0;
  135. /**
  136. * Gets the current code unit for returning and advances to the next code unit
  137. * in the iteration range
  138. * (toward endIndex()). If there are
  139. * no more code units to return, returns DONE.
  140. * @return the current code unit.
  141. * @stable ICU 2.0
  142. */
  143. virtual UChar nextPostInc(void) = 0;
  144. /**
  145. * Gets the current code point for returning and advances to the next code point
  146. * in the iteration range
  147. * (toward endIndex()). If there are
  148. * no more code points to return, returns DONE.
  149. * @return the current code point.
  150. * @stable ICU 2.0
  151. */
  152. virtual UChar32 next32PostInc(void) = 0;
  153. /**
  154. * Returns FALSE if there are no more code units or code points
  155. * at or after the current position in the iteration range.
  156. * This is used with nextPostInc() or next32PostInc() in forward
  157. * iteration.
  158. * @returns FALSE if there are no more code units or code points
  159. * at or after the current position in the iteration range.
  160. * @stable ICU 2.0
  161. */
  162. virtual UBool hasNext() = 0;
  163. protected:
  164. /** Default constructor to be overridden in the implementing class. @stable ICU 2.0*/
  165. ForwardCharacterIterator();
  166. /** Copy constructor to be overridden in the implementing class. @stable ICU 2.0*/
  167. ForwardCharacterIterator(const ForwardCharacterIterator &other);
  168. /**
  169. * Assignment operator to be overridden in the implementing class.
  170. * @stable ICU 2.0
  171. */
  172. ForwardCharacterIterator &operator=(const ForwardCharacterIterator&) { return *this; }
  173. };
  174. /**
  175. * Abstract class that defines an API for iteration
  176. * on text objects.
  177. * This is an interface for forward and backward iteration
  178. * and random access into a text object.
  179. *
  180. * <p>The API provides backward compatibility to the Java and older ICU
  181. * CharacterIterator classes but extends them significantly:
  182. * <ol>
  183. * <li>CharacterIterator is now a subclass of ForwardCharacterIterator.</li>
  184. * <li>While the old API functions provided forward iteration with
  185. * "pre-increment" semantics, the new one also provides functions
  186. * with "post-increment" semantics. They are more efficient and should
  187. * be the preferred iterator functions for new implementations.
  188. * The backward iteration always had "pre-decrement" semantics, which
  189. * are efficient.</li>
  190. * <li>Just like ForwardCharacterIterator, it provides access to
  191. * both code units and code points. Code point access versions are available
  192. * for the old and the new iteration semantics.</li>
  193. * <li>There are new functions for setting and moving the current position
  194. * without returning a character, for efficiency.</li>
  195. * </ol>
  196. *
  197. * See ForwardCharacterIterator for examples for using the new forward iteration
  198. * functions. For backward iteration, there is also a hasPrevious() function
  199. * that can be used analogously to hasNext().
  200. * The old functions work as before and are shown below.</p>
  201. *
  202. * <p>Examples for some of the new functions:</p>
  203. *
  204. * Forward iteration with hasNext():
  205. * \code
  206. * void forward1(CharacterIterator &it) {
  207. * UChar32 c;
  208. * for(it.setToStart(); it.hasNext();) {
  209. * c=it.next32PostInc();
  210. * // use c
  211. * }
  212. * }
  213. * \endcode
  214. * Forward iteration more similar to loops with the old forward iteration,
  215. * showing a way to convert simple for() loops:
  216. * \code
  217. * void forward2(CharacterIterator &it) {
  218. * UChar c;
  219. * for(c=it.firstPostInc(); c!=CharacterIterator::DONE; c=it.nextPostInc()) {
  220. * // use c
  221. * }
  222. * }
  223. * \endcode
  224. * Backward iteration with setToEnd() and hasPrevious():
  225. * \code
  226. * void backward1(CharacterIterator &it) {
  227. * UChar32 c;
  228. * for(it.setToEnd(); it.hasPrevious();) {
  229. * c=it.previous32();
  230. * // use c
  231. * }
  232. * }
  233. * \endcode
  234. * Backward iteration with a more traditional for() loop:
  235. * \code
  236. * void backward2(CharacterIterator &it) {
  237. * UChar c;
  238. * for(c=it.last(); c!=CharacterIterator::DONE; c=it.previous()) {
  239. * // use c
  240. * }
  241. * }
  242. * \endcode
  243. *
  244. * Example for random access:
  245. * \code
  246. * void random(CharacterIterator &it) {
  247. * // set to the third code point from the beginning
  248. * it.move32(3, CharacterIterator::kStart);
  249. * // get a code point from here without moving the position
  250. * UChar32 c=it.current32();
  251. * // get the position
  252. * int32_t pos=it.getIndex();
  253. * // get the previous code unit
  254. * UChar u=it.previous();
  255. * // move back one more code unit
  256. * it.move(-1, CharacterIterator::kCurrent);
  257. * // set the position back to where it was
  258. * // and read the same code point c and move beyond it
  259. * it.setIndex(pos);
  260. * if(c!=it.next32PostInc()) {
  261. * exit(1); // CharacterIterator inconsistent
  262. * }
  263. * }
  264. * \endcode
  265. *
  266. * <p>Examples, especially for the old API:</p>
  267. *
  268. * Function processing characters, in this example simple output
  269. * <pre>
  270. * \code
  271. * void processChar( UChar c )
  272. * {
  273. * cout << " " << c;
  274. * }
  275. * \endcode
  276. * </pre>
  277. * Traverse the text from start to finish
  278. * <pre>
  279. * \code
  280. * void traverseForward(CharacterIterator& iter)
  281. * {
  282. * for(UChar c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
  283. * processChar(c);
  284. * }
  285. * }
  286. * \endcode
  287. * </pre>
  288. * Traverse the text backwards, from end to start
  289. * <pre>
  290. * \code
  291. * void traverseBackward(CharacterIterator& iter)
  292. * {
  293. * for(UChar c = iter.last(); c != CharacterIterator.DONE; c = iter.previous()) {
  294. * processChar(c);
  295. * }
  296. * }
  297. * \endcode
  298. * </pre>
  299. * Traverse both forward and backward from a given position in the text.
  300. * Calls to notBoundary() in this example represents some additional stopping criteria.
  301. * <pre>
  302. * \code
  303. * void traverseOut(CharacterIterator& iter, int32_t pos)
  304. * {
  305. * UChar c;
  306. * for (c = iter.setIndex(pos);
  307. * c != CharacterIterator.DONE && (Unicode::isLetter(c) || Unicode::isDigit(c));
  308. * c = iter.next()) {}
  309. * int32_t end = iter.getIndex();
  310. * for (c = iter.setIndex(pos);
  311. * c != CharacterIterator.DONE && (Unicode::isLetter(c) || Unicode::isDigit(c));
  312. * c = iter.previous()) {}
  313. * int32_t start = iter.getIndex() + 1;
  314. *
  315. * cout << "start: " << start << " end: " << end << endl;
  316. * for (c = iter.setIndex(start); iter.getIndex() < end; c = iter.next() ) {
  317. * processChar(c);
  318. * }
  319. * }
  320. * \endcode
  321. * </pre>
  322. * Creating a StringCharacterIterator and calling the test functions
  323. * <pre>
  324. * \code
  325. * void CharacterIterator_Example( void )
  326. * {
  327. * cout << endl << "===== CharacterIterator_Example: =====" << endl;
  328. * UnicodeString text("Ein kleiner Satz.");
  329. * StringCharacterIterator iterator(text);
  330. * cout << "----- traverseForward: -----------" << endl;
  331. * traverseForward( iterator );
  332. * cout << endl << endl << "----- traverseBackward: ----------" << endl;
  333. * traverseBackward( iterator );
  334. * cout << endl << endl << "----- traverseOut: ---------------" << endl;
  335. * traverseOut( iterator, 7 );
  336. * cout << endl << endl << "-----" << endl;
  337. * }
  338. * \endcode
  339. * </pre>
  340. *
  341. * @stable ICU 2.0
  342. */
  343. class U_COMMON_API CharacterIterator : public ForwardCharacterIterator {
  344. public:
  345. /**
  346. * Origin enumeration for the move() and move32() functions.
  347. * @stable ICU 2.0
  348. */
  349. enum EOrigin { kStart, kCurrent, kEnd };
  350. /**
  351. * Destructor.
  352. * @stable ICU 2.0
  353. */
  354. virtual ~CharacterIterator();
  355. /**
  356. * Returns a pointer to a new CharacterIterator of the same
  357. * concrete class as this one, and referring to the same
  358. * character in the same text-storage object as this one. The
  359. * caller is responsible for deleting the new clone.
  360. * @return a pointer to a new CharacterIterator
  361. * @stable ICU 2.0
  362. */
  363. virtual CharacterIterator* clone(void) const = 0;
  364. /**
  365. * Sets the iterator to refer to the first code unit in its
  366. * iteration range, and returns that code unit.
  367. * This can be used to begin an iteration with next().
  368. * @return the first code unit in its iteration range.
  369. * @stable ICU 2.0
  370. */
  371. virtual UChar first(void) = 0;
  372. /**
  373. * Sets the iterator to refer to the first code unit in its
  374. * iteration range, returns that code unit, and moves the position
  375. * to the second code unit. This is an alternative to setToStart()
  376. * for forward iteration with nextPostInc().
  377. * @return the first code unit in its iteration range.
  378. * @stable ICU 2.0
  379. */
  380. virtual UChar firstPostInc(void);
  381. /**
  382. * Sets the iterator to refer to the first code point in its
  383. * iteration range, and returns that code unit,
  384. * This can be used to begin an iteration with next32().
  385. * Note that an iteration with next32PostInc(), beginning with,
  386. * e.g., setToStart() or firstPostInc(), is more efficient.
  387. * @return the first code point in its iteration range.
  388. * @stable ICU 2.0
  389. */
  390. virtual UChar32 first32(void) = 0;
  391. /**
  392. * Sets the iterator to refer to the first code point in its
  393. * iteration range, returns that code point, and moves the position
  394. * to the second code point. This is an alternative to setToStart()
  395. * for forward iteration with next32PostInc().
  396. * @return the first code point in its iteration range.
  397. * @stable ICU 2.0
  398. */
  399. virtual UChar32 first32PostInc(void);
  400. /**
  401. * Sets the iterator to refer to the first code unit or code point in its
  402. * iteration range. This can be used to begin a forward
  403. * iteration with nextPostInc() or next32PostInc().
  404. * @return the start position of the iteration range
  405. * @stable ICU 2.0
  406. */
  407. inline int32_t setToStart();
  408. /**
  409. * Sets the iterator to refer to the last code unit in its
  410. * iteration range, and returns that code unit.
  411. * This can be used to begin an iteration with previous().
  412. * @return the last code unit.
  413. * @stable ICU 2.0
  414. */
  415. virtual UChar last(void) = 0;
  416. /**
  417. * Sets the iterator to refer to the last code point in its
  418. * iteration range, and returns that code unit.
  419. * This can be used to begin an iteration with previous32().
  420. * @return the last code point.
  421. * @stable ICU 2.0
  422. */
  423. virtual UChar32 last32(void) = 0;
  424. /**
  425. * Sets the iterator to the end of its iteration range, just behind
  426. * the last code unit or code point. This can be used to begin a backward
  427. * iteration with previous() or previous32().
  428. * @return the end position of the iteration range
  429. * @stable ICU 2.0
  430. */
  431. inline int32_t setToEnd();
  432. /**
  433. * Sets the iterator to refer to the "position"-th code unit
  434. * in the text-storage object the iterator refers to, and
  435. * returns that code unit.
  436. * @param position the "position"-th code unit in the text-storage object
  437. * @return the "position"-th code unit.
  438. * @stable ICU 2.0
  439. */
  440. virtual UChar setIndex(int32_t position) = 0;
  441. /**
  442. * Sets the iterator to refer to the beginning of the code point
  443. * that contains the "position"-th code unit
  444. * in the text-storage object the iterator refers to, and
  445. * returns that code point.
  446. * The current position is adjusted to the beginning of the code point
  447. * (its first code unit).
  448. * @param position the "position"-th code unit in the text-storage object
  449. * @return the "position"-th code point.
  450. * @stable ICU 2.0
  451. */
  452. virtual UChar32 setIndex32(int32_t position) = 0;
  453. /**
  454. * Returns the code unit the iterator currently refers to.
  455. * @return the current code unit.
  456. * @stable ICU 2.0
  457. */
  458. virtual UChar current(void) const = 0;
  459. /**
  460. * Returns the code point the iterator currently refers to.
  461. * @return the current code point.
  462. * @stable ICU 2.0
  463. */
  464. virtual UChar32 current32(void) const = 0;
  465. /**
  466. * Advances to the next code unit in the iteration range
  467. * (toward endIndex()), and returns that code unit. If there are
  468. * no more code units to return, returns DONE.
  469. * @return the next code unit.
  470. * @stable ICU 2.0
  471. */
  472. virtual UChar next(void) = 0;
  473. /**
  474. * Advances to the next code point in the iteration range
  475. * (toward endIndex()), and returns that code point. If there are
  476. * no more code points to return, returns DONE.
  477. * Note that iteration with "pre-increment" semantics is less
  478. * efficient than iteration with "post-increment" semantics
  479. * that is provided by next32PostInc().
  480. * @return the next code point.
  481. * @stable ICU 2.0
  482. */
  483. virtual UChar32 next32(void) = 0;
  484. /**
  485. * Advances to the previous code unit in the iteration range
  486. * (toward startIndex()), and returns that code unit. If there are
  487. * no more code units to return, returns DONE.
  488. * @return the previous code unit.
  489. * @stable ICU 2.0
  490. */
  491. virtual UChar previous(void) = 0;
  492. /**
  493. * Advances to the previous code point in the iteration range
  494. * (toward startIndex()), and returns that code point. If there are
  495. * no more code points to return, returns DONE.
  496. * @return the previous code point.
  497. * @stable ICU 2.0
  498. */
  499. virtual UChar32 previous32(void) = 0;
  500. /**
  501. * Returns FALSE if there are no more code units or code points
  502. * before the current position in the iteration range.
  503. * This is used with previous() or previous32() in backward
  504. * iteration.
  505. * @return FALSE if there are no more code units or code points
  506. * before the current position in the iteration range, return TRUE otherwise.
  507. * @stable ICU 2.0
  508. */
  509. virtual UBool hasPrevious() = 0;
  510. /**
  511. * Returns the numeric index in the underlying text-storage
  512. * object of the character returned by first(). Since it's
  513. * possible to create an iterator that iterates across only
  514. * part of a text-storage object, this number isn't
  515. * necessarily 0.
  516. * @returns the numeric index in the underlying text-storage
  517. * object of the character returned by first().
  518. * @stable ICU 2.0
  519. */
  520. inline int32_t startIndex(void) const;
  521. /**
  522. * Returns the numeric index in the underlying text-storage
  523. * object of the position immediately BEYOND the character
  524. * returned by last().
  525. * @return the numeric index in the underlying text-storage
  526. * object of the position immediately BEYOND the character
  527. * returned by last().
  528. * @stable ICU 2.0
  529. */
  530. inline int32_t endIndex(void) const;
  531. /**
  532. * Returns the numeric index in the underlying text-storage
  533. * object of the character the iterator currently refers to
  534. * (i.e., the character returned by current()).
  535. * @return the numberic index in the text-storage object of
  536. * the character the iterator currently refers to
  537. * @stable ICU 2.0
  538. */
  539. inline int32_t getIndex(void) const;
  540. /**
  541. * Returns the length of the entire text in the underlying
  542. * text-storage object.
  543. * @return the length of the entire text in the text-storage object
  544. * @stable ICU 2.0
  545. */
  546. inline int32_t getLength() const;
  547. /**
  548. * Moves the current position relative to the start or end of the
  549. * iteration range, or relative to the current position itself.
  550. * The movement is expressed in numbers of code units forward
  551. * or backward by specifying a positive or negative delta.
  552. * @param delta the position relative to origin. A positive delta means forward;
  553. * a negative delta means backward.
  554. * @param origin Origin enumeration {kStart, kCurrent, kEnd}
  555. * @return the new position
  556. * @stable ICU 2.0
  557. */
  558. virtual int32_t move(int32_t delta, EOrigin origin) = 0;
  559. /**
  560. * Moves the current position relative to the start or end of the
  561. * iteration range, or relative to the current position itself.
  562. * The movement is expressed in numbers of code points forward
  563. * or backward by specifying a positive or negative delta.
  564. * @param delta the position relative to origin. A positive delta means forward;
  565. * a negative delta means backward.
  566. * @param origin Origin enumeration {kStart, kCurrent, kEnd}
  567. * @return the new position
  568. * @stable ICU 2.0
  569. */
  570. virtual int32_t move32(int32_t delta, EOrigin origin) = 0;
  571. /**
  572. * Copies the text under iteration into the UnicodeString
  573. * referred to by "result".
  574. * @param result Receives a copy of the text under iteration.
  575. * @stable ICU 2.0
  576. */
  577. virtual void getText(UnicodeString& result) = 0;
  578. protected:
  579. /**
  580. * Empty constructor.
  581. * @stable ICU 2.0
  582. */
  583. CharacterIterator();
  584. /**
  585. * Constructor, just setting the length field in this base class.
  586. * @stable ICU 2.0
  587. */
  588. CharacterIterator(int32_t length);
  589. /**
  590. * Constructor, just setting the length and position fields in this base class.
  591. * @stable ICU 2.0
  592. */
  593. CharacterIterator(int32_t length, int32_t position);
  594. /**
  595. * Constructor, just setting the length, start, end, and position fields in this base class.
  596. * @stable ICU 2.0
  597. */
  598. CharacterIterator(int32_t length, int32_t textBegin, int32_t textEnd, int32_t position);
  599. /**
  600. * Copy constructor.
  601. *
  602. * @param that The CharacterIterator to be copied
  603. * @stable ICU 2.0
  604. */
  605. CharacterIterator(const CharacterIterator &that);
  606. /**
  607. * Assignment operator. Sets this CharacterIterator to have the same behavior,
  608. * as the one passed in.
  609. * @param that The CharacterIterator passed in.
  610. * @return the newly set CharacterIterator.
  611. * @stable ICU 2.0
  612. */
  613. CharacterIterator &operator=(const CharacterIterator &that);
  614. /**
  615. * Base class text length field.
  616. * Necessary this for correct getText() and hashCode().
  617. * @stable ICU 2.0
  618. */
  619. int32_t textLength;
  620. /**
  621. * Base class field for the current position.
  622. * @stable ICU 2.0
  623. */
  624. int32_t pos;
  625. /**
  626. * Base class field for the start of the iteration range.
  627. * @stable ICU 2.0
  628. */
  629. int32_t begin;
  630. /**
  631. * Base class field for the end of the iteration range.
  632. * @stable ICU 2.0
  633. */
  634. int32_t end;
  635. };
  636. inline UBool
  637. ForwardCharacterIterator::operator!=(const ForwardCharacterIterator& that) const {
  638. return !operator==(that);
  639. }
  640. inline int32_t
  641. CharacterIterator::setToStart() {
  642. return move(0, kStart);
  643. }
  644. inline int32_t
  645. CharacterIterator::setToEnd() {
  646. return move(0, kEnd);
  647. }
  648. inline int32_t
  649. CharacterIterator::startIndex(void) const {
  650. return begin;
  651. }
  652. inline int32_t
  653. CharacterIterator::endIndex(void) const {
  654. return end;
  655. }
  656. inline int32_t
  657. CharacterIterator::getIndex(void) const {
  658. return pos;
  659. }
  660. inline int32_t
  661. CharacterIterator::getLength(void) const {
  662. return textLength;
  663. }
  664. U_NAMESPACE_END
  665. #endif