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