1999-12-28 23:57:50 +00:00
|
|
|
/*
|
|
|
|
********************************************************************************
|
2001-03-21 20:31:13 +00:00
|
|
|
* Copyright (C) 1997-2001, International Business Machines
|
1999-12-28 23:57:50 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
********************************************************************************
|
|
|
|
*
|
|
|
|
* File FIELDPOS.H
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 02/25/97 aliu Converted from java.
|
|
|
|
* 03/17/97 clhuang Updated per Format implementation.
|
|
|
|
* 07/17/98 stephen Added default/copy ctors, and operators =, ==, !=
|
|
|
|
********************************************************************************
|
|
|
|
*/
|
|
|
|
// *****************************************************************************
|
|
|
|
// This file was generated from the java source file FieldPosition.java
|
|
|
|
// *****************************************************************************
|
|
|
|
|
|
|
|
#ifndef FIELDPOS_H
|
|
|
|
#define FIELDPOS_H
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
2002-06-27 01:19:20 +00:00
|
|
|
#include "unicode/uobject.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* <code>FieldPosition</code> is a simple class used by <code>Format</code>
|
|
|
|
* and its subclasses to identify fields in formatted output. Fields are
|
|
|
|
* identified by constants, whose names typically end with <code>_FIELD</code>,
|
|
|
|
* defined in the various subclasses of <code>Format</code>. See
|
|
|
|
* <code>ERA_FIELD</code> and its friends in <code>DateFormat</code> for
|
|
|
|
* an example.
|
|
|
|
*
|
|
|
|
* <p>
|
|
|
|
* <code>FieldPosition</code> keeps track of the position of the
|
|
|
|
* field within the formatted output with two indices: the index
|
|
|
|
* of the first character of the field and the index of the last
|
|
|
|
* character of the field.
|
|
|
|
*
|
|
|
|
* <p>
|
|
|
|
* One version of the <code>format</code> method in the various
|
|
|
|
* <code>Format</code> classes requires a <code>FieldPosition</code>
|
|
|
|
* object as an argument. You use this <code>format</code> method
|
|
|
|
* to perform partial formatting or to get information about the
|
|
|
|
* formatted output (such as the position of a field).
|
|
|
|
*
|
|
|
|
* <p>
|
|
|
|
* Below is an example of using <code>FieldPosition</code> to aid
|
|
|
|
* alignment of an array of formatted floating-point numbers on
|
|
|
|
* their decimal points:
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
* \code
|
|
|
|
* double doubleNum[] = {123456789.0, -12345678.9, 1234567.89, -123456.789,
|
|
|
|
* 12345.6789, -1234.56789, 123.456789, -12.3456789, 1.23456789};
|
|
|
|
* int dNumSize = (int)(sizeof(doubleNum)/sizeof(double));
|
|
|
|
*
|
|
|
|
* UErrorCode status = U_ZERO_ERROR;
|
|
|
|
* DecimalFormat* fmt = (DecimalFormat*) NumberFormat::createInstance(status);
|
|
|
|
* fmt->setDecimalSeparatorAlwaysShown(true);
|
|
|
|
*
|
|
|
|
* const int tempLen = 20;
|
|
|
|
* char temp[tempLen];
|
|
|
|
*
|
2001-03-19 22:30:38 +00:00
|
|
|
* for (int i=0; i<dNumSize; i++) {
|
2000-12-08 18:46:55 +00:00
|
|
|
* FieldPosition pos(NumberFormat::INTEGER_FIELD);
|
|
|
|
* UnicodeString buf;
|
|
|
|
* char fmtText[tempLen];
|
|
|
|
* ToCharString(fmt->format(doubleNum[i], buf, pos), fmtText);
|
2001-03-19 22:30:38 +00:00
|
|
|
* for (int j=0; j<tempLen; j++) temp[j] = ' '; // clear with spaces
|
2000-12-08 18:46:55 +00:00
|
|
|
* temp[__min(tempLen, tempLen-pos.getEndIndex())] = '\0';
|
2001-03-19 22:30:38 +00:00
|
|
|
* cout << temp << fmtText << endl;
|
2000-12-08 18:46:55 +00:00
|
|
|
* }
|
|
|
|
* delete fmt;
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
* </pre>
|
|
|
|
* <p>
|
|
|
|
* The code will generate the following output:
|
|
|
|
* <pre>
|
2000-12-08 18:46:55 +00:00
|
|
|
* \code
|
|
|
|
* 123,456,789.000
|
|
|
|
* -12,345,678.900
|
|
|
|
* 1,234,567.880
|
|
|
|
* -123,456.789
|
|
|
|
* 12,345.678
|
|
|
|
* -1,234.567
|
|
|
|
* 123.456
|
|
|
|
* -12.345
|
|
|
|
* 1.234
|
|
|
|
* \endcode
|
1999-12-28 23:57:50 +00:00
|
|
|
* </pre>
|
|
|
|
*/
|
2002-06-27 01:19:20 +00:00
|
|
|
class U_I18N_API FieldPosition : public UObject {
|
1999-12-28 23:57:50 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* DONT_CARE may be specified as the field to indicate that the
|
|
|
|
* caller doesn't need to specify a field. Do not subclass.
|
|
|
|
*/
|
|
|
|
enum { DONT_CARE = -1 };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a FieldPosition object with a non-specified field.
|
2000-03-22 19:19:33 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
FieldPosition()
|
2002-07-02 23:58:34 +00:00
|
|
|
: UObject(), fField(DONT_CARE), fBeginIndex(0), fEndIndex(0) {}
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a FieldPosition object for the given field. Fields are
|
|
|
|
* identified by constants, whose names typically end with _FIELD,
|
|
|
|
* in the various subclasses of Format.
|
|
|
|
*
|
|
|
|
* @see NumberFormat#INTEGER_FIELD
|
|
|
|
* @see NumberFormat#FRACTION_FIELD
|
|
|
|
* @see DateFormat#YEAR_FIELD
|
|
|
|
* @see DateFormat#MONTH_FIELD
|
2000-03-22 19:19:33 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
FieldPosition(int32_t field)
|
2002-07-02 23:58:34 +00:00
|
|
|
: UObject(), fField(field), fBeginIndex(0), fEndIndex(0) {}
|
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
|
|
|
*/
|
|
|
|
FieldPosition(const FieldPosition& copy)
|
2002-07-02 23:58:34 +00:00
|
|
|
: UObject(copy), fField(copy.fField), fBeginIndex(copy.fBeginIndex), fEndIndex(copy.fEndIndex) {}
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
2000-03-22 19:19:33 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
~FieldPosition() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assignment operator
|
2002-07-01 11:04:45 +00:00
|
|
|
* @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
|
|
|
*/
|
|
|
|
FieldPosition& operator=(const FieldPosition& copy);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Equality operator.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param that the object to be compared with.
|
|
|
|
* @return TRUE if the two field 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 FieldPosition& that) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Equality operator.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param that the object to be compared with.
|
|
|
|
* @return TRUE if the two field 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 FieldPosition& that) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the field identifier.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @return the field identifier.
|
2000-03-22 19:19:33 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
int32_t getField(void) const { return fField; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the index of the first character in the requested field.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @return the index of the first character in the requested field.
|
2000-03-22 19:19:33 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
int32_t getBeginIndex(void) const { return fBeginIndex; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the index of the character following the last character in the
|
|
|
|
* requested field.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @return the index of the character following the last character in the
|
|
|
|
* requested field.
|
2000-03-22 19:19:33 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
int32_t getEndIndex(void) const { return fEndIndex; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the field.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param f the new value of the field.
|
2000-03-22 19:19:33 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
void setField(int32_t f) { fField = f; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the begin index. For use by subclasses of Format.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param bi the new value of the begin index
|
2000-03-22 19:19:33 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
void setBeginIndex(int32_t bi) { fBeginIndex = bi; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the end index. For use by subclasses of Format.
|
2002-07-01 11:04:45 +00:00
|
|
|
* @param ei the new value of the end index
|
2000-03-22 19:19:33 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
void setEndIndex(int32_t ei) { fEndIndex = ei; }
|
|
|
|
|
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: Desired field to determine start and end offsets for.
|
|
|
|
* The meaning depends on the subclass of Format.
|
|
|
|
*/
|
|
|
|
int32_t fField;
|
|
|
|
|
|
|
|
/**
|
2000-04-07 23:10:09 +00:00
|
|
|
* Output: Start offset of field in text.
|
1999-12-28 23:57:50 +00:00
|
|
|
* If the field does not occur in the text, 0 is returned.
|
|
|
|
*/
|
2000-04-07 23:10:09 +00:00
|
|
|
int32_t fBeginIndex;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
2000-04-07 23:10:09 +00:00
|
|
|
* Output: End offset of field in text.
|
1999-12-28 23:57:50 +00:00
|
|
|
* If the field does not occur in the text, 0 is returned.
|
|
|
|
*/
|
2000-04-07 23:10:09 +00:00
|
|
|
int32_t fEndIndex;
|
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 FieldPosition&
|
|
|
|
FieldPosition::operator=(const FieldPosition& copy)
|
|
|
|
{
|
|
|
|
fField = copy.fField;
|
|
|
|
fEndIndex = copy.fEndIndex;
|
|
|
|
fBeginIndex = copy.fBeginIndex;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
inline UBool
|
1999-12-28 23:57:50 +00:00
|
|
|
FieldPosition::operator==(const FieldPosition& copy) const
|
|
|
|
{
|
|
|
|
if( fField != copy.fField ||
|
|
|
|
fEndIndex != copy.fEndIndex ||
|
|
|
|
fBeginIndex != copy.fBeginIndex)
|
|
|
|
return FALSE;
|
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
inline UBool
|
1999-12-28 23:57:50 +00:00
|
|
|
FieldPosition::operator!=(const FieldPosition& copy) const
|
|
|
|
{
|
|
|
|
return !operator==(copy);
|
|
|
|
}
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#endif // _FIELDPOS
|
|
|
|
//eof
|