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