os/textandloc/fontservices/textshaperplugin/IcuSource/common/unicode/parsepos.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (C) 1997-2005, International Business Machines Corporation and others. All Rights Reserved.
sl@0
     3
*******************************************************************************
sl@0
     4
*
sl@0
     5
* File PARSEPOS.H
sl@0
     6
*
sl@0
     7
* Modification History:
sl@0
     8
*
sl@0
     9
*   Date        Name        Description
sl@0
    10
*   07/09/97    helena      Converted from java.
sl@0
    11
*   07/17/98    stephen     Added errorIndex support.
sl@0
    12
*   05/11/99    stephen     Cleaned up.
sl@0
    13
*******************************************************************************
sl@0
    14
*/
sl@0
    15
sl@0
    16
#ifndef PARSEPOS_H
sl@0
    17
#define PARSEPOS_H
sl@0
    18
sl@0
    19
#include "unicode/utypes.h"
sl@0
    20
#include "unicode/uobject.h"
sl@0
    21
sl@0
    22
 
sl@0
    23
U_NAMESPACE_BEGIN
sl@0
    24
sl@0
    25
/**
sl@0
    26
 * \file
sl@0
    27
 * \brief C++ API: Canonical Iterator
sl@0
    28
 */
sl@0
    29
/** 
sl@0
    30
 * <code>ParsePosition</code> is a simple class used by <code>Format</code>
sl@0
    31
 * and its subclasses to keep track of the current position during parsing.
sl@0
    32
 * The <code>parseObject</code> method in the various <code>Format</code>
sl@0
    33
 * classes requires a <code>ParsePosition</code> object as an argument.
sl@0
    34
 *
sl@0
    35
 * <p>
sl@0
    36
 * By design, as you parse through a string with different formats,
sl@0
    37
 * you can use the same <code>ParsePosition</code>, since the index parameter
sl@0
    38
 * records the current position.
sl@0
    39
 *
sl@0
    40
 * The ParsePosition class is not suitable for subclassing.
sl@0
    41
 *
sl@0
    42
 * @version     1.3 10/30/97
sl@0
    43
 * @author      Mark Davis, Helena Shih
sl@0
    44
 * @see         java.text.Format
sl@0
    45
 */
sl@0
    46
sl@0
    47
class U_COMMON_API ParsePosition : public UObject {
sl@0
    48
public:
sl@0
    49
    /**
sl@0
    50
     * Default constructor, the index starts with 0 as default.
sl@0
    51
     * @stable ICU 2.0
sl@0
    52
     */
sl@0
    53
    ParsePosition()
sl@0
    54
        : UObject(),
sl@0
    55
        index(0),
sl@0
    56
        errorIndex(-1)
sl@0
    57
      {}
sl@0
    58
sl@0
    59
    /**
sl@0
    60
     * Create a new ParsePosition with the given initial index.
sl@0
    61
     * @param newIndex the new text offset.
sl@0
    62
     * @stable ICU 2.0
sl@0
    63
     */
sl@0
    64
    ParsePosition(int32_t newIndex)
sl@0
    65
        : UObject(),
sl@0
    66
        index(newIndex),
sl@0
    67
        errorIndex(-1)
sl@0
    68
      {}
sl@0
    69
sl@0
    70
    /**
sl@0
    71
     * Copy constructor
sl@0
    72
     * @param copy the object to be copied from.
sl@0
    73
     * @stable ICU 2.0
sl@0
    74
     */
sl@0
    75
    ParsePosition(const ParsePosition& copy)
sl@0
    76
        : UObject(copy),
sl@0
    77
        index(copy.index),
sl@0
    78
        errorIndex(copy.errorIndex)
sl@0
    79
      {}
sl@0
    80
sl@0
    81
    /**
sl@0
    82
     * Destructor
sl@0
    83
     * @stable ICU 2.0
sl@0
    84
     */
sl@0
    85
    virtual ~ParsePosition();
sl@0
    86
sl@0
    87
    /**
sl@0
    88
     * Assignment operator
sl@0
    89
     * @stable ICU 2.0
sl@0
    90
     */
sl@0
    91
    ParsePosition&      operator=(const ParsePosition& copy);
sl@0
    92
sl@0
    93
    /**
sl@0
    94
     * Equality operator.
sl@0
    95
     * @return TRUE if the two parse positions are equal, FALSE otherwise.
sl@0
    96
     * @stable ICU 2.0
sl@0
    97
     */
sl@0
    98
    UBool              operator==(const ParsePosition& that) const;
sl@0
    99
sl@0
   100
    /**
sl@0
   101
     * Equality operator.
sl@0
   102
     * @return TRUE if the two parse positions are not equal, FALSE otherwise.
sl@0
   103
     * @stable ICU 2.0
sl@0
   104
     */
sl@0
   105
    UBool              operator!=(const ParsePosition& that) const;
sl@0
   106
sl@0
   107
    /**
sl@0
   108
     * Clone this object.
sl@0
   109
     * Clones can be used concurrently in multiple threads.
sl@0
   110
     * If an error occurs, then NULL is returned.
sl@0
   111
     * The caller must delete the clone.
sl@0
   112
     *
sl@0
   113
     * @return a clone of this object
sl@0
   114
     *
sl@0
   115
     * @see getDynamicClassID
sl@0
   116
     * @stable ICU 2.8
sl@0
   117
     */
sl@0
   118
    ParsePosition *clone() const;
sl@0
   119
sl@0
   120
    /**
sl@0
   121
     * Retrieve the current parse position.  On input to a parse method, this
sl@0
   122
     * is the index of the character at which parsing will begin; on output, it
sl@0
   123
     * is the index of the character following the last character parsed.
sl@0
   124
     * @return the current index.
sl@0
   125
     * @stable ICU 2.0
sl@0
   126
     */
sl@0
   127
    int32_t getIndex(void) const;
sl@0
   128
sl@0
   129
    /**
sl@0
   130
     * Set the current parse position.
sl@0
   131
     * @param index the new index.
sl@0
   132
     * @stable ICU 2.0
sl@0
   133
     */
sl@0
   134
    void setIndex(int32_t index);
sl@0
   135
sl@0
   136
    /**
sl@0
   137
     * Set the index at which a parse error occurred.  Formatters
sl@0
   138
     * should set this before returning an error code from their
sl@0
   139
     * parseObject method.  The default value is -1 if this is not
sl@0
   140
     * set.
sl@0
   141
     * @stable ICU 2.0
sl@0
   142
     */
sl@0
   143
    void setErrorIndex(int32_t ei);
sl@0
   144
sl@0
   145
    /**
sl@0
   146
     * Retrieve the index at which an error occurred, or -1 if the
sl@0
   147
     * error index has not been set.
sl@0
   148
     * @stable ICU 2.0
sl@0
   149
     */
sl@0
   150
    int32_t getErrorIndex(void) const;
sl@0
   151
sl@0
   152
    /**
sl@0
   153
     * ICU "poor man's RTTI", returns a UClassID for this class.
sl@0
   154
     *
sl@0
   155
     * @stable ICU 2.2
sl@0
   156
     */
sl@0
   157
    static UClassID U_EXPORT2 getStaticClassID();
sl@0
   158
sl@0
   159
    /**
sl@0
   160
     * ICU "poor man's RTTI", returns a UClassID for the actual class.
sl@0
   161
     *
sl@0
   162
     * @stable ICU 2.2
sl@0
   163
     */
sl@0
   164
    virtual UClassID getDynamicClassID() const;
sl@0
   165
sl@0
   166
private:
sl@0
   167
    /**
sl@0
   168
     * Input: the place you start parsing.
sl@0
   169
     * <br>Output: position where the parse stopped.
sl@0
   170
     * This is designed to be used serially,
sl@0
   171
     * with each call setting index up for the next one.
sl@0
   172
     */
sl@0
   173
    int32_t index;
sl@0
   174
sl@0
   175
    /**
sl@0
   176
     * The index at which a parse error occurred.
sl@0
   177
     */
sl@0
   178
    int32_t errorIndex;
sl@0
   179
sl@0
   180
};
sl@0
   181
sl@0
   182
inline ParsePosition&
sl@0
   183
ParsePosition::operator=(const ParsePosition& copy)
sl@0
   184
{
sl@0
   185
  index = copy.index;
sl@0
   186
  errorIndex = copy.errorIndex;
sl@0
   187
  return *this;
sl@0
   188
}
sl@0
   189
sl@0
   190
inline UBool
sl@0
   191
ParsePosition::operator==(const ParsePosition& copy) const
sl@0
   192
{
sl@0
   193
  if(index != copy.index || errorIndex != copy.errorIndex)
sl@0
   194
  return FALSE;
sl@0
   195
  else
sl@0
   196
  return TRUE;
sl@0
   197
}
sl@0
   198
sl@0
   199
inline UBool
sl@0
   200
ParsePosition::operator!=(const ParsePosition& copy) const
sl@0
   201
{
sl@0
   202
  return !operator==(copy);
sl@0
   203
}
sl@0
   204
sl@0
   205
inline int32_t
sl@0
   206
ParsePosition::getIndex() const
sl@0
   207
{
sl@0
   208
  return index;
sl@0
   209
}
sl@0
   210
sl@0
   211
inline void
sl@0
   212
ParsePosition::setIndex(int32_t offset)
sl@0
   213
{
sl@0
   214
  this->index = offset;
sl@0
   215
}
sl@0
   216
sl@0
   217
inline int32_t
sl@0
   218
ParsePosition::getErrorIndex() const
sl@0
   219
{
sl@0
   220
  return errorIndex;
sl@0
   221
}
sl@0
   222
sl@0
   223
inline void
sl@0
   224
ParsePosition::setErrorIndex(int32_t ei)
sl@0
   225
{
sl@0
   226
  this->errorIndex = ei;
sl@0
   227
}
sl@0
   228
U_NAMESPACE_END
sl@0
   229
sl@0
   230
#endif