Path: blob/jdk8u272-b10-aarch32-20201026/jdk/src/share/native/common/unicode/parsepos.h
48773 views
// © 2016 and later: Unicode, Inc. and others.1// License & terms of use: http://www.unicode.org/copyright.html2/*3* Copyright (C) 1997-2005, International Business Machines Corporation and others. All Rights Reserved.4*******************************************************************************5*6* File PARSEPOS.H7*8* Modification History:9*10* Date Name Description11* 07/09/97 helena Converted from java.12* 07/17/98 stephen Added errorIndex support.13* 05/11/99 stephen Cleaned up.14*******************************************************************************15*/1617#ifndef PARSEPOS_H18#define PARSEPOS_H1920#include "unicode/utypes.h"21#include "unicode/uobject.h"222324U_NAMESPACE_BEGIN2526/**27* \file28* \brief C++ API: Canonical Iterator29*/30/**31* <code>ParsePosition</code> is a simple class used by <code>Format</code>32* and its subclasses to keep track of the current position during parsing.33* The <code>parseObject</code> method in the various <code>Format</code>34* classes requires a <code>ParsePosition</code> object as an argument.35*36* <p>37* By design, as you parse through a string with different formats,38* you can use the same <code>ParsePosition</code>, since the index parameter39* records the current position.40*41* The ParsePosition class is not suitable for subclassing.42*43* @version 1.3 10/30/9744* @author Mark Davis, Helena Shih45* @see java.text.Format46*/4748class U_COMMON_API ParsePosition : public UObject {49public:50/**51* Default constructor, the index starts with 0 as default.52* @stable ICU 2.053*/54ParsePosition()55: UObject(),56index(0),57errorIndex(-1)58{}5960/**61* Create a new ParsePosition with the given initial index.62* @param newIndex the new text offset.63* @stable ICU 2.064*/65ParsePosition(int32_t newIndex)66: UObject(),67index(newIndex),68errorIndex(-1)69{}7071/**72* Copy constructor73* @param copy the object to be copied from.74* @stable ICU 2.075*/76ParsePosition(const ParsePosition& copy)77: UObject(copy),78index(copy.index),79errorIndex(copy.errorIndex)80{}8182/**83* Destructor84* @stable ICU 2.085*/86virtual ~ParsePosition();8788/**89* Assignment operator90* @stable ICU 2.091*/92inline ParsePosition& operator=(const ParsePosition& copy);9394/**95* Equality operator.96* @return TRUE if the two parse positions are equal, FALSE otherwise.97* @stable ICU 2.098*/99inline UBool operator==(const ParsePosition& that) const;100101/**102* Equality operator.103* @return TRUE if the two parse positions are not equal, FALSE otherwise.104* @stable ICU 2.0105*/106inline UBool operator!=(const ParsePosition& that) const;107108/**109* Clone this object.110* Clones can be used concurrently in multiple threads.111* If an error occurs, then NULL is returned.112* The caller must delete the clone.113*114* @return a clone of this object115*116* @see getDynamicClassID117* @stable ICU 2.8118*/119ParsePosition *clone() const;120121/**122* Retrieve the current parse position. On input to a parse method, this123* is the index of the character at which parsing will begin; on output, it124* is the index of the character following the last character parsed.125* @return the current index.126* @stable ICU 2.0127*/128inline int32_t getIndex(void) const;129130/**131* Set the current parse position.132* @param index the new index.133* @stable ICU 2.0134*/135inline void setIndex(int32_t index);136137/**138* Set the index at which a parse error occurred. Formatters139* should set this before returning an error code from their140* parseObject method. The default value is -1 if this is not141* set.142* @stable ICU 2.0143*/144inline void setErrorIndex(int32_t ei);145146/**147* Retrieve the index at which an error occurred, or -1 if the148* error index has not been set.149* @stable ICU 2.0150*/151inline int32_t getErrorIndex(void) const;152153/**154* ICU "poor man's RTTI", returns a UClassID for this class.155*156* @stable ICU 2.2157*/158static UClassID U_EXPORT2 getStaticClassID();159160/**161* ICU "poor man's RTTI", returns a UClassID for the actual class.162*163* @stable ICU 2.2164*/165virtual UClassID getDynamicClassID() const;166167private:168/**169* Input: the place you start parsing.170* <br>Output: position where the parse stopped.171* This is designed to be used serially,172* with each call setting index up for the next one.173*/174int32_t index;175176/**177* The index at which a parse error occurred.178*/179int32_t errorIndex;180181};182183inline ParsePosition&184ParsePosition::operator=(const ParsePosition& copy)185{186index = copy.index;187errorIndex = copy.errorIndex;188return *this;189}190191inline UBool192ParsePosition::operator==(const ParsePosition& copy) const193{194if(index != copy.index || errorIndex != copy.errorIndex)195return FALSE;196else197return TRUE;198}199200inline UBool201ParsePosition::operator!=(const ParsePosition& copy) const202{203return !operator==(copy);204}205206inline int32_t207ParsePosition::getIndex() const208{209return index;210}211212inline void213ParsePosition::setIndex(int32_t offset)214{215this->index = offset;216}217218inline int32_t219ParsePosition::getErrorIndex() const220{221return errorIndex;222}223224inline void225ParsePosition::setErrorIndex(int32_t ei)226{227this->errorIndex = ei;228}229U_NAMESPACE_END230231#endif232233234