~ubuntu-branches/ubuntu/gutsy/icu/gutsy-updates

« back to all changes in this revision

Viewing changes to source/i18n/unicode/parsepos.h

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2005-11-19 11:29:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20051119112931-vcizkrp10tli4enw
Tags: 3.4-3
Explicitly build with g++ 3.4.  The current ICU fails its test suite
with 4.0 but not with 3.4.  Future versions should work properly with
4.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
* Copyright (C) {1997-1999}, International Business Machines Corporation and others. All Rights Reserved.
3
 
*******************************************************************************
4
 
*
5
 
* File PARSEPOS.H
6
 
*
7
 
* Modification History:
8
 
*
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
 
*******************************************************************************
14
 
*/
15
 
 
16
 
#ifndef PARSEPOS_H
17
 
#define PARSEPOS_H
18
 
 
19
 
#include "unicode/utypes.h"
20
 
 
21
 
U_NAMESPACE_BEGIN
22
 
 
23
 
/**
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.
28
 
 *
29
 
 * <p>
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.
33
 
 *
34
 
 * @version     1.3 10/30/97
35
 
 * @author      Mark Davis, Helena Shih
36
 
 * @see         java.text.Format
37
 
 */
38
 
 
39
 
class U_I18N_API ParsePosition {
40
 
public:
41
 
    /**
42
 
     * Default constructor, the index starts with 0 as default.
43
 
     * @stable
44
 
     */
45
 
    ParsePosition()
46
 
      { this->index = 0; this->errorIndex = -1; }
47
 
 
48
 
    /**
49
 
     * Create a new ParsePosition with the given initial index.
50
 
     * @param newIndex the new text offset.
51
 
     * @stable
52
 
     */
53
 
    ParsePosition(int32_t newIndex)
54
 
      {    this->index = newIndex; this->errorIndex = -1; }
55
 
 
56
 
    /**
57
 
     * Copy constructor
58
 
     * @param copy the object to be copied from.
59
 
     * @stable
60
 
     */
61
 
    ParsePosition(const ParsePosition& copy)
62
 
      {    this->index = copy.index; this->errorIndex = copy.errorIndex; }
63
 
 
64
 
    /**
65
 
     * Destructor
66
 
     * @stable
67
 
     */
68
 
    ~ParsePosition() {}
69
 
 
70
 
    /**
71
 
     * Assignment operator
72
 
     * @stable
73
 
     */
74
 
    ParsePosition&      operator=(const ParsePosition& copy);
75
 
 
76
 
    /**
77
 
     * Equality operator.
78
 
     * @return TRUE if the two parse positions are equal, FALSE otherwise.
79
 
     * @stable
80
 
     */
81
 
    UBool              operator==(const ParsePosition& that) const;
82
 
 
83
 
    /**
84
 
     * Equality operator.
85
 
     * @return TRUE if the two parse positions are not equal, FALSE otherwise.
86
 
     * @stable
87
 
     */
88
 
    UBool              operator!=(const ParsePosition& that) const;
89
 
 
90
 
    /**
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.
95
 
     * @stable
96
 
     */
97
 
    int32_t getIndex(void) const;
98
 
 
99
 
    /**
100
 
     * Set the current parse position.
101
 
     * @param index the new index.
102
 
     * @stable
103
 
     */
104
 
    void setIndex(int32_t index);
105
 
 
106
 
    /**
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
110
 
     * set.
111
 
     * @stable
112
 
     */
113
 
    void setErrorIndex(int32_t ei);
114
 
 
115
 
    /**
116
 
     * Retrieve the index at which an error occurred, or -1 if the
117
 
     * error index has not been set.
118
 
     * @stable
119
 
     */
120
 
    int32_t getErrorIndex(void) const;
121
 
 
122
 
private:
123
 
    /**
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.
128
 
     */
129
 
    int32_t index;
130
 
 
131
 
    /**
132
 
     * The index at which a parse error occurred.
133
 
     */
134
 
    int32_t errorIndex;
135
 
};
136
 
 
137
 
inline ParsePosition&
138
 
ParsePosition::operator=(const ParsePosition& copy)
139
 
{
140
 
  index = copy.index;
141
 
  errorIndex = copy.errorIndex;
142
 
  return *this;
143
 
}
144
 
 
145
 
inline UBool
146
 
ParsePosition::operator==(const ParsePosition& copy) const
147
 
{
148
 
  if(index != copy.index || errorIndex != copy.errorIndex)
149
 
  return FALSE;
150
 
  else
151
 
  return TRUE;
152
 
}
153
 
 
154
 
inline UBool
155
 
ParsePosition::operator!=(const ParsePosition& copy) const
156
 
{
157
 
  return !operator==(copy);
158
 
}
159
 
 
160
 
inline int32_t
161
 
ParsePosition::getIndex() const
162
 
{
163
 
  return index;
164
 
}
165
 
 
166
 
inline void
167
 
ParsePosition::setIndex(int32_t offset)
168
 
{
169
 
  this->index = offset;
170
 
}
171
 
 
172
 
inline int32_t
173
 
ParsePosition::getErrorIndex() const
174
 
{
175
 
  return errorIndex;
176
 
}
177
 
 
178
 
inline void
179
 
ParsePosition::setErrorIndex(int32_t ei)
180
 
{
181
 
  this->errorIndex = ei;
182
 
}
183
 
U_NAMESPACE_END
184
 
 
185
 
#endif