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