]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/unicode/parsepos.h
ICU-62141.0.1.tar.gz
[apple/icu.git] / icuSources / common / unicode / parsepos.h
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
b75a7d8f 3/*
73c04bcf 4* Copyright (C) 1997-2005, International Business Machines Corporation and others. All Rights Reserved.
b75a7d8f
A
5*******************************************************************************
6*
7* File PARSEPOS.H
8*
9* Modification History:
10*
11* Date Name Description
12* 07/09/97 helena Converted from java.
13* 07/17/98 stephen Added errorIndex support.
14* 05/11/99 stephen Cleaned up.
15*******************************************************************************
16*/
17
18#ifndef PARSEPOS_H
19#define PARSEPOS_H
20
21#include "unicode/utypes.h"
22#include "unicode/uobject.h"
23
73c04bcf 24
f3c0d7a5 25#if U_SHOW_CPLUSPLUS_API
b75a7d8f
A
26U_NAMESPACE_BEGIN
27
28/**
73c04bcf
A
29 * \file
30 * \brief C++ API: Canonical Iterator
31 */
32/**
b75a7d8f
A
33 * <code>ParsePosition</code> is a simple class used by <code>Format</code>
34 * and its subclasses to keep track of the current position during parsing.
35 * The <code>parseObject</code> method in the various <code>Format</code>
36 * classes requires a <code>ParsePosition</code> object as an argument.
37 *
38 * <p>
39 * By design, as you parse through a string with different formats,
40 * you can use the same <code>ParsePosition</code>, since the index parameter
41 * records the current position.
42 *
43 * The ParsePosition class is not suitable for subclassing.
44 *
45 * @version 1.3 10/30/97
46 * @author Mark Davis, Helena Shih
47 * @see java.text.Format
48 */
49
50class U_COMMON_API ParsePosition : public UObject {
51public:
52 /**
53 * Default constructor, the index starts with 0 as default.
54 * @stable ICU 2.0
55 */
56 ParsePosition()
374ca955
A
57 : UObject(),
58 index(0),
59 errorIndex(-1)
60 {}
b75a7d8f
A
61
62 /**
63 * Create a new ParsePosition with the given initial index.
64 * @param newIndex the new text offset.
65 * @stable ICU 2.0
66 */
67 ParsePosition(int32_t newIndex)
374ca955
A
68 : UObject(),
69 index(newIndex),
70 errorIndex(-1)
71 {}
b75a7d8f
A
72
73 /**
74 * Copy constructor
75 * @param copy the object to be copied from.
76 * @stable ICU 2.0
77 */
78 ParsePosition(const ParsePosition& copy)
374ca955
A
79 : UObject(copy),
80 index(copy.index),
81 errorIndex(copy.errorIndex)
82 {}
b75a7d8f
A
83
84 /**
85 * Destructor
86 * @stable ICU 2.0
87 */
374ca955 88 virtual ~ParsePosition();
b75a7d8f
A
89
90 /**
91 * Assignment operator
92 * @stable ICU 2.0
93 */
94 ParsePosition& operator=(const ParsePosition& copy);
95
96 /**
97 * Equality operator.
98 * @return TRUE if the two parse positions are equal, FALSE otherwise.
99 * @stable ICU 2.0
100 */
101 UBool operator==(const ParsePosition& that) const;
102
103 /**
104 * Equality operator.
105 * @return TRUE if the two parse positions are not equal, FALSE otherwise.
106 * @stable ICU 2.0
107 */
108 UBool operator!=(const ParsePosition& that) const;
109
374ca955
A
110 /**
111 * Clone this object.
112 * Clones can be used concurrently in multiple threads.
113 * If an error occurs, then NULL is returned.
114 * The caller must delete the clone.
115 *
116 * @return a clone of this object
117 *
118 * @see getDynamicClassID
73c04bcf 119 * @stable ICU 2.8
374ca955
A
120 */
121 ParsePosition *clone() const;
122
b75a7d8f
A
123 /**
124 * Retrieve the current parse position. On input to a parse method, this
125 * is the index of the character at which parsing will begin; on output, it
126 * is the index of the character following the last character parsed.
127 * @return the current index.
128 * @stable ICU 2.0
129 */
130 int32_t getIndex(void) const;
131
132 /**
133 * Set the current parse position.
134 * @param index the new index.
135 * @stable ICU 2.0
136 */
137 void setIndex(int32_t index);
138
139 /**
140 * Set the index at which a parse error occurred. Formatters
141 * should set this before returning an error code from their
142 * parseObject method. The default value is -1 if this is not
143 * set.
144 * @stable ICU 2.0
145 */
146 void setErrorIndex(int32_t ei);
147
148 /**
149 * Retrieve the index at which an error occurred, or -1 if the
150 * error index has not been set.
151 * @stable ICU 2.0
152 */
153 int32_t getErrorIndex(void) const;
154
155 /**
374ca955 156 * ICU "poor man's RTTI", returns a UClassID for this class.
b75a7d8f 157 *
374ca955 158 * @stable ICU 2.2
b75a7d8f 159 */
374ca955 160 static UClassID U_EXPORT2 getStaticClassID();
b75a7d8f
A
161
162 /**
374ca955 163 * ICU "poor man's RTTI", returns a UClassID for the actual class.
b75a7d8f 164 *
374ca955 165 * @stable ICU 2.2
b75a7d8f 166 */
374ca955 167 virtual UClassID getDynamicClassID() const;
b75a7d8f
A
168
169private:
170 /**
171 * Input: the place you start parsing.
172 * <br>Output: position where the parse stopped.
173 * This is designed to be used serially,
174 * with each call setting index up for the next one.
175 */
176 int32_t index;
177
178 /**
179 * The index at which a parse error occurred.
180 */
181 int32_t errorIndex;
182
b75a7d8f
A
183};
184
b75a7d8f
A
185inline ParsePosition&
186ParsePosition::operator=(const ParsePosition& copy)
187{
188 index = copy.index;
189 errorIndex = copy.errorIndex;
190 return *this;
191}
192
193inline UBool
194ParsePosition::operator==(const ParsePosition& copy) const
195{
196 if(index != copy.index || errorIndex != copy.errorIndex)
197 return FALSE;
198 else
199 return TRUE;
200}
201
202inline UBool
203ParsePosition::operator!=(const ParsePosition& copy) const
204{
205 return !operator==(copy);
206}
207
208inline int32_t
209ParsePosition::getIndex() const
210{
211 return index;
212}
213
214inline void
215ParsePosition::setIndex(int32_t offset)
216{
217 this->index = offset;
218}
219
220inline int32_t
221ParsePosition::getErrorIndex() const
222{
223 return errorIndex;
224}
225
226inline void
227ParsePosition::setErrorIndex(int32_t ei)
228{
229 this->errorIndex = ei;
230}
231U_NAMESPACE_END
f3c0d7a5 232#endif // U_SHOW_CPLUSPLUS_API
b75a7d8f
A
233
234#endif