1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ******************************************************************************
6 * Copyright (C) 1998-2005, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 ******************************************************************************
13 * Modification History:
15 * Date Name Description
16 * 05/05/99 stephen Cleaned up.
17 ******************************************************************************
23 #include "unicode/utypes.h"
25 #if U_SHOW_CPLUSPLUS_API
27 #include "unicode/chariter.h"
28 #include "unicode/uchriter.h"
32 * \brief C++ API: String Character Iterator
37 * A concrete subclass of CharacterIterator that iterates over the
38 * characters (code units or code points) in a UnicodeString.
39 * It's possible not only to create an
40 * iterator that iterates over an entire UnicodeString, but also to
41 * create one that iterates over only a subrange of a UnicodeString
42 * (iterators over different subranges of the same UnicodeString don't
44 * @see CharacterIterator
45 * @see ForwardCharacterIterator
48 class U_COMMON_API StringCharacterIterator
: public UCharCharacterIterator
{
51 * Create an iterator over the UnicodeString referred to by "textStr".
52 * The UnicodeString object is copied.
53 * The iteration range is the whole string, and the starting position is 0.
54 * @param textStr The unicode string used to create an iterator
57 StringCharacterIterator(const UnicodeString
& textStr
);
60 * Create an iterator over the UnicodeString referred to by "textStr".
61 * The iteration range is the whole string, and the starting
62 * position is specified by "textPos". If "textPos" is outside the valid
63 * iteration range, the behavior of this object is undefined.
64 * @param textStr The unicode string used to create an iterator
65 * @param textPos The starting position of the iteration
68 StringCharacterIterator(const UnicodeString
& textStr
,
72 * Create an iterator over the UnicodeString referred to by "textStr".
73 * The UnicodeString object is copied.
74 * The iteration range begins with the code unit specified by
75 * "textBegin" and ends with the code unit BEFORE the code unit specified
76 * by "textEnd". The starting position is specified by "textPos". If
77 * "textBegin" and "textEnd" don't form a valid range on "text" (i.e.,
78 * textBegin >= textEnd or either is negative or greater than text.size()),
79 * or "textPos" is outside the range defined by "textBegin" and "textEnd",
80 * the behavior of this iterator is undefined.
81 * @param textStr The unicode string used to create the StringCharacterIterator
82 * @param textBegin The begin position of the iteration range
83 * @param textEnd The end position of the iteration range
84 * @param textPos The starting position of the iteration
87 StringCharacterIterator(const UnicodeString
& textStr
,
93 * Copy constructor. The new iterator iterates over the same range
94 * of the same string as "that", and its initial position is the
95 * same as "that"'s current position.
96 * The UnicodeString object in "that" is copied.
97 * @param that The StringCharacterIterator to be copied
100 StringCharacterIterator(const StringCharacterIterator
& that
);
106 virtual ~StringCharacterIterator();
109 * Assignment operator. *this is altered to iterate over the same
110 * range of the same string as "that", and refers to the same
111 * character within that string as "that" does.
112 * @param that The object to be copied.
113 * @return the newly created object.
116 StringCharacterIterator
&
117 operator=(const StringCharacterIterator
& that
);
120 * Returns true if the iterators iterate over the same range of the
121 * same string and are pointing at the same character.
122 * @param that The ForwardCharacterIterator to be compared for equality
123 * @return true if the iterators iterate over the same range of the
124 * same string and are pointing at the same character.
127 virtual UBool
operator==(const ForwardCharacterIterator
& that
) const;
130 * Returns a new StringCharacterIterator referring to the same
131 * character in the same range of the same string as this one. The
132 * caller must delete the new iterator.
133 * @return the newly cloned object.
136 virtual StringCharacterIterator
* clone() const;
139 * Sets the iterator to iterate over the provided string.
140 * @param newText The string to be iterated over
143 void setText(const UnicodeString
& newText
);
146 * Copies the UnicodeString under iteration into the UnicodeString
147 * referred to by "result". Even if this iterator iterates across
148 * only a part of this string, the whole string is copied.
149 * @param result Receives a copy of the text under iteration.
152 virtual void getText(UnicodeString
& result
);
155 * Return a class ID for this object (not really public)
156 * @return a class ID for this object.
159 virtual UClassID
getDynamicClassID(void) const;
162 * Return a class ID for this class (not really public)
163 * @return a class ID for this class
166 static UClassID U_EXPORT2
getStaticClassID(void);
170 * Default constructor, iteration over empty string.
173 StringCharacterIterator();
176 * Sets the iterator to iterate over the provided string.
177 * @param newText The string to be iterated over
178 * @param newTextLength The length of the String
181 void setText(const char16_t* newText
, int32_t newTextLength
);
184 * Copy of the iterated string object.
193 #endif /* U_SHOW_CPLUSPLUS_API */