ICU 77.1  77.1
Public Member Functions
icu::ConstrainedFieldPosition Class Reference

Represents a span of a string containing a given field. More...

#include <formattedvalue.h>

Inheritance diagram for icu::ConstrainedFieldPosition:
icu::UMemory

Public Member Functions

 ConstrainedFieldPosition ()
 Initializes a ConstrainedFieldPosition. More...
 
 ~ConstrainedFieldPosition ()
 
void reset ()
 Resets this ConstrainedFieldPosition to its initial state, as if it were newly created: More...
 
void constrainCategory (int32_t category)
 Sets a constraint on the field category. More...
 
void constrainField (int32_t category, int32_t field)
 Sets a constraint on the category and field. More...
 
int32_t getCategory () const
 Gets the field category for the current position. More...
 
int32_t getField () const
 Gets the field for the current position. More...
 
int32_t getStart () const
 Gets the INCLUSIVE start index for the current position. More...
 
int32_t getLimit () const
 Gets the EXCLUSIVE end index stored for the current position. More...
 
int64_t getInt64IterationContext () const
 Gets an int64 that FormattedValue implementations may use for storage. More...
 
void setInt64IterationContext (int64_t context)
 Sets an int64 that FormattedValue implementations may use for storage. More...
 
UBool matchesField (int32_t category, int32_t field) const
 Determines whether a given field should be included given the constraints. More...
 
void setState (int32_t category, int32_t field, int32_t start, int32_t limit)
 Sets new values for the primary public getters. More...
 

Detailed Description

Represents a span of a string containing a given field.

This class differs from FieldPosition in the following ways:

  1. It has information on the field category.
  2. It allows you to set constraints to use when iterating over field positions.
  3. It is used for the newer FormattedValue APIs.

This class is not intended for public subclassing.

Stable:
ICU 64

Definition at line 41 of file formattedvalue.h.

Constructor & Destructor Documentation

◆ ConstrainedFieldPosition()

icu::ConstrainedFieldPosition::ConstrainedFieldPosition ( )

Initializes a ConstrainedFieldPosition.

By default, the ConstrainedFieldPosition has no iteration constraints.

Stable:
ICU 64

◆ ~ConstrainedFieldPosition()

icu::ConstrainedFieldPosition::~ConstrainedFieldPosition ( )
Stable:
ICU 64

Member Function Documentation

◆ constrainCategory()

void icu::ConstrainedFieldPosition::constrainCategory ( int32_t  category)

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.

Parameters
categoryThe field category to fix when iterating.
Stable:
ICU 64

◆ constrainField()

void icu::ConstrainedFieldPosition::constrainField ( int32_t  category,
int32_t  field 
)

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.

Parameters
categoryThe field category to fix when iterating.
fieldThe field to fix when iterating.
Stable:
ICU 64

◆ getCategory()

int32_t icu::ConstrainedFieldPosition::getCategory ( ) const
inline

Gets the field category for the current position.

The return value is well-defined only after FormattedValue::nextPosition returns true.

Returns
The field category saved in the instance.
Stable:
ICU 64

Definition at line 124 of file formattedvalue.h.

◆ getField()

int32_t icu::ConstrainedFieldPosition::getField ( ) const
inline

Gets the field for the current position.

The return value is well-defined only after FormattedValue::nextPosition returns true.

Returns
The field saved in the instance.
Stable:
ICU 64

Definition at line 137 of file formattedvalue.h.