2 * Copyright (C) 1997-2004, International Business Machines Corporation and others. All Rights Reserved.
3 *******************************************************************************
7 * Modification History:
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 *******************************************************************************
19 #include "unicode/utypes.h"
20 #include "unicode/uobject.h"
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.
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.
35 * The ParsePosition class is not suitable for subclassing.
37 * @version 1.3 10/30/97
38 * @author Mark Davis, Helena Shih
39 * @see java.text.Format
42 class U_COMMON_API ParsePosition
: public UObject
{
45 * Default constructor, the index starts with 0 as default.
55 * Create a new ParsePosition with the given initial index.
56 * @param newIndex the new text offset.
59 ParsePosition(int32_t newIndex
)
67 * @param copy the object to be copied from.
70 ParsePosition(const ParsePosition
& copy
)
73 errorIndex(copy
.errorIndex
)
80 virtual ~ParsePosition();
86 ParsePosition
& operator=(const ParsePosition
& copy
);
90 * @return TRUE if the two parse positions are equal, FALSE otherwise.
93 UBool
operator==(const ParsePosition
& that
) const;
97 * @return TRUE if the two parse positions are not equal, FALSE otherwise.
100 UBool
operator!=(const ParsePosition
& that
) const;
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.
108 * @return a clone of this object
110 * @see getDynamicClassID
113 ParsePosition
*clone() const;
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.
122 int32_t getIndex(void) const;
125 * Set the current parse position.
126 * @param index the new index.
129 void setIndex(int32_t index
);
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
138 void setErrorIndex(int32_t ei
);
141 * Retrieve the index at which an error occurred, or -1 if the
142 * error index has not been set.
145 int32_t getErrorIndex(void) const;
148 * ICU "poor man's RTTI", returns a UClassID for this class.
152 static UClassID U_EXPORT2
getStaticClassID();
155 * ICU "poor man's RTTI", returns a UClassID for the actual class.
159 virtual UClassID
getDynamicClassID() const;
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.
171 * The index at which a parse error occurred.
177 inline ParsePosition
&
178 ParsePosition::operator=(const ParsePosition
& copy
)
181 errorIndex
= copy
.errorIndex
;
186 ParsePosition::operator==(const ParsePosition
& copy
) const
188 if(index
!= copy
.index
|| errorIndex
!= copy
.errorIndex
)
195 ParsePosition::operator!=(const ParsePosition
& copy
) const
197 return !operator==(copy
);
201 ParsePosition::getIndex() const
207 ParsePosition::setIndex(int32_t offset
)
209 this->index
= offset
;
213 ParsePosition::getErrorIndex() const
219 ParsePosition::setErrorIndex(int32_t ei
)
221 this->errorIndex
= ei
;