michael@0: /* michael@0: * Copyright (C) 1997-2005, International Business Machines Corporation and others. All Rights Reserved. michael@0: ******************************************************************************* michael@0: * michael@0: * File PARSEPOS.H michael@0: * michael@0: * Modification History: michael@0: * michael@0: * Date Name Description michael@0: * 07/09/97 helena Converted from java. michael@0: * 07/17/98 stephen Added errorIndex support. michael@0: * 05/11/99 stephen Cleaned up. michael@0: ******************************************************************************* michael@0: */ michael@0: michael@0: #ifndef PARSEPOS_H michael@0: #define PARSEPOS_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/uobject.h" michael@0: michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C++ API: Canonical Iterator michael@0: */ michael@0: /** michael@0: * ParsePosition is a simple class used by Format michael@0: * and its subclasses to keep track of the current position during parsing. michael@0: * The parseObject method in the various Format michael@0: * classes requires a ParsePosition object as an argument. michael@0: * michael@0: *

michael@0: * By design, as you parse through a string with different formats, michael@0: * you can use the same ParsePosition, since the index parameter michael@0: * records the current position. michael@0: * michael@0: * The ParsePosition class is not suitable for subclassing. michael@0: * michael@0: * @version 1.3 10/30/97 michael@0: * @author Mark Davis, Helena Shih michael@0: * @see java.text.Format michael@0: */ michael@0: michael@0: class U_COMMON_API ParsePosition : public UObject { michael@0: public: michael@0: /** michael@0: * Default constructor, the index starts with 0 as default. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: ParsePosition() michael@0: : UObject(), michael@0: index(0), michael@0: errorIndex(-1) michael@0: {} michael@0: michael@0: /** michael@0: * Create a new ParsePosition with the given initial index. michael@0: * @param newIndex the new text offset. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: ParsePosition(int32_t newIndex) michael@0: : UObject(), michael@0: index(newIndex), michael@0: errorIndex(-1) michael@0: {} michael@0: michael@0: /** michael@0: * Copy constructor michael@0: * @param copy the object to be copied from. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: ParsePosition(const ParsePosition& copy) michael@0: : UObject(copy), michael@0: index(copy.index), michael@0: errorIndex(copy.errorIndex) michael@0: {} michael@0: michael@0: /** michael@0: * Destructor michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual ~ParsePosition(); michael@0: michael@0: /** michael@0: * Assignment operator michael@0: * @stable ICU 2.0 michael@0: */ michael@0: ParsePosition& operator=(const ParsePosition& copy); michael@0: michael@0: /** michael@0: * Equality operator. michael@0: * @return TRUE if the two parse positions are equal, FALSE otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UBool operator==(const ParsePosition& that) const; michael@0: michael@0: /** michael@0: * Equality operator. michael@0: * @return TRUE if the two parse positions are not equal, FALSE otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UBool operator!=(const ParsePosition& that) const; michael@0: michael@0: /** michael@0: * Clone this object. michael@0: * Clones can be used concurrently in multiple threads. michael@0: * If an error occurs, then NULL is returned. michael@0: * The caller must delete the clone. michael@0: * michael@0: * @return a clone of this object michael@0: * michael@0: * @see getDynamicClassID michael@0: * @stable ICU 2.8 michael@0: */ michael@0: ParsePosition *clone() const; michael@0: michael@0: /** michael@0: * Retrieve the current parse position. On input to a parse method, this michael@0: * is the index of the character at which parsing will begin; on output, it michael@0: * is the index of the character following the last character parsed. michael@0: * @return the current index. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: int32_t getIndex(void) const; michael@0: michael@0: /** michael@0: * Set the current parse position. michael@0: * @param index the new index. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void setIndex(int32_t index); michael@0: michael@0: /** michael@0: * Set the index at which a parse error occurred. Formatters michael@0: * should set this before returning an error code from their michael@0: * parseObject method. The default value is -1 if this is not michael@0: * set. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void setErrorIndex(int32_t ei); michael@0: michael@0: /** michael@0: * Retrieve the index at which an error occurred, or -1 if the michael@0: * error index has not been set. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: int32_t getErrorIndex(void) const; michael@0: michael@0: /** michael@0: * ICU "poor man's RTTI", returns a UClassID for this class. michael@0: * michael@0: * @stable ICU 2.2 michael@0: */ michael@0: static UClassID U_EXPORT2 getStaticClassID(); michael@0: michael@0: /** michael@0: * ICU "poor man's RTTI", returns a UClassID for the actual class. michael@0: * michael@0: * @stable ICU 2.2 michael@0: */ michael@0: virtual UClassID getDynamicClassID() const; michael@0: michael@0: private: michael@0: /** michael@0: * Input: the place you start parsing. michael@0: *
Output: position where the parse stopped. michael@0: * This is designed to be used serially, michael@0: * with each call setting index up for the next one. michael@0: */ michael@0: int32_t index; michael@0: michael@0: /** michael@0: * The index at which a parse error occurred. michael@0: */ michael@0: int32_t errorIndex; michael@0: michael@0: }; michael@0: michael@0: inline ParsePosition& michael@0: ParsePosition::operator=(const ParsePosition& copy) michael@0: { michael@0: index = copy.index; michael@0: errorIndex = copy.errorIndex; michael@0: return *this; michael@0: } michael@0: michael@0: inline UBool michael@0: ParsePosition::operator==(const ParsePosition& copy) const michael@0: { michael@0: if(index != copy.index || errorIndex != copy.errorIndex) michael@0: return FALSE; michael@0: else michael@0: return TRUE; michael@0: } michael@0: michael@0: inline UBool michael@0: ParsePosition::operator!=(const ParsePosition& copy) const michael@0: { michael@0: return !operator==(copy); michael@0: } michael@0: michael@0: inline int32_t michael@0: ParsePosition::getIndex() const michael@0: { michael@0: return index; michael@0: } michael@0: michael@0: inline void michael@0: ParsePosition::setIndex(int32_t offset) michael@0: { michael@0: this->index = offset; michael@0: } michael@0: michael@0: inline int32_t michael@0: ParsePosition::getErrorIndex() const michael@0: { michael@0: return errorIndex; michael@0: } michael@0: michael@0: inline void michael@0: ParsePosition::setErrorIndex(int32_t ei) michael@0: { michael@0: this->errorIndex = ei; michael@0: } michael@0: U_NAMESPACE_END michael@0: michael@0: #endif