schriter.h 6.1 KB

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