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