2 ******************************************************************************
4 * Copyright (C) 1998-2003, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 ******************************************************************************
11 * Modification History:
13 * Date Name Description
14 * 05/05/99 stephen Cleaned up.
15 ******************************************************************************
21 #include "unicode/utypes.h"
22 #include "unicode/chariter.h"
23 #include "unicode/uchriter.h"
27 * A concrete subclass of CharacterIterator that iterates over the
28 * characters (code units or code points) in a UnicodeString.
29 * It's possible not only to create an
30 * iterator that iterates over an entire UnicodeString, but also to
31 * create one that iterates over only a subrange of a UnicodeString
32 * (iterators over different subranges of the same UnicodeString don't
34 * @see CharacterIterator
35 * @see ForwardCharacterIterator
38 class U_COMMON_API StringCharacterIterator
: public UCharCharacterIterator
{
41 * Create an iterator over the UnicodeString referred to by "textStr".
42 * The UnicodeString object is copied.
43 * The iteration range is the whole string, and the starting position is 0.
44 * @param textStr The unicode string used to create an iterator
47 StringCharacterIterator(const UnicodeString
& textStr
);
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 * @textStr The unicode string used to create an iterator
55 * @textPos The starting position of the iteration
58 StringCharacterIterator(const UnicodeString
& textStr
,
62 * Create an iterator over the UnicodeString referred to by "textStr".
63 * The UnicodeString object is copied.
64 * The iteration range begins with the code unit specified by
65 * "textBegin" and ends with the code unit BEFORE the code unit specfied
66 * by "textEnd". The starting position is specified by "textPos". If
67 * "textBegin" and "textEnd" don't form a valid range on "text" (i.e.,
68 * textBegin >= textEnd or either is negative or greater than text.size()),
69 * or "textPos" is outside the range defined by "textBegin" and "textEnd",
70 * the behavior of this iterator is undefined.
71 * @param textStr The unicode string used to create the StringCharacterIterator
72 * @param textBegin The begin position of the iteration range
73 * @param textEnd The end position of the iteration range
74 * @param textPos The starting position of the iteration
77 StringCharacterIterator(const UnicodeString
& textStr
,
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
90 StringCharacterIterator(const StringCharacterIterator
& that
);
96 virtual ~StringCharacterIterator();
99 * Assignment operator. *this is altered to iterate over the same
100 * range of the same string as "that", and refers to the same
101 * character within that string as "that" does.
102 * @param that The object to be copied.
103 * @return the newly created object.
106 StringCharacterIterator
&
107 operator=(const StringCharacterIterator
& that
);
110 * Returns true if the iterators iterate over the same range of the
111 * same string and are pointing at the same character.
112 * @param that The ForwardCharacterIterator to be compared for equality
113 * @return true if the iterators iterate over the same range of the
114 * same string and are pointing at the same character.
117 virtual UBool
operator==(const ForwardCharacterIterator
& that
) const;
120 * Returns a new StringCharacterIterator referring to the same
121 * character in the same range of the same string as this one. The
122 * caller must delete the new iterator.
123 * @return the newly cloned object.
126 virtual CharacterIterator
* clone(void) const;
129 * Sets the iterator to iterate over the provided string.
130 * @param newText The string to be iterated over
133 void setText(const UnicodeString
& newText
);
136 * Copies the UnicodeString under iteration into the UnicodeString
137 * referred to by "result". Even if this iterator iterates across
138 * only a part of this string, the whole string is copied.
139 * @param result Receives a copy of the text under iteration.
142 virtual void getText(UnicodeString
& result
);
145 * Return a class ID for this object (not really public)
146 * @return a class ID for this object.
149 virtual UClassID
getDynamicClassID(void) const;
152 * Return a class ID for this class (not really public)
153 * @return a class ID for this class
156 static inline UClassID
getStaticClassID(void);
160 * Default constructor, iteration over empty string.
163 StringCharacterIterator();
166 * Sets the iterator to iterate over the provided string.
167 * @param newText The string to be iterated over
168 * @param newTextLength The length of the String
171 void setText(const UChar
* newText
, int32_t newTextLength
);
174 * Copy of the iterated string object.
180 static const char fgClassID
;
184 StringCharacterIterator::getStaticClassID(void)
185 { return (UClassID
)(&fgClassID
); }
188 StringCharacterIterator::getDynamicClassID(void) const
189 { return StringCharacterIterator::getStaticClassID(); }