1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 * Copyright (C) 1997-2005, International Business Machines Corporation and others. All Rights Reserved.
5 *******************************************************************************
9 * Modification History:
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 *******************************************************************************
21 #include "unicode/utypes.h"
22 #include "unicode/uobject.h"
25 #if U_SHOW_CPLUSPLUS_API
30 * \brief C++ API: Canonical Iterator
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.
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.
43 * The ParsePosition class is not suitable for subclassing.
45 * @version 1.3 10/30/97
46 * @author Mark Davis, Helena Shih
47 * @see java.text.Format
50 class U_COMMON_API ParsePosition
: public UObject
{
53 * Default constructor, the index starts with 0 as default.
63 * Create a new ParsePosition with the given initial index.
64 * @param newIndex the new text offset.
67 ParsePosition(int32_t newIndex
)
75 * @param copy the object to be copied from.
78 ParsePosition(const ParsePosition
& copy
)
81 errorIndex(copy
.errorIndex
)
88 virtual ~ParsePosition();
94 inline ParsePosition
& operator=(const ParsePosition
& copy
);
98 * @return TRUE if the two parse positions are equal, FALSE otherwise.
101 inline UBool
operator==(const ParsePosition
& that
) const;
105 * @return TRUE if the two parse positions are not equal, FALSE otherwise.
108 inline UBool
operator!=(const ParsePosition
& that
) const;
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.
116 * @return a clone of this object
118 * @see getDynamicClassID
121 ParsePosition
*clone() const;
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.
130 inline int32_t getIndex(void) const;
133 * Set the current parse position.
134 * @param index the new index.
137 inline void setIndex(int32_t index
);
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
146 inline void setErrorIndex(int32_t ei
);
149 * Retrieve the index at which an error occurred, or -1 if the
150 * error index has not been set.
153 inline int32_t getErrorIndex(void) const;
156 * ICU "poor man's RTTI", returns a UClassID for this class.
160 static UClassID U_EXPORT2
getStaticClassID();
163 * ICU "poor man's RTTI", returns a UClassID for the actual class.
167 virtual UClassID
getDynamicClassID() const;
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.
179 * The index at which a parse error occurred.
185 inline ParsePosition
&
186 ParsePosition::operator=(const ParsePosition
& copy
)
189 errorIndex
= copy
.errorIndex
;
194 ParsePosition::operator==(const ParsePosition
& copy
) const
196 if(index
!= copy
.index
|| errorIndex
!= copy
.errorIndex
)
203 ParsePosition::operator!=(const ParsePosition
& copy
) const
205 return !operator==(copy
);
209 ParsePosition::getIndex() const
215 ParsePosition::setIndex(int32_t offset
)
217 this->index
= offset
;
221 ParsePosition::getErrorIndex() const
227 ParsePosition::setErrorIndex(int32_t ei
)
229 this->errorIndex
= ei
;
232 #endif // U_SHOW_CPLUSPLUS_API