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"
23 #if U_SHOW_CPLUSPLUS_API
25 #include "unicode/uobject.h"
32 * \brief C++ API: Canonical Iterator
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.
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.
45 * The ParsePosition class is not suitable for subclassing.
47 * @version 1.3 10/30/97
48 * @author Mark Davis, Helena Shih
49 * @see java.text.Format
52 class U_COMMON_API ParsePosition
: public UObject
{
55 * Default constructor, the index starts with 0 as default.
65 * Create a new ParsePosition with the given initial index.
66 * @param newIndex the new text offset.
69 ParsePosition(int32_t newIndex
)
77 * @param copy the object to be copied from.
80 ParsePosition(const ParsePosition
& copy
)
83 errorIndex(copy
.errorIndex
)
90 virtual ~ParsePosition();
96 inline ParsePosition
& operator=(const ParsePosition
& copy
);
100 * @return TRUE if the two parse positions are equal, FALSE otherwise.
103 inline UBool
operator==(const ParsePosition
& that
) const;
107 * @return TRUE if the two parse positions are not equal, FALSE otherwise.
110 inline UBool
operator!=(const ParsePosition
& that
) const;
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.
118 * @return a clone of this object
120 * @see getDynamicClassID
123 ParsePosition
*clone() const;
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.
132 inline int32_t getIndex(void) const;
135 * Set the current parse position.
136 * @param index the new index.
139 inline void setIndex(int32_t index
);
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
148 inline void setErrorIndex(int32_t ei
);
151 * Retrieve the index at which an error occurred, or -1 if the
152 * error index has not been set.
155 inline int32_t getErrorIndex(void) const;
158 * ICU "poor man's RTTI", returns a UClassID for this class.
162 static UClassID U_EXPORT2
getStaticClassID();
165 * ICU "poor man's RTTI", returns a UClassID for the actual class.
169 virtual UClassID
getDynamicClassID() const;
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.
181 * The index at which a parse error occurred.
187 inline ParsePosition
&
188 ParsePosition::operator=(const ParsePosition
& copy
)
191 errorIndex
= copy
.errorIndex
;
196 ParsePosition::operator==(const ParsePosition
& copy
) const
198 if(index
!= copy
.index
|| errorIndex
!= copy
.errorIndex
)
205 ParsePosition::operator!=(const ParsePosition
& copy
) const
207 return !operator==(copy
);
211 ParsePosition::getIndex() const
217 ParsePosition::setIndex(int32_t offset
)
219 this->index
= offset
;
223 ParsePosition::getErrorIndex() const
229 ParsePosition::setErrorIndex(int32_t ei
)
231 this->errorIndex
= ei
;
235 #endif /* U_SHOW_CPLUSPLUS_API */