1999-12-28 23:57:50 +00:00
|
|
|
/*
|
2001-03-22 00:09:10 +00:00
|
|
|
* Copyright (C) {1997-1999}, International Business Machines Corporation and others. All Rights Reserved.
|
1999-12-28 23:57:50 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* File PARSEPOS.H
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 07/09/97 helena Converted from java.
|
|
|
|
* 07/17/98 stephen Added errorIndex support.
|
|
|
|
* 05/11/99 stephen Cleaned up.
|
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PARSEPOS_H
|
|
|
|
#define PARSEPOS_H
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
2002-06-27 01:19:20 +00:00
|
|
|
#include "unicode/uobject.h"
|
2001-03-22 00:09:10 +00:00
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* <code>ParsePosition</code> is a simple class used by <code>Format</code>
|
|
|
|
* and its subclasses to keep track of the current position during parsing.
|
|
|
|
* The <code>parseObject</code> method in the various <code>Format</code>
|
|
|
|
* classes requires a <code>ParsePosition</code> object as an argument.
|
|
|
|
*
|
2001-03-22 00:09:10 +00:00
|
|
|
* <p>
|
1999-12-28 23:57:50 +00:00
|
|
|
* By design, as you parse through a string with different formats,
|
|
|
|
* you can use the same <code>ParsePosition</code>, since the index parameter
|
|
|
|
* records the current position.
|
|
|
|
*
|
|
|
|
* @version 1.3 10/30/97
|
|
|
|
* @author Mark Davis, Helena Shih
|
|
|
|
* @see java.text.Format
|
|
|
|
*/
|
|
|
|
|
2002-06-27 01:19:20 +00:00
|
|
|
class U_COMMON_API ParsePosition : public UObject {
|
1999-12-28 23:57:50 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Default constructor, the index starts with 0 as default.
|
2000-03-22 19:19:33 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2001-03-22 00:09:10 +00:00
|
|
|
ParsePosition()
|
2002-07-02 23:58:34 +00:00
|
|
|
: UObject()
|
1999-12-28 23:57:50 +00:00
|
|
|
{ this->index = 0; this->errorIndex = -1; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new ParsePosition with the given initial index.
|
|
|
|
* @param newIndex the new text offset.
|
2000-03-22 19:19:33 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2002-03-12 01:32:42 +00:00
|
|
|
ParsePosition(int32_t newIndex)
|
2002-07-02 23:58:34 +00:00
|
|
|
: UObject()
|
2001-03-22 00:09:10 +00:00
|
|
|
{ this->index = newIndex; this->errorIndex = -1; }
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Copy constructor
|
|
|
|
* @param copy the object to be copied from.
|
2000-03-22 19:19:33 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2001-03-22 00:09:10 +00:00
|
|
|
ParsePosition(const ParsePosition& copy)
|
2002-07-02 23:58:34 +00:00
|
|
|
: UObject(copy)
|
1999-12-28 23:57:50 +00:00
|
|
|
{ this->index = copy.index; this->errorIndex = copy.errorIndex; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
2000-03-22 19:19:33 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
~ParsePosition() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assignment operator
|
2000-03-22 19:19:33 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
ParsePosition& operator=(const ParsePosition& copy);
|
|
|
|
|
2001-03-22 00:09:10 +00:00
|
|
|
/**
|
1999-12-28 23:57:50 +00:00
|
|
|
* Equality operator.
|
|
|
|
* @return TRUE if the two parse positions are equal, FALSE otherwise.
|
2000-03-22 19:19:33 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool operator==(const ParsePosition& that) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
2001-03-22 00:09:10 +00:00
|
|
|
/**
|
1999-12-28 23:57:50 +00:00
|
|
|
* Equality operator.
|
|
|
|
* @return TRUE if the two parse positions are not equal, FALSE otherwise.
|
2000-03-22 19:19:33 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool operator!=(const ParsePosition& that) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the current parse position. On input to a parse method, this
|
|
|
|
* is the index of the character at which parsing will begin; on output, it
|
|
|
|
* is the index of the character following the last character parsed.
|
|
|
|
* @return the current index.
|
2000-03-22 19:19:33 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2002-03-12 01:32:42 +00:00
|
|
|
int32_t getIndex(void) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the current parse position.
|
|
|
|
* @param index the new index.
|
2000-03-22 19:19:33 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2002-03-12 01:32:42 +00:00
|
|
|
void setIndex(int32_t index);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the index at which a parse error occurred. Formatters
|
|
|
|
* should set this before returning an error code from their
|
|
|
|
* parseObject method. The default value is -1 if this is not
|
2001-03-22 00:09:10 +00:00
|
|
|
* set.
|
2000-03-22 19:19:33 +00:00
|
|
|
* @stable
|
|
|
|
*/
|
2002-03-12 01:32:42 +00:00
|
|
|
void setErrorIndex(int32_t ei);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the index at which an error occurred, or -1 if the
|
2001-03-22 00:09:10 +00:00
|
|
|
* error index has not been set.
|
2000-03-22 19:19:33 +00:00
|
|
|
* @stable
|
|
|
|
*/
|
2002-03-12 01:32:42 +00:00
|
|
|
int32_t getErrorIndex(void) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
2002-06-29 00:04:16 +00:00
|
|
|
/**
|
|
|
|
* ICU "poor man's RTTI", returns a UClassID for the actual class.
|
|
|
|
*
|
|
|
|
* @draft ICU 2.2
|
|
|
|
*/
|
|
|
|
virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ICU "poor man's RTTI", returns a UClassID for this class.
|
|
|
|
*
|
|
|
|
* @draft ICU 2.2
|
|
|
|
*/
|
|
|
|
static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Input: the place you start parsing.
|
|
|
|
* <br>Output: position where the parse stopped.
|
|
|
|
* This is designed to be used serially,
|
|
|
|
* with each call setting index up for the next one.
|
|
|
|
*/
|
2002-03-12 01:32:42 +00:00
|
|
|
int32_t index;
|
2001-03-22 00:09:10 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* The index at which a parse error occurred.
|
|
|
|
*/
|
2002-03-12 01:32:42 +00:00
|
|
|
int32_t errorIndex;
|
2002-06-29 00:04:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The address of this static class variable serves as this class's ID
|
|
|
|
* for ICU "poor man's RTTI".
|
|
|
|
*/
|
|
|
|
static const char fgClassID;
|
1999-12-28 23:57:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline ParsePosition&
|
|
|
|
ParsePosition::operator=(const ParsePosition& copy)
|
|
|
|
{
|
|
|
|
index = copy.index;
|
|
|
|
errorIndex = copy.errorIndex;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
inline UBool
|
1999-12-28 23:57:50 +00:00
|
|
|
ParsePosition::operator==(const ParsePosition& copy) const
|
|
|
|
{
|
2001-03-22 00:09:10 +00:00
|
|
|
if(index != copy.index || errorIndex != copy.errorIndex)
|
1999-12-28 23:57:50 +00:00
|
|
|
return FALSE;
|
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
inline UBool
|
1999-12-28 23:57:50 +00:00
|
|
|
ParsePosition::operator!=(const ParsePosition& copy) const
|
|
|
|
{
|
|
|
|
return !operator==(copy);
|
|
|
|
}
|
|
|
|
|
2002-03-12 01:32:42 +00:00
|
|
|
inline int32_t
|
1999-12-28 23:57:50 +00:00
|
|
|
ParsePosition::getIndex() const
|
|
|
|
{
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2002-03-12 01:32:42 +00:00
|
|
|
ParsePosition::setIndex(int32_t offset)
|
1999-12-28 23:57:50 +00:00
|
|
|
{
|
2000-04-14 05:22:29 +00:00
|
|
|
this->index = offset;
|
1999-12-28 23:57:50 +00:00
|
|
|
}
|
|
|
|
|
2002-03-12 01:32:42 +00:00
|
|
|
inline int32_t
|
1999-12-28 23:57:50 +00:00
|
|
|
ParsePosition::getErrorIndex() const
|
|
|
|
{
|
|
|
|
return errorIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2002-03-12 01:32:42 +00:00
|
|
|
ParsePosition::setErrorIndex(int32_t ei)
|
1999-12-28 23:57:50 +00:00
|
|
|
{
|
|
|
|
this->errorIndex = ei;
|
|
|
|
}
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_END
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
#endif
|