chariter.h 24 KB

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