intl/icu/source/common/unicode/parsepos.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/common/unicode/parsepos.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,230 @@
     1.4 +/*
     1.5 +* Copyright (C) 1997-2005, International Business Machines Corporation and others. All Rights Reserved.
     1.6 +*******************************************************************************
     1.7 +*
     1.8 +* File PARSEPOS.H
     1.9 +*
    1.10 +* Modification History:
    1.11 +*
    1.12 +*   Date        Name        Description
    1.13 +*   07/09/97    helena      Converted from java.
    1.14 +*   07/17/98    stephen     Added errorIndex support.
    1.15 +*   05/11/99    stephen     Cleaned up.
    1.16 +*******************************************************************************
    1.17 +*/
    1.18 +
    1.19 +#ifndef PARSEPOS_H
    1.20 +#define PARSEPOS_H
    1.21 +
    1.22 +#include "unicode/utypes.h"
    1.23 +#include "unicode/uobject.h"
    1.24 +
    1.25 + 
    1.26 +U_NAMESPACE_BEGIN
    1.27 +
    1.28 +/**
    1.29 + * \file
    1.30 + * \brief C++ API: Canonical Iterator
    1.31 + */
    1.32 +/** 
    1.33 + * <code>ParsePosition</code> is a simple class used by <code>Format</code>
    1.34 + * and its subclasses to keep track of the current position during parsing.
    1.35 + * The <code>parseObject</code> method in the various <code>Format</code>
    1.36 + * classes requires a <code>ParsePosition</code> object as an argument.
    1.37 + *
    1.38 + * <p>
    1.39 + * By design, as you parse through a string with different formats,
    1.40 + * you can use the same <code>ParsePosition</code>, since the index parameter
    1.41 + * records the current position.
    1.42 + *
    1.43 + * The ParsePosition class is not suitable for subclassing.
    1.44 + *
    1.45 + * @version     1.3 10/30/97
    1.46 + * @author      Mark Davis, Helena Shih
    1.47 + * @see         java.text.Format
    1.48 + */
    1.49 +
    1.50 +class U_COMMON_API ParsePosition : public UObject {
    1.51 +public:
    1.52 +    /**
    1.53 +     * Default constructor, the index starts with 0 as default.
    1.54 +     * @stable ICU 2.0
    1.55 +     */
    1.56 +    ParsePosition()
    1.57 +        : UObject(),
    1.58 +        index(0),
    1.59 +        errorIndex(-1)
    1.60 +      {}
    1.61 +
    1.62 +    /**
    1.63 +     * Create a new ParsePosition with the given initial index.
    1.64 +     * @param newIndex the new text offset.
    1.65 +     * @stable ICU 2.0
    1.66 +     */
    1.67 +    ParsePosition(int32_t newIndex)
    1.68 +        : UObject(),
    1.69 +        index(newIndex),
    1.70 +        errorIndex(-1)
    1.71 +      {}
    1.72 +
    1.73 +    /**
    1.74 +     * Copy constructor
    1.75 +     * @param copy the object to be copied from.
    1.76 +     * @stable ICU 2.0
    1.77 +     */
    1.78 +    ParsePosition(const ParsePosition& copy)
    1.79 +        : UObject(copy),
    1.80 +        index(copy.index),
    1.81 +        errorIndex(copy.errorIndex)
    1.82 +      {}
    1.83 +
    1.84 +    /**
    1.85 +     * Destructor
    1.86 +     * @stable ICU 2.0
    1.87 +     */
    1.88 +    virtual ~ParsePosition();
    1.89 +
    1.90 +    /**
    1.91 +     * Assignment operator
    1.92 +     * @stable ICU 2.0
    1.93 +     */
    1.94 +    ParsePosition&      operator=(const ParsePosition& copy);
    1.95 +
    1.96 +    /**
    1.97 +     * Equality operator.
    1.98 +     * @return TRUE if the two parse positions are equal, FALSE otherwise.
    1.99 +     * @stable ICU 2.0
   1.100 +     */
   1.101 +    UBool              operator==(const ParsePosition& that) const;
   1.102 +
   1.103 +    /**
   1.104 +     * Equality operator.
   1.105 +     * @return TRUE if the two parse positions are not equal, FALSE otherwise.
   1.106 +     * @stable ICU 2.0
   1.107 +     */
   1.108 +    UBool              operator!=(const ParsePosition& that) const;
   1.109 +
   1.110 +    /**
   1.111 +     * Clone this object.
   1.112 +     * Clones can be used concurrently in multiple threads.
   1.113 +     * If an error occurs, then NULL is returned.
   1.114 +     * The caller must delete the clone.
   1.115 +     *
   1.116 +     * @return a clone of this object
   1.117 +     *
   1.118 +     * @see getDynamicClassID
   1.119 +     * @stable ICU 2.8
   1.120 +     */
   1.121 +    ParsePosition *clone() const;
   1.122 +
   1.123 +    /**
   1.124 +     * Retrieve the current parse position.  On input to a parse method, this
   1.125 +     * is the index of the character at which parsing will begin; on output, it
   1.126 +     * is the index of the character following the last character parsed.
   1.127 +     * @return the current index.
   1.128 +     * @stable ICU 2.0
   1.129 +     */
   1.130 +    int32_t getIndex(void) const;
   1.131 +
   1.132 +    /**
   1.133 +     * Set the current parse position.
   1.134 +     * @param index the new index.
   1.135 +     * @stable ICU 2.0
   1.136 +     */
   1.137 +    void setIndex(int32_t index);
   1.138 +
   1.139 +    /**
   1.140 +     * Set the index at which a parse error occurred.  Formatters
   1.141 +     * should set this before returning an error code from their
   1.142 +     * parseObject method.  The default value is -1 if this is not
   1.143 +     * set.
   1.144 +     * @stable ICU 2.0
   1.145 +     */
   1.146 +    void setErrorIndex(int32_t ei);
   1.147 +
   1.148 +    /**
   1.149 +     * Retrieve the index at which an error occurred, or -1 if the
   1.150 +     * error index has not been set.
   1.151 +     * @stable ICU 2.0
   1.152 +     */
   1.153 +    int32_t getErrorIndex(void) const;
   1.154 +
   1.155 +    /**
   1.156 +     * ICU "poor man's RTTI", returns a UClassID for this class.
   1.157 +     *
   1.158 +     * @stable ICU 2.2
   1.159 +     */
   1.160 +    static UClassID U_EXPORT2 getStaticClassID();
   1.161 +
   1.162 +    /**
   1.163 +     * ICU "poor man's RTTI", returns a UClassID for the actual class.
   1.164 +     *
   1.165 +     * @stable ICU 2.2
   1.166 +     */
   1.167 +    virtual UClassID getDynamicClassID() const;
   1.168 +
   1.169 +private:
   1.170 +    /**
   1.171 +     * Input: the place you start parsing.
   1.172 +     * <br>Output: position where the parse stopped.
   1.173 +     * This is designed to be used serially,
   1.174 +     * with each call setting index up for the next one.
   1.175 +     */
   1.176 +    int32_t index;
   1.177 +
   1.178 +    /**
   1.179 +     * The index at which a parse error occurred.
   1.180 +     */
   1.181 +    int32_t errorIndex;
   1.182 +
   1.183 +};
   1.184 +
   1.185 +inline ParsePosition&
   1.186 +ParsePosition::operator=(const ParsePosition& copy)
   1.187 +{
   1.188 +  index = copy.index;
   1.189 +  errorIndex = copy.errorIndex;
   1.190 +  return *this;
   1.191 +}
   1.192 +
   1.193 +inline UBool
   1.194 +ParsePosition::operator==(const ParsePosition& copy) const
   1.195 +{
   1.196 +  if(index != copy.index || errorIndex != copy.errorIndex)
   1.197 +  return FALSE;
   1.198 +  else
   1.199 +  return TRUE;
   1.200 +}
   1.201 +
   1.202 +inline UBool
   1.203 +ParsePosition::operator!=(const ParsePosition& copy) const
   1.204 +{
   1.205 +  return !operator==(copy);
   1.206 +}
   1.207 +
   1.208 +inline int32_t
   1.209 +ParsePosition::getIndex() const
   1.210 +{
   1.211 +  return index;
   1.212 +}
   1.213 +
   1.214 +inline void
   1.215 +ParsePosition::setIndex(int32_t offset)
   1.216 +{
   1.217 +  this->index = offset;
   1.218 +}
   1.219 +
   1.220 +inline int32_t
   1.221 +ParsePosition::getErrorIndex() const
   1.222 +{
   1.223 +  return errorIndex;
   1.224 +}
   1.225 +
   1.226 +inline void
   1.227 +ParsePosition::setErrorIndex(int32_t ei)
   1.228 +{
   1.229 +  this->errorIndex = ei;
   1.230 +}
   1.231 +U_NAMESPACE_END
   1.232 +
   1.233 +#endif

mercurial