ICU 76.1 76.1
|
Represents a span of a string containing a given field. More...
#include <formattedvalue.h>
Public Member Functions | |
ConstrainedFieldPosition () | |
Initializes a ConstrainedFieldPosition. | |
~ConstrainedFieldPosition () | |
void | reset () |
Resets this ConstrainedFieldPosition to its initial state, as if it were newly created: | |
void | constrainCategory (int32_t category) |
Sets a constraint on the field category. | |
void | constrainField (int32_t category, int32_t field) |
Sets a constraint on the category and field. | |
int32_t | getCategory () const |
Gets the field category for the current position. | |
int32_t | getField () const |
Gets the field for the current position. | |
int32_t | getStart () const |
Gets the INCLUSIVE start index for the current position. | |
int32_t | getLimit () const |
Gets the EXCLUSIVE end index stored for the current position. | |
int64_t | getInt64IterationContext () const |
Gets an int64 that FormattedValue implementations may use for storage. | |
void | setInt64IterationContext (int64_t context) |
Sets an int64 that FormattedValue implementations may use for storage. | |
UBool | matchesField (int32_t category, int32_t field) const |
Determines whether a given field should be included given the constraints. | |
void | setState (int32_t category, int32_t field, int32_t start, int32_t limit) |
Sets new values for the primary public getters. | |
Represents a span of a string containing a given field.
This class differs from FieldPosition in the following ways:
This class is not intended for public subclassing.
Definition at line 41 of file formattedvalue.h.
icu::ConstrainedFieldPosition::ConstrainedFieldPosition | ( | ) |
Initializes a ConstrainedFieldPosition.
By default, the ConstrainedFieldPosition has no iteration constraints.
icu::ConstrainedFieldPosition::~ConstrainedFieldPosition | ( | ) |
Sets a constraint on the field category.
When this instance of ConstrainedFieldPosition is passed to FormattedValue::nextPosition, positions are skipped unless they have the given category.
Any previously set constraints are cleared.
For example, to loop over only the number-related fields:
ConstrainedFieldPosition cfpos; cfpos.constrainCategory(UFIELDCATEGORY_NUMBER_FORMAT); while (fmtval.nextPosition(cfpos, status)) { // handle the number-related field position }
Changing the constraint while in the middle of iterating over a FormattedValue does not generally have well-defined behavior.
category | The field category to fix when iterating. |
Sets a constraint on the category and field.
When this instance of ConstrainedFieldPosition is passed to FormattedValue::nextPosition, positions are skipped unless they have the given category and field.
Any previously set constraints are cleared.
For example, to loop over all grouping separators:
ConstrainedFieldPosition cfpos; cfpos.constrainField(UFIELDCATEGORY_NUMBER_FORMAT, UNUM_GROUPING_SEPARATOR_FIELD); while (fmtval.nextPosition(cfpos, status)) { // handle the grouping separator position }
Changing the constraint while in the middle of iterating over a FormattedValue does not generally have well-defined behavior.
category | The field category to fix when iterating. |
field | The field to fix when iterating. |
|
inline |
Gets the field category for the current position.
The return value is well-defined only after FormattedValue::nextPosition returns true.
Definition at line 124 of file formattedvalue.h.
|
inline |
Gets the field for the current position.
The return value is well-defined only after FormattedValue::nextPosition returns true.
Definition at line 137 of file formattedvalue.h.
|
inline |
Gets an int64 that FormattedValue implementations may use for storage.
The initial value is zero.
Users of FormattedValue should not need to call this method.
setInt64IterationContext
. Definition at line 180 of file formattedvalue.h.
|
inline |
Gets the EXCLUSIVE end index stored for the current position.
The return value is well-defined only after FormattedValue::nextPosition returns true.
Definition at line 161 of file formattedvalue.h.
|
inline |
Gets the INCLUSIVE start index for the current position.
The return value is well-defined only after FormattedValue::nextPosition returns true.
Definition at line 149 of file formattedvalue.h.
Determines whether a given field should be included given the constraints.
Intended to be used by FormattedValue implementations.
category | The category to test. |
field | The field to test. |
void icu::ConstrainedFieldPosition::reset | ( | ) |
Resets this ConstrainedFieldPosition to its initial state, as if it were newly created:
Resets the iteration position.
Sets an int64 that FormattedValue implementations may use for storage.
Intended to be used by FormattedValue implementations.
context | The new iteration context. |
void icu::ConstrainedFieldPosition::setState | ( | int32_t | category, |
int32_t | field, | ||
int32_t | start, | ||
int32_t | limit | ||
) |
Sets new values for the primary public getters.
Intended to be used by FormattedValue implementations.
It is up to the implementation to ensure that the user-requested constraints are satisfied. This method does not check!
category | The new field category. |
field | The new field. |
start | The new inclusive start index. |
limit | The new exclusive end index. |