sl@0: /*
sl@0: * Copyright (C) 1997-2005, International Business Machines Corporation and others. All Rights Reserved.
sl@0: *******************************************************************************
sl@0: *
sl@0: * File PARSEPOS.H
sl@0: *
sl@0: * Modification History:
sl@0: *
sl@0: * Date Name Description
sl@0: * 07/09/97 helena Converted from java.
sl@0: * 07/17/98 stephen Added errorIndex support.
sl@0: * 05/11/99 stephen Cleaned up.
sl@0: *******************************************************************************
sl@0: */
sl@0:
sl@0: #ifndef PARSEPOS_H
sl@0: #define PARSEPOS_H
sl@0:
sl@0: #include "unicode/utypes.h"
sl@0: #include "unicode/uobject.h"
sl@0:
sl@0:
sl@0: U_NAMESPACE_BEGIN
sl@0:
sl@0: /**
sl@0: * \file
sl@0: * \brief C++ API: Canonical Iterator
sl@0: */
sl@0: /**
sl@0: * ParsePosition
is a simple class used by Format
sl@0: * and its subclasses to keep track of the current position during parsing.
sl@0: * The parseObject
method in the various Format
sl@0: * classes requires a ParsePosition
object as an argument.
sl@0: *
sl@0: *
sl@0: * By design, as you parse through a string with different formats,
sl@0: * you can use the same ParsePosition
, since the index parameter
sl@0: * records the current position.
sl@0: *
sl@0: * The ParsePosition class is not suitable for subclassing.
sl@0: *
sl@0: * @version 1.3 10/30/97
sl@0: * @author Mark Davis, Helena Shih
sl@0: * @see java.text.Format
sl@0: */
sl@0:
sl@0: class U_COMMON_API ParsePosition : public UObject {
sl@0: public:
sl@0: /**
sl@0: * Default constructor, the index starts with 0 as default.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: ParsePosition()
sl@0: : UObject(),
sl@0: index(0),
sl@0: errorIndex(-1)
sl@0: {}
sl@0:
sl@0: /**
sl@0: * Create a new ParsePosition with the given initial index.
sl@0: * @param newIndex the new text offset.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: ParsePosition(int32_t newIndex)
sl@0: : UObject(),
sl@0: index(newIndex),
sl@0: errorIndex(-1)
sl@0: {}
sl@0:
sl@0: /**
sl@0: * Copy constructor
sl@0: * @param copy the object to be copied from.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: ParsePosition(const ParsePosition& copy)
sl@0: : UObject(copy),
sl@0: index(copy.index),
sl@0: errorIndex(copy.errorIndex)
sl@0: {}
sl@0:
sl@0: /**
sl@0: * Destructor
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: virtual ~ParsePosition();
sl@0:
sl@0: /**
sl@0: * Assignment operator
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: ParsePosition& operator=(const ParsePosition& copy);
sl@0:
sl@0: /**
sl@0: * Equality operator.
sl@0: * @return TRUE if the two parse positions are equal, FALSE otherwise.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: UBool operator==(const ParsePosition& that) const;
sl@0:
sl@0: /**
sl@0: * Equality operator.
sl@0: * @return TRUE if the two parse positions are not equal, FALSE otherwise.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: UBool operator!=(const ParsePosition& that) const;
sl@0:
sl@0: /**
sl@0: * Clone this object.
sl@0: * Clones can be used concurrently in multiple threads.
sl@0: * If an error occurs, then NULL is returned.
sl@0: * The caller must delete the clone.
sl@0: *
sl@0: * @return a clone of this object
sl@0: *
sl@0: * @see getDynamicClassID
sl@0: * @stable ICU 2.8
sl@0: */
sl@0: ParsePosition *clone() const;
sl@0:
sl@0: /**
sl@0: * Retrieve the current parse position. On input to a parse method, this
sl@0: * is the index of the character at which parsing will begin; on output, it
sl@0: * is the index of the character following the last character parsed.
sl@0: * @return the current index.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: int32_t getIndex(void) const;
sl@0:
sl@0: /**
sl@0: * Set the current parse position.
sl@0: * @param index the new index.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: void setIndex(int32_t index);
sl@0:
sl@0: /**
sl@0: * Set the index at which a parse error occurred. Formatters
sl@0: * should set this before returning an error code from their
sl@0: * parseObject method. The default value is -1 if this is not
sl@0: * set.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: void setErrorIndex(int32_t ei);
sl@0:
sl@0: /**
sl@0: * Retrieve the index at which an error occurred, or -1 if the
sl@0: * error index has not been set.
sl@0: * @stable ICU 2.0
sl@0: */
sl@0: int32_t getErrorIndex(void) const;
sl@0:
sl@0: /**
sl@0: * ICU "poor man's RTTI", returns a UClassID for this class.
sl@0: *
sl@0: * @stable ICU 2.2
sl@0: */
sl@0: static UClassID U_EXPORT2 getStaticClassID();
sl@0:
sl@0: /**
sl@0: * ICU "poor man's RTTI", returns a UClassID for the actual class.
sl@0: *
sl@0: * @stable ICU 2.2
sl@0: */
sl@0: virtual UClassID getDynamicClassID() const;
sl@0:
sl@0: private:
sl@0: /**
sl@0: * Input: the place you start parsing.
sl@0: *
Output: position where the parse stopped.
sl@0: * This is designed to be used serially,
sl@0: * with each call setting index up for the next one.
sl@0: */
sl@0: int32_t index;
sl@0:
sl@0: /**
sl@0: * The index at which a parse error occurred.
sl@0: */
sl@0: int32_t errorIndex;
sl@0:
sl@0: };
sl@0:
sl@0: inline ParsePosition&
sl@0: ParsePosition::operator=(const ParsePosition& copy)
sl@0: {
sl@0: index = copy.index;
sl@0: errorIndex = copy.errorIndex;
sl@0: return *this;
sl@0: }
sl@0:
sl@0: inline UBool
sl@0: ParsePosition::operator==(const ParsePosition& copy) const
sl@0: {
sl@0: if(index != copy.index || errorIndex != copy.errorIndex)
sl@0: return FALSE;
sl@0: else
sl@0: return TRUE;
sl@0: }
sl@0:
sl@0: inline UBool
sl@0: ParsePosition::operator!=(const ParsePosition& copy) const
sl@0: {
sl@0: return !operator==(copy);
sl@0: }
sl@0:
sl@0: inline int32_t
sl@0: ParsePosition::getIndex() const
sl@0: {
sl@0: return index;
sl@0: }
sl@0:
sl@0: inline void
sl@0: ParsePosition::setIndex(int32_t offset)
sl@0: {
sl@0: this->index = offset;
sl@0: }
sl@0:
sl@0: inline int32_t
sl@0: ParsePosition::getErrorIndex() const
sl@0: {
sl@0: return errorIndex;
sl@0: }
sl@0:
sl@0: inline void
sl@0: ParsePosition::setErrorIndex(int32_t ei)
sl@0: {
sl@0: this->errorIndex = ei;
sl@0: }
sl@0: U_NAMESPACE_END
sl@0:
sl@0: #endif