ICU 78.1 78.1 |
FieldPosition is a simple class used byFormat and its subclasses to identify fields in formatted output.More...
#include <fieldpos.h>

Public Types | |
| enum | {DONT_CARE = -1 } |
| DONT_CARE may be specified as the field to indicate that the caller doesn't need to specify a field.More... | |
Public Member Functions | |
| FieldPosition () | |
| Creates aFieldPosition object with a non-specified field.More... | |
| FieldPosition (int32_t field) | |
| Creates aFieldPosition object for the given field.More... | |
| FieldPosition (constFieldPosition ©) | |
| Copy constructor.More... | |
| virtual | ~FieldPosition () |
| Destructor.More... | |
| FieldPosition & | operator= (constFieldPosition ©) |
| Assignment operator.More... | |
| bool | operator== (constFieldPosition &that) const |
| Equality operator.More... | |
| bool | operator!= (constFieldPosition &that) const |
| Equality operator.More... | |
| FieldPosition * | clone () const |
| Clone this object.More... | |
| int32_t | getField () const |
| Retrieve the field identifier.More... | |
| int32_t | getBeginIndex () const |
| Retrieve the index of the first character in the requested field.More... | |
| int32_t | getEndIndex () const |
| Retrieve the index of the character following the last character in the requested field.More... | |
| void | setField (int32_t f) |
| Set the field.More... | |
| void | setBeginIndex (int32_t bi) |
| Set the begin index.More... | |
| void | setEndIndex (int32_t ei) |
| Set the end index.More... | |
| virtualUClassID | getDynamicClassID () const override |
| ICU "poor man's RTTI", returns a UClassID for the actual class.More... | |
Public Member Functions inherited fromicu::UObject | |
| virtual | ~UObject () |
| Destructor.More... | |
Static Public Member Functions | |
| staticUClassID | getStaticClassID () |
| ICU "poor man's RTTI", returns a UClassID for this class.More... | |
FieldPosition is a simple class used byFormat 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 ofFormat. SeeERA_FIELD and its friends inDateFormat 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 theformat method in the variousFormat classes requires aFieldPosition object as an argument. You use thisformat method to perform partial formatting or to get information about the formatted output (such as the position of a field).
TheFieldPosition class is not intended for public subclassing.
Below is an example of usingFieldPosition to aid alignment of an array of formatted floating-point numbers on their decimal points:
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);constint tempLen = 20;char temp[tempLen];for (int i=0; i<dNumSize; i++) {UnicodeString buf;char fmtText[tempLen];ToCharString(fmt->format(doubleNum[i], buf, pos), fmtText);for (int j=0; j<tempLen; j++) temp[j] =' ';// clear with spacestemp[__min(tempLen, tempLen-pos.getEndIndex())] ='\0';cout << temp << fmtText << endl;}delete fmt;static NumberFormat * createInstance(UErrorCode &)Create a default style NumberFormat for the current default locale.@ INTEGER_FIELDThese constants are provided for backwards compatibility only.Definition:numfmt.h:267
<p<blockquote>
The code will generate the following output:
123,456,789.000-12,345,678.9001,234,567.880-123,456.78912,345.678-1,234.567123.456-12.3451.234
Definition at line110 of filefieldpos.h.
| anonymous enum |
DONT_CARE may be specified as the field to indicate that the caller doesn't need to specify a field.
Definition at line117 of filefieldpos.h.
| inline |
Creates aFieldPosition object with a non-specified field.
Definition at line123 of filefieldpos.h.
| inline |
Creates aFieldPosition object for the given field.
Fields are identified by constants, whose names typically end with _FIELD, in the various subclasses ofFormat.
Definition at line137 of filefieldpos.h.
| inline |
Copy constructor.
| copy | the object to be copied from. |
Definition at line145 of filefieldpos.h.
| virtual |
Destructor.
| FieldPosition* icu::FieldPosition::clone | ( | ) | const |
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.
| inline |
Retrieve the index of the first character in the requested field.
Definition at line202 of filefieldpos.h.
| overridevirtual |
ICU "poor man's RTTI", returns a UClassID for the actual class.
Reimplemented fromicu::UObject.
| inline |
Retrieve the index of the character following the last character in the requested field.
Definition at line211 of filefieldpos.h.
| inline |
Retrieve the field identifier.
Definition at line195 of filefieldpos.h.
| static |
ICU "poor man's RTTI", returns a UClassID for this class.
| inline |
Equality operator.
| that | the object to be compared with. |
Definition at line286 of filefieldpos.h.
Referencesicu::operator==().
| inline |
Assignment operator.
| copy | the object to be copied from. |
Definition at line269 of filefieldpos.h.
| inline |
Equality operator.
| that | the object to be compared with. |
Definition at line278 of filefieldpos.h.
| inline |
Set the begin index.
For use by subclasses ofFormat.
| bi | the new value of the begin index |
Definition at line225 of filefieldpos.h.
| inline |
Set the end index.
For use by subclasses ofFormat.
| ei | the new value of the end index |
Definition at line232 of filefieldpos.h.
| inline |
Set the field.
| f | the new value of the field. |
Definition at line218 of filefieldpos.h.