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