2
* Copyright (C) {1997-1999}, 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"
24
* <code>ParsePosition</code> is a simple class used by <code>Format</code>
25
* and its subclasses to keep track of the current position during parsing.
26
* The <code>parseObject</code> method in the various <code>Format</code>
27
* classes requires a <code>ParsePosition</code> object as an argument.
30
* By design, as you parse through a string with different formats,
31
* you can use the same <code>ParsePosition</code>, since the index parameter
32
* records the current position.
34
* @version 1.3 10/30/97
35
* @author Mark Davis, Helena Shih
36
* @see java.text.Format
39
class U_I18N_API ParsePosition {
42
* Default constructor, the index starts with 0 as default.
46
{ this->index = 0; this->errorIndex = -1; }
49
* Create a new ParsePosition with the given initial index.
50
* @param newIndex the new text offset.
53
ParsePosition(int32_t newIndex)
54
{ this->index = newIndex; this->errorIndex = -1; }
58
* @param copy the object to be copied from.
61
ParsePosition(const ParsePosition& copy)
62
{ this->index = copy.index; this->errorIndex = copy.errorIndex; }
74
ParsePosition& operator=(const ParsePosition& copy);
78
* @return TRUE if the two parse positions are equal, FALSE otherwise.
81
UBool operator==(const ParsePosition& that) const;
85
* @return TRUE if the two parse positions are not equal, FALSE otherwise.
88
UBool operator!=(const ParsePosition& that) const;
91
* Retrieve the current parse position. On input to a parse method, this
92
* is the index of the character at which parsing will begin; on output, it
93
* is the index of the character following the last character parsed.
94
* @return the current index.
97
int32_t getIndex(void) const;
100
* Set the current parse position.
101
* @param index the new index.
104
void setIndex(int32_t index);
107
* Set the index at which a parse error occurred. Formatters
108
* should set this before returning an error code from their
109
* parseObject method. The default value is -1 if this is not
113
void setErrorIndex(int32_t ei);
116
* Retrieve the index at which an error occurred, or -1 if the
117
* error index has not been set.
120
int32_t getErrorIndex(void) const;
124
* Input: the place you start parsing.
125
* <br>Output: position where the parse stopped.
126
* This is designed to be used serially,
127
* with each call setting index up for the next one.
132
* The index at which a parse error occurred.
137
inline ParsePosition&
138
ParsePosition::operator=(const ParsePosition& copy)
141
errorIndex = copy.errorIndex;
146
ParsePosition::operator==(const ParsePosition& copy) const
148
if(index != copy.index || errorIndex != copy.errorIndex)
155
ParsePosition::operator!=(const ParsePosition& copy) const
157
return !operator==(copy);
161
ParsePosition::getIndex() const
167
ParsePosition::setIndex(int32_t offset)
169
this->index = offset;
173
ParsePosition::getErrorIndex() const
179
ParsePosition::setErrorIndex(int32_t ei)
181
this->errorIndex = ei;