schriter.h 6.1 KB

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