ICU 50.2 50.2
ListFormatter Class Reference

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

#include <listformatter.h>

Inheritance diagram for ListFormatter:
UObject UMemory

Public Member Functions

virtual ~ListFormatter ()
 Destructor.
 
UnicodeStringformat (const UnicodeString items[], int32_t n_items, UnicodeString &appendTo, UErrorCode &errorCode) const
 Formats a list of strings.
 
 ListFormatter (const ListFormatData &listFormatterData)
 
- Public Member Functions inherited from UObject
virtual ~UObject ()
 Destructor.
 

Static Public Member Functions

static ListFormattercreateInstance (UErrorCode &errorCode)
 Creates a ListFormatter appropriate for the default locale.
 
static ListFormattercreateInstance (const Locale &locale, UErrorCode &errorCode)
 Creates a ListFormatter appropriate for a locale.
 
static void getFallbackLocale (const Locale &in, Locale &out, UErrorCode &errorCode)
 Gets the fallback locale for a given locale.
 

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.

Definition at line 56 of file listformatter.h.

Constructor & Destructor Documentation

◆ ~ListFormatter()

virtual ListFormatter::~ListFormatter ( )
virtual

Destructor.

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

◆ ListFormatter()

ListFormatter::ListFormatter ( const ListFormatData & listFormatterData)
Internal
Do not use. This API is for internal use only. constructor made public for testing.

References ListFormatter().

Referenced by createInstance(), createInstance(), and ListFormatter().

Member Function Documentation

◆ createInstance() [1/2]

static ListFormatter * 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.
Draft
This API may be changed in the future versions and was introduced in ICU 50

References ListFormatter().

◆ createInstance() [2/2]

static ListFormatter * 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.
Draft
This API may be changed in the future versions and was introduced in ICU 50

References ListFormatter().

◆ format()

UnicodeString & 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.
Draft
This API may be changed in the future versions and was introduced in ICU 50

◆ getFallbackLocale()

static void ListFormatter::getFallbackLocale ( const Locale & in,
Locale & out,
UErrorCode & errorCode )
static

Gets the fallback locale for a given locale.

TODO: Consider moving this to the Locale class.

Parameters
inThe input locale.
outThe output locale after fallback.
Internal
Do not use. This API is for internal use only. For testing.

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