ICU 64.2  64.2
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.

Draft:
This API may be changed in the future versions and was introduced in ICU 64

Definition at line 40 of file formattedvalue.h.

Constructor & Destructor Documentation

◆ ConstrainedFieldPosition()

icu::ConstrainedFieldPosition::ConstrainedFieldPosition ( )

Initializes a ConstrainedFieldPosition.

By default, the ConstrainedFieldPosition has no iteration constraints.

Draft:
This API may be changed in the future versions and was introduced in ICU 64

◆ ~ConstrainedFieldPosition()

icu::ConstrainedFieldPosition::~ConstrainedFieldPosition ( )
Draft:
This API may be changed in the future versions and was introduced in 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.
Draft:
This API may be changed in the future versions and was introduced in 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.
Draft:
This API may be changed in the future versions and was introduced in 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.
Draft:
This API may be changed in the future versions and was introduced in ICU 64

Definition at line 123 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.
Draft:
This API may be changed in the future versions and was introduced in ICU 64

Definition at line 136 of file formattedvalue.h.

◆ getInt64IterationContext()

int64_t icu::ConstrainedFieldPosition::getInt64IterationContext ( ) const
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.

Returns
The current iteration context from setInt64IterationContext.
Draft:
This API may be changed in the future versions and was introduced in ICU 64

Definition at line 179 of file formattedvalue.h.

References UFIELD_CATEGORY_UNDEFINED.

◆ getLimit()

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

Gets the EXCLUSIVE end index stored for the current position.

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

Returns
The end index saved in the instance.
Draft:
This API may be changed in the future versions and was introduced in ICU 64

Definition at line 160 of file formattedvalue.h.

◆ getStart()

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

Gets the INCLUSIVE start index for the current position.

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

Returns
The start index saved in the instance.
Draft:
This API may be changed in the future versions and was introduced in ICU 64

Definition at line 148 of file formattedvalue.h.

◆ matchesField()

UBool icu::ConstrainedFieldPosition::matchesField ( int32_t  category,
int32_t  field 
) const

Determines whether a given field should be included given the constraints.

Intended to be used by FormattedValue implementations.

Parameters
categoryThe category to test.
fieldThe field to test.
Draft:
This API may be changed in the future versions and was introduced in ICU 64

◆ reset()

void icu::ConstrainedFieldPosition::reset ( )

Resets this ConstrainedFieldPosition to its initial state, as if it were newly created:

  • Removes any constraints that may have been set on the instance.
  • Resets the iteration position.
Draft:
This API may be changed in the future versions and was introduced in ICU 64

◆ setInt64IterationContext()

void icu::ConstrainedFieldPosition::setInt64IterationContext ( int64_t  context)

Sets an int64 that FormattedValue implementations may use for storage.

Intended to be used by FormattedValue implementations.

Parameters
contextThe new iteration context.
Draft:
This API may be changed in the future versions and was introduced in ICU 64

◆ setState()

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!

Parameters
categoryThe new field category.
fieldThe new field.
startThe new inclusive start index.
limitThe new exclusive end index.
Draft:
This API may be changed in the future versions and was introduced in ICU 64

The documentation for this class was generated from the following file: