ICU 64.2  64.2
Public Member Functions | Static Public Member Functions
icu::ListFormatter Class Reference

An immutable class for formatting a list, using data from CLDR (or supplied separately). More...

#include <listformatter.h>

Inheritance diagram for icu::ListFormatter:
icu::UObject icu::UMemory

Public Member Functions

 ListFormatter (const ListFormatter &)
 Copy constructor. More...
 
ListFormatteroperator= (const ListFormatter &other)
 Assignment operator. More...
 
virtual ~ListFormatter ()
 Destructor. More...
 
UnicodeStringformat (const UnicodeString items[], int32_t n_items, UnicodeString &appendTo, UErrorCode &errorCode) const
 Formats a list of strings. More...
 
UnicodeStringformat (const UnicodeString items[], int32_t n_items, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &errorCode) const
 Format a list of strings. More...
 
FormattedList formatStringsToValue (const UnicodeString items[], int32_t n_items, UErrorCode &errorCode) const
 Formats a list of strings to a FormattedList, which exposes field position information. More...
 
UnicodeStringformat (const UnicodeString items[], int32_t n_items, UnicodeString &appendTo, int32_t index, int32_t &offset, UErrorCode &errorCode) const
 
 ListFormatter (const ListFormatData &data, UErrorCode &errorCode)
 
 ListFormatter (const ListFormatInternal *listFormatterInternal)
 
- Public Member Functions inherited from icu::UObject
virtual ~UObject ()
 Destructor. More...
 
virtual UClassID getDynamicClassID () const
 ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class. More...
 

Static Public Member Functions

static ListFormattercreateInstance (UErrorCode &errorCode)
 Creates a ListFormatter appropriate for the default locale. More...
 
static ListFormattercreateInstance (const Locale &locale, UErrorCode &errorCode)
 Creates a ListFormatter appropriate for a locale. More...
 
static ListFormattercreateInstance (const Locale &locale, const char *style, UErrorCode &errorCode)
 Creates a ListFormatter appropriate for a locale and style. More...
 

Detailed Description

An immutable class for formatting a list, using data from CLDR (or supplied separately).

Example: Input data ["Alice", "Bob", "Charlie", "Delta"] will be formatted as "Alice, Bob, Charlie and Delta" in English.

The ListFormatter class is not intended for public subclassing.

Stable:
ICU 50

Definition at line 149 of file listformatter.h.

Constructor & Destructor Documentation

◆ ListFormatter() [1/3]

icu::ListFormatter::ListFormatter ( const ListFormatter )

Copy constructor.

Stable:
ICU 52

◆ ~ListFormatter()

virtual icu::ListFormatter::~ListFormatter ( )
virtual

Destructor.

Stable:
ICU 50

◆ ListFormatter() [2/3]

icu::ListFormatter::ListFormatter ( const ListFormatData &  data,
UErrorCode errorCode 
)
Internal:
Do not use.

This API is for internal use only. constructor made public for testing.

◆ ListFormatter() [3/3]

icu::ListFormatter::ListFormatter ( const ListFormatInternal *  listFormatterInternal)
Internal:
Do not use.

This API is for internal use only. constructor made public for testing.

Member Function Documentation

◆ createInstance() [1/3]

static ListFormatter* icu::ListFormatter::createInstance ( UErrorCode errorCode)
static

Creates a ListFormatter appropriate for the default locale.

Parameters
errorCodeICU error code, set if no data available for default locale.
Returns
Pointer to a ListFormatter object for the default locale, created from internal data derived from CLDR data.
Stable:
ICU 50

◆ createInstance() [2/3]

static ListFormatter* icu::ListFormatter::createInstance ( const Locale locale,
UErrorCode errorCode 
)
static

Creates a ListFormatter appropriate for a locale.

Parameters
localeThe locale.
errorCodeICU error code, set if no data available for the given locale.
Returns
A ListFormatter object created from internal data derived from CLDR data.
Stable:
ICU 50

◆ createInstance() [3/3]

static ListFormatter* icu::ListFormatter::createInstance ( const Locale locale,
const char *  style,
UErrorCode errorCode 
)
static

Creates a ListFormatter appropriate for a locale and style.

Parameters
localeThe locale.
stylethe style, either "standard", "or", "unit", "unit-narrow", or "unit-short"
errorCodeICU error code, set if no data available for the given locale.
Returns
A ListFormatter object created from internal data derived from CLDR data.
Internal:
Do not use. This API is for internal use only.

◆ format() [1/3]

UnicodeString& icu::ListFormatter::format ( const UnicodeString  items[],
int32_t  n_items,
UnicodeString appendTo,
UErrorCode errorCode 
) const

Formats a list of strings.

Parameters
itemsAn array of strings to be combined and formatted.
n_itemsLength of the array items.
appendToThe string to which the result should be appended to.
errorCodeICU error code, set if there is an error.
Returns
Formatted string combining the elements of items, appended to appendTo.
Stable:
ICU 50

◆ format() [2/3]

UnicodeString& icu::ListFormatter::format ( const UnicodeString  items[],
int32_t  n_items,
UnicodeString appendTo,
FieldPositionIterator posIter,
UErrorCode errorCode 
) const

Format a list of strings.

Parameters
itemsAn array of strings to be combined and formatted.
n_itemsLength of the array items.
appendToThe string to which the formatted result will be appended.
posIterOn return, can be used to iterate over positions of fields generated by this format call. Field values are defined in UListFormatterField. Can be NULL.
errorCodeICU error code returned here.
Returns
Formatted string combining the elements of items, appended to appendTo.
Draft:
This API may be changed in the future versions and was introduced in ICU 63

◆ format() [3/3]

UnicodeString& icu::ListFormatter::format ( const UnicodeString  items[],
int32_t  n_items,
UnicodeString appendTo,
int32_t  index,
int32_t &  offset,
UErrorCode errorCode 
) const
Internal:
Do not use.

This API is for internal use only. for MeasureFormat

◆ formatStringsToValue()

FormattedList icu::ListFormatter::formatStringsToValue ( const UnicodeString  items[],
int32_t  n_items,
UErrorCode errorCode 
) const

Formats a list of strings to a FormattedList, which exposes field position information.

The FormattedList contains more information than a FieldPositionIterator.

Parameters
itemsAn array of strings to be combined and formatted.
n_itemsLength of the array items.
errorCodeICU error code returned here.
Returns
A FormattedList containing field information.
Draft:
This API may be changed in the future versions and was introduced in ICU 64

◆ operator=()

ListFormatter& icu::ListFormatter::operator= ( const ListFormatter other)

Assignment operator.

Stable:
ICU 52

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