schriter.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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) 1998-2005, International Business Machines
  7. * Corporation and others. All Rights Reserved.
  8. *
  9. ******************************************************************************
  10. *
  11. * File schriter.h
  12. *
  13. * Modification History:
  14. *
  15. * Date Name Description
  16. * 05/05/99 stephen Cleaned up.
  17. ******************************************************************************
  18. */
  19. #ifndef SCHRITER_H
  20. #define SCHRITER_H
  21. #include "unicode/utypes.h"
  22. #include "unicode/chariter.h"
  23. #include "unicode/uchriter.h"
  24. /**
  25. * \file
  26. * \brief C++ API: String Character Iterator
  27. */
  28. U_NAMESPACE_BEGIN
  29. /**
  30. * A concrete subclass of CharacterIterator that iterates over the
  31. * characters (code units or code points) in a UnicodeString.
  32. * It's possible not only to create an
  33. * iterator that iterates over an entire UnicodeString, but also to
  34. * create one that iterates over only a subrange of a UnicodeString
  35. * (iterators over different subranges of the same UnicodeString don't
  36. * compare equal).
  37. * @see CharacterIterator
  38. * @see ForwardCharacterIterator
  39. * @stable ICU 2.0
  40. */
  41. class U_COMMON_API StringCharacterIterator : public UCharCharacterIterator {
  42. public:
  43. /**
  44. * Create an iterator over the UnicodeString referred to by "textStr".
  45. * The UnicodeString object is copied.
  46. * The iteration range is the whole string, and the starting position is 0.
  47. * @param textStr The unicode string used to create an iterator
  48. * @stable ICU 2.0
  49. */
  50. StringCharacterIterator(const UnicodeString& textStr);
  51. /**
  52. * Create an iterator over the UnicodeString referred to by "textStr".
  53. * The iteration range is the whole string, and the starting
  54. * position is specified by "textPos". If "textPos" is outside the valid
  55. * iteration range, the behavior of this object is undefined.
  56. * @param textStr The unicode string used to create an iterator
  57. * @param textPos The starting position of the iteration
  58. * @stable ICU 2.0
  59. */
  60. StringCharacterIterator(const UnicodeString& textStr,
  61. int32_t textPos);
  62. /**
  63. * Create an iterator over the UnicodeString referred to by "textStr".
  64. * The UnicodeString object is copied.
  65. * The iteration range begins with the code unit specified by
  66. * "textBegin" and ends with the code unit BEFORE the code unit specfied
  67. * by "textEnd". The starting position is specified by "textPos". If
  68. * "textBegin" and "textEnd" don't form a valid range on "text" (i.e.,
  69. * textBegin >= textEnd or either is negative or greater than text.size()),
  70. * or "textPos" is outside the range defined by "textBegin" and "textEnd",
  71. * the behavior of this iterator is undefined.
  72. * @param textStr The unicode string used to create the StringCharacterIterator
  73. * @param textBegin The begin position of the iteration range
  74. * @param textEnd The end position of the iteration range
  75. * @param textPos The starting position of the iteration
  76. * @stable ICU 2.0
  77. */
  78. StringCharacterIterator(const UnicodeString& textStr,
  79. int32_t textBegin,
  80. int32_t textEnd,
  81. int32_t textPos);
  82. /**
  83. * Copy constructor. The new iterator iterates over the same range
  84. * of the same string as "that", and its initial position is the
  85. * same as "that"'s current position.
  86. * The UnicodeString object in "that" is copied.
  87. * @param that The StringCharacterIterator to be copied
  88. * @stable ICU 2.0
  89. */
  90. StringCharacterIterator(const StringCharacterIterator& that);
  91. /**
  92. * Destructor.
  93. * @stable ICU 2.0
  94. */
  95. virtual ~StringCharacterIterator();
  96. /**
  97. * Assignment operator. *this is altered to iterate over the same
  98. * range of the same string as "that", and refers to the same
  99. * character within that string as "that" does.
  100. * @param that The object to be copied.
  101. * @return the newly created object.
  102. * @stable ICU 2.0
  103. */
  104. StringCharacterIterator&
  105. operator=(const StringCharacterIterator& that);
  106. /**
  107. * Returns true if the iterators iterate over the same range of the
  108. * same string and are pointing at the same character.
  109. * @param that The ForwardCharacterIterator to be compared for equality
  110. * @return true if the iterators iterate over the same range of the
  111. * same string and are pointing at the same character.
  112. * @stable ICU 2.0
  113. */
  114. virtual UBool operator==(const ForwardCharacterIterator& that) const;
  115. /**
  116. * Returns a new StringCharacterIterator referring to the same
  117. * character in the same range of the same string as this one. The
  118. * caller must delete the new iterator.
  119. * @return the newly cloned object.
  120. * @stable ICU 2.0
  121. */
  122. virtual CharacterIterator* clone(void) const;
  123. /**
  124. * Sets the iterator to iterate over the provided string.
  125. * @param newText The string to be iterated over
  126. * @stable ICU 2.0
  127. */
  128. void setText(const UnicodeString& newText);
  129. /**
  130. * Copies the UnicodeString under iteration into the UnicodeString
  131. * referred to by "result". Even if this iterator iterates across
  132. * only a part of this string, the whole string is copied.
  133. * @param result Receives a copy of the text under iteration.
  134. * @stable ICU 2.0
  135. */
  136. virtual void getText(UnicodeString& result);
  137. /**
  138. * Return a class ID for this object (not really public)
  139. * @return a class ID for this object.
  140. * @stable ICU 2.0
  141. */
  142. virtual UClassID getDynamicClassID(void) const;
  143. /**
  144. * Return a class ID for this class (not really public)
  145. * @return a class ID for this class
  146. * @stable ICU 2.0
  147. */
  148. static UClassID U_EXPORT2 getStaticClassID(void);
  149. protected:
  150. /**
  151. * Default constructor, iteration over empty string.
  152. * @stable ICU 2.0
  153. */
  154. StringCharacterIterator();
  155. /**
  156. * Sets the iterator to iterate over the provided string.
  157. * @param newText The string to be iterated over
  158. * @param newTextLength The length of the String
  159. * @stable ICU 2.0
  160. */
  161. void setText(const UChar* newText, int32_t newTextLength);
  162. /**
  163. * Copy of the iterated string object.
  164. * @stable ICU 2.0
  165. */
  166. UnicodeString text;
  167. };
  168. U_NAMESPACE_END
  169. #endif