Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/common/unicode/parsepos.h
38827 views
/*1* Copyright (C) 1997-2005, International Business Machines Corporation and others. All Rights Reserved.2*******************************************************************************3*4* File PARSEPOS.H5*6* Modification History:7*8* Date Name Description9* 07/09/97 helena Converted from java.10* 07/17/98 stephen Added errorIndex support.11* 05/11/99 stephen Cleaned up.12*******************************************************************************13*/1415#ifndef PARSEPOS_H16#define PARSEPOS_H1718#include "unicode/utypes.h"19#include "unicode/uobject.h"202122U_NAMESPACE_BEGIN2324/**25* \file26* \brief C++ API: Canonical Iterator27*/28/**29* <code>ParsePosition</code> is a simple class used by <code>Format</code>30* and its subclasses to keep track of the current position during parsing.31* The <code>parseObject</code> method in the various <code>Format</code>32* classes requires a <code>ParsePosition</code> object as an argument.33*34* <p>35* By design, as you parse through a string with different formats,36* you can use the same <code>ParsePosition</code>, since the index parameter37* records the current position.38*39* The ParsePosition class is not suitable for subclassing.40*41* @version 1.3 10/30/9742* @author Mark Davis, Helena Shih43* @see java.text.Format44*/4546class U_COMMON_API ParsePosition : public UObject {47public:48/**49* Default constructor, the index starts with 0 as default.50* @stable ICU 2.051*/52ParsePosition()53: UObject(),54index(0),55errorIndex(-1)56{}5758/**59* Create a new ParsePosition with the given initial index.60* @param newIndex the new text offset.61* @stable ICU 2.062*/63ParsePosition(int32_t newIndex)64: UObject(),65index(newIndex),66errorIndex(-1)67{}6869/**70* Copy constructor71* @param copy the object to be copied from.72* @stable ICU 2.073*/74ParsePosition(const ParsePosition& copy)75: UObject(copy),76index(copy.index),77errorIndex(copy.errorIndex)78{}7980/**81* Destructor82* @stable ICU 2.083*/84virtual ~ParsePosition();8586/**87* Assignment operator88* @stable ICU 2.089*/90ParsePosition& operator=(const ParsePosition& copy);9192/**93* Equality operator.94* @return TRUE if the two parse positions are equal, FALSE otherwise.95* @stable ICU 2.096*/97UBool operator==(const ParsePosition& that) const;9899/**100* Equality operator.101* @return TRUE if the two parse positions are not equal, FALSE otherwise.102* @stable ICU 2.0103*/104UBool operator!=(const ParsePosition& that) const;105106/**107* Clone this object.108* Clones can be used concurrently in multiple threads.109* If an error occurs, then NULL is returned.110* The caller must delete the clone.111*112* @return a clone of this object113*114* @see getDynamicClassID115* @stable ICU 2.8116*/117ParsePosition *clone() const;118119/**120* Retrieve the current parse position. On input to a parse method, this121* is the index of the character at which parsing will begin; on output, it122* is the index of the character following the last character parsed.123* @return the current index.124* @stable ICU 2.0125*/126int32_t getIndex(void) const;127128/**129* Set the current parse position.130* @param index the new index.131* @stable ICU 2.0132*/133void setIndex(int32_t index);134135/**136* Set the index at which a parse error occurred. Formatters137* should set this before returning an error code from their138* parseObject method. The default value is -1 if this is not139* set.140* @stable ICU 2.0141*/142void setErrorIndex(int32_t ei);143144/**145* Retrieve the index at which an error occurred, or -1 if the146* error index has not been set.147* @stable ICU 2.0148*/149int32_t getErrorIndex(void) const;150151/**152* ICU "poor man's RTTI", returns a UClassID for this class.153*154* @stable ICU 2.2155*/156static UClassID U_EXPORT2 getStaticClassID();157158/**159* ICU "poor man's RTTI", returns a UClassID for the actual class.160*161* @stable ICU 2.2162*/163virtual UClassID getDynamicClassID() const;164165private:166/**167* Input: the place you start parsing.168* <br>Output: position where the parse stopped.169* This is designed to be used serially,170* with each call setting index up for the next one.171*/172int32_t index;173174/**175* The index at which a parse error occurred.176*/177int32_t errorIndex;178179};180181inline ParsePosition&182ParsePosition::operator=(const ParsePosition& copy)183{184index = copy.index;185errorIndex = copy.errorIndex;186return *this;187}188189inline UBool190ParsePosition::operator==(const ParsePosition& copy) const191{192if(index != copy.index || errorIndex != copy.errorIndex)193return FALSE;194else195return TRUE;196}197198inline UBool199ParsePosition::operator!=(const ParsePosition& copy) const200{201return !operator==(copy);202}203204inline int32_t205ParsePosition::getIndex() const206{207return index;208}209210inline void211ParsePosition::setIndex(int32_t offset)212{213this->index = offset;214}215216inline int32_t217ParsePosition::getErrorIndex() const218{219return errorIndex;220}221222inline void223ParsePosition::setErrorIndex(int32_t ei)224{225this->errorIndex = ei;226}227U_NAMESPACE_END228229#endif230231232