class FieldPosition

Defined at line 110 of file ../../third_party/icu/latest/source/i18n/unicode/fieldpos.h

FieldPosition

is a simple class used by

Format

and its subclasses to identify fields in formatted output. Fields are

identified by constants, whose names typically end with

_FIELD

,

defined in the various subclasses of

Format

. See

ERA_FIELD

and its friends in

DateFormat

for

an example.

FieldPosition

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.

One version of the

format

method in the various

Format

classes requires a

FieldPosition

object as an argument. You use this

format

method

to perform partial formatting or to get information about the

formatted output (such as the position of a field).

The FieldPosition class is not intended for public subclassing.

Below is an example of using

FieldPosition

to aid

alignment of an array of formatted floating-point numbers on

their decimal points:

The code will generate the following output:

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];
                                        
                                               for (int i=0; i<dNumSize; i++) {
                                                   FieldPosition pos(NumberFormat::INTEGER_FIELD);
                                                   UnicodeString buf;
                                                   char fmtText[tempLen];
                                                   ToCharString(fmt->format(doubleNum[i], buf, pos), fmtText);
                                                   for (int j=0; j<tempLen; j++) temp[j] = ' '; // clear with spaces
                                                   temp[__min(tempLen, tempLen-pos.getEndIndex())] = '\0';
                                                   cout << temp << fmtText   << endl;
                                               }
                                               delete fmt;
                                    
                                
                                    
                                                   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
                                    
                                

Public Methods

void FieldPosition ()

Creates a FieldPosition object with a non-specified field.

ICU 2.0

Defined at line 123 of file ../../third_party/icu/latest/source/i18n/unicode/fieldpos.h

void FieldPosition (int32_t field)

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.

Defined at line 137 of file ../../third_party/icu/latest/source/i18n/unicode/fieldpos.h

void FieldPosition (const FieldPosition & copy)

Copy constructor

Parameters

copy the object to be copied from. ICU 2.0

Defined at line 145 of file ../../third_party/icu/latest/source/i18n/unicode/fieldpos.h

void ~FieldPosition ()

Destructor

ICU 2.0

FieldPosition & operator= (const FieldPosition & copy)

Assignment operator

Parameters

copy the object to be copied from. ICU 2.0

Defined at line 268 of file ../../third_party/icu/latest/source/i18n/unicode/fieldpos.h

bool operator== (const FieldPosition & that)

Equality operator.

Parameters

that the object to be compared with.

Returns

true if the two field positions are equal, false otherwise.

ICU 2.0

Defined at line 277 of file ../../third_party/icu/latest/source/i18n/unicode/fieldpos.h

bool operator!= (const FieldPosition & that)

Equality operator.

Parameters

that the object to be compared with.

Returns

true if the two field positions are not equal, false otherwise.

ICU 2.0

Defined at line 285 of file ../../third_party/icu/latest/source/i18n/unicode/fieldpos.h

FieldPosition * clone ()

Clone this object.

Clones can be used concurrently in multiple threads.

If an error occurs, then nullptr is returned.

The caller must delete the clone.

Returns

a clone of this object

int32_t getField ()

Retrieve the field identifier.

Returns

the field identifier.

ICU 2.0

Defined at line 195 of file ../../third_party/icu/latest/source/i18n/unicode/fieldpos.h

int32_t getBeginIndex ()

Retrieve the index of the first character in the requested field.

Returns

the index of the first character in the requested field.

ICU 2.0

Defined at line 202 of file ../../third_party/icu/latest/source/i18n/unicode/fieldpos.h

UClassID getDynamicClassID ()

ICU "poor man's RTTI", returns a UClassID for the actual class.

ICU 2.2

int32_t getEndIndex ()

Retrieve the index of the character following the last character in the

requested field.

Returns

the index of the character following the last character in the

requested field.

ICU 2.0

Defined at line 211 of file ../../third_party/icu/latest/source/i18n/unicode/fieldpos.h

UClassID getStaticClassID ()

ICU "poor man's RTTI", returns a UClassID for this class.

ICU 2.2

void setField (int32_t f)

Set the field.

Parameters

f the new value of the field. ICU 2.0

Defined at line 218 of file ../../third_party/icu/latest/source/i18n/unicode/fieldpos.h

void setBeginIndex (int32_t bi)

Set the begin index. For use by subclasses of Format.

Parameters

bi the new value of the begin index ICU 2.0

Defined at line 225 of file ../../third_party/icu/latest/source/i18n/unicode/fieldpos.h

void setEndIndex (int32_t ei)

Set the end index. For use by subclasses of Format.

Parameters

ei the new value of the end index ICU 2.0

Defined at line 232 of file ../../third_party/icu/latest/source/i18n/unicode/fieldpos.h

Enumerations

enum 
Name Value
DONT_CARE -1

DONT_CARE may be specified as the field to indicate that the

caller doesn't need to specify a field.

ICU 2.0

Defined at line 117 of file ../../third_party/icu/latest/source/i18n/unicode/fieldpos.h