2 *******************************************************************************
4 * Copyright (C) 2012-2014, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: listformatter.h
10 * tab size: 8 (not used)
13 * created on: 20120426
14 * created by: Umesh P. Nair
17 #ifndef __LISTFORMATTER_H__
18 #define __LISTFORMATTER_H__
20 #include "unicode/utypes.h"
22 #include "unicode/unistr.h"
23 #include "unicode/locid.h"
31 struct ListFormatInternal
;
33 /* The following can't be #ifndef U_HIDE_INTERNAL_API, needed for other .h file declarations */
35 struct ListFormatData
: public UMemory
{
36 UnicodeString twoPattern
;
37 UnicodeString startPattern
;
38 UnicodeString middlePattern
;
39 UnicodeString endPattern
;
41 ListFormatData(const UnicodeString
& two
, const UnicodeString
& start
, const UnicodeString
& middle
, const UnicodeString
& end
) :
42 twoPattern(two
), startPattern(start
), middlePattern(middle
), endPattern(end
) {}
48 * \brief C++ API: API for formatting a list.
53 * An immutable class for formatting a list, using data from CLDR (or supplied
56 * Example: Input data ["Alice", "Bob", "Charlie", "Delta"] will be formatted
57 * as "Alice, Bob, Charlie and Delta" in English.
59 * The ListFormatter class is not intended for public subclassing.
62 class U_COMMON_API ListFormatter
: public UObject
{
70 ListFormatter(const ListFormatter
&);
73 * Assignment operator.
76 ListFormatter
& operator=(const ListFormatter
& other
);
79 * Creates a ListFormatter appropriate for the default locale.
81 * @param errorCode ICU error code, set if no data available for default locale.
82 * @return Pointer to a ListFormatter object for the default locale,
83 * created from internal data derived from CLDR data.
86 static ListFormatter
* createInstance(UErrorCode
& errorCode
);
89 * Creates a ListFormatter appropriate for a locale.
91 * @param locale The locale.
92 * @param errorCode ICU error code, set if no data available for the given locale.
93 * @return A ListFormatter object created from internal data derived from
97 static ListFormatter
* createInstance(const Locale
& locale
, UErrorCode
& errorCode
);
99 #ifndef U_HIDE_INTERNAL_API
101 * Creates a ListFormatter appropriate for a locale and style.
103 * @param locale The locale.
104 * @param style the style, either "standard", "duration", or "duration-short"
105 * @param errorCode ICU error code, set if no data available for the given locale.
106 * @return A ListFormatter object created from internal data derived from
110 static ListFormatter
* createInstance(const Locale
& locale
, const char* style
, UErrorCode
& errorCode
);
111 #endif /* U_HIDE_INTERNAL_API */
118 virtual ~ListFormatter();
122 * Formats a list of strings.
124 * @param items An array of strings to be combined and formatted.
125 * @param n_items Length of the array items.
126 * @param appendTo The string to which the result should be appended to.
127 * @param errorCode ICU error code, set if there is an error.
128 * @return Formatted string combining the elements of items, appended to appendTo.
131 UnicodeString
& format(const UnicodeString items
[], int32_t n_items
,
132 UnicodeString
& appendTo
, UErrorCode
& errorCode
) const;
134 #ifndef U_HIDE_INTERNAL_API
136 @internal for MeasureFormat
138 UnicodeString
& format(
139 const UnicodeString items
[],
141 UnicodeString
& appendTo
,
144 UErrorCode
& errorCode
) const;
146 * @internal constructor made public for testing.
148 ListFormatter(const ListFormatData
&data
);
150 * @internal constructor made public for testing.
152 ListFormatter(const ListFormatInternal
* listFormatterInternal
);
153 #endif /* U_HIDE_INTERNAL_API */
156 static void initializeHash(UErrorCode
& errorCode
);
157 static const ListFormatInternal
* getListFormatInternal(const Locale
& locale
, const char *style
, UErrorCode
& errorCode
);
161 ListFormatInternal
* owned
;
162 const ListFormatInternal
* data
;