1 // Copyright (C) 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"
29 * \brief C++ API: Canonical Iterator
32 * <code>ParsePosition</code> is a simple class used by <code>Format</code>
33 * and its subclasses to keep track of the current position during parsing.
34 * The <code>parseObject</code> method in the various <code>Format</code>
35 * classes requires a <code>ParsePosition</code> object as an argument.
38 * By design, as you parse through a string with different formats,
39 * you can use the same <code>ParsePosition</code>, since the index parameter
40 * records the current position.
42 * The ParsePosition class is not suitable for subclassing.
44 * @version 1.3 10/30/97
45 * @author Mark Davis, Helena Shih
46 * @see java.text.Format
49 class U_COMMON_API ParsePosition : public UObject {
52 * Default constructor, the index starts with 0 as default.
62 * Create a new ParsePosition with the given initial index.
63 * @param newIndex the new text offset.
66 ParsePosition(int32_t newIndex)
74 * @param copy the object to be copied from.
77 ParsePosition(const ParsePosition& copy)
80 errorIndex(copy.errorIndex)
87 virtual ~ParsePosition();
93 ParsePosition& operator=(const ParsePosition& copy);
97 * @return TRUE if the two parse positions are equal, FALSE otherwise.
100 UBool operator==(const ParsePosition& that) const;
104 * @return TRUE if the two parse positions are not equal, FALSE otherwise.
107 UBool operator!=(const ParsePosition& that) const;
111 * Clones can be used concurrently in multiple threads.
112 * If an error occurs, then NULL is returned.
113 * The caller must delete the clone.
115 * @return a clone of this object
117 * @see getDynamicClassID
120 ParsePosition *clone() const;
123 * Retrieve the current parse position. On input to a parse method, this
124 * is the index of the character at which parsing will begin; on output, it
125 * is the index of the character following the last character parsed.
126 * @return the current index.
129 int32_t getIndex(void) const;
132 * Set the current parse position.
133 * @param index the new index.
136 void setIndex(int32_t index);
139 * Set the index at which a parse error occurred. Formatters
140 * should set this before returning an error code from their
141 * parseObject method. The default value is -1 if this is not
145 void setErrorIndex(int32_t ei);
148 * Retrieve the index at which an error occurred, or -1 if the
149 * error index has not been set.
152 int32_t getErrorIndex(void) const;
155 * ICU "poor man's RTTI", returns a UClassID for this class.
159 static UClassID U_EXPORT2 getStaticClassID();
162 * ICU "poor man's RTTI", returns a UClassID for the actual class.
166 virtual UClassID getDynamicClassID() const;
170 * Input: the place you start parsing.
171 * <br>Output: position where the parse stopped.
172 * This is designed to be used serially,
173 * with each call setting index up for the next one.
178 * The index at which a parse error occurred.
184 inline ParsePosition&
185 ParsePosition::operator=(const ParsePosition& copy)
188 errorIndex = copy.errorIndex;
193 ParsePosition::operator==(const ParsePosition& copy) const
195 if(index != copy.index || errorIndex != copy.errorIndex)
202 ParsePosition::operator!=(const ParsePosition& copy) const
204 return !operator==(copy);
208 ParsePosition::getIndex() const
214 ParsePosition::setIndex(int32_t offset)
216 this->index = offset;
220 ParsePosition::getErrorIndex() const
226 ParsePosition::setErrorIndex(int32_t ei)
228 this->errorIndex = ei;