ICU 64.2 64.2

listformatter.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 *
6 * Copyright (C) 2012-2016, International Business Machines
7 * Corporation and others. All Rights Reserved.
8 *
9 *******************************************************************************
10 * file name: listformatter.h
11 * encoding: UTF-8
12 * tab size: 8 (not used)
13 * indentation:4
14 *
15 * created on: 20120426
16 * created by: Umesh P. Nair
17 */
18
19 #ifndef __LISTFORMATTER_H__
20 #define __LISTFORMATTER_H__
21
22 #include "unicode/utypes.h"
23
24 #include "unicode/unistr.h"
25 #include "unicode/locid.h"
26 #include "unicode/formattedvalue.h"
27
28 U_NAMESPACE_BEGIN
29
30 class FieldPositionIterator;
31 class FieldPositionHandler;
32 class FormattedListData;
33 class ListFormatter;
34
36 class Hashtable;
37
39 struct ListFormatInternal;
40
41 /* The following can't be #ifndef U_HIDE_INTERNAL_API, needed for other .h file declarations */
46 struct ListFormatData : public UMemory {
47 UnicodeString twoPattern;
48 UnicodeString startPattern;
49 UnicodeString middlePattern;
50 UnicodeString endPattern;
51
52 ListFormatData(const UnicodeString& two, const UnicodeString& start, const UnicodeString& middle, const UnicodeString& end) :
53 twoPattern(two), startPattern(start), middlePattern(middle), endPattern(end) {}
54 };
64 #if !UCONFIG_NO_FORMATTING
65 #ifndef U_HIDE_DRAFT_API
66
82 class U_I18N_API FormattedList : public UMemory, public FormattedValue {
83 public:
88 FormattedList() : fData(nullptr), fErrorCode(U_INVALID_STATE_ERROR) {}
89
94 FormattedList(FormattedList&& src) U_NOEXCEPT;
95
100 virtual ~FormattedList() U_OVERRIDE;
101
103 FormattedList(const FormattedList&) = delete;
104
106 FormattedList& operator=(const FormattedList&) = delete;
107
112 FormattedList& operator=(FormattedList&& src) U_NOEXCEPT;
113
115 UnicodeString toString(UErrorCode& status) const U_OVERRIDE;
116
118 UnicodeString toTempString(UErrorCode& status) const U_OVERRIDE;
119
121 Appendable &appendTo(Appendable& appendable, UErrorCode& status) const U_OVERRIDE;
122
124 UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const U_OVERRIDE;
125
126 private:
127 FormattedListData *fData;
128 UErrorCode fErrorCode;
129 explicit FormattedList(FormattedListData *results)
130 : fData(results), fErrorCode(U_ZERO_ERROR) {}
131 explicit FormattedList(UErrorCode errorCode)
132 : fData(nullptr), fErrorCode(errorCode) {}
133 friend class ListFormatter;
134 };
135 #endif /* U_HIDE_DRAFT_API */
136 #endif // !UCONFIG_NO_FORMATTING
137
138
149 class U_I18N_API ListFormatter : public UObject{
150
151 public:
152
157 ListFormatter(const ListFormatter&);
158
163 ListFormatter& operator=(const ListFormatter& other);
164
173 static ListFormatter* createInstance(UErrorCode& errorCode);
174
184 static ListFormatter* createInstance(const Locale& locale, UErrorCode& errorCode);
185
186 #ifndef U_HIDE_INTERNAL_API
187
197 static ListFormatter* createInstance(const Locale& locale, const char* style, UErrorCode& errorCode);
198 #endif /* U_HIDE_INTERNAL_API */
199
205 virtual ~ListFormatter();
206
207
218 UnicodeString& format(const UnicodeString items[], int32_t n_items,
219 UnicodeString& appendTo, UErrorCode& errorCode) const;
220
221 #ifndef U_HIDE_DRAFT_API
222
237 UnicodeString& format(const UnicodeString items[], int32_t n_items,
238 UnicodeString & appendTo, FieldPositionIterator* posIter,
239 UErrorCode& errorCode) const;
240 #endif /* U_HIDE_DRAFT_API */
241
242 #if !UCONFIG_NO_FORMATTING
243 #ifndef U_HIDE_DRAFT_API
244
255 FormattedList formatStringsToValue(
256 const UnicodeString items[],
257 int32_t n_items,
258 UErrorCode& errorCode) const;
259 #endif /* U_HIDE_DRAFT_API */
260 #endif // !UCONFIG_NO_FORMATTING
261
262 #ifndef U_HIDE_INTERNAL_API
263
266 UnicodeString& format(
267 const UnicodeString items[],
268 int32_t n_items,
269 UnicodeString& appendTo,
270 int32_t index,
271 int32_t &offset,
272 UErrorCode& errorCode) const;
276 ListFormatter(const ListFormatData &data, UErrorCode &errorCode);
280 ListFormatter(const ListFormatInternal* listFormatterInternal);
281 #endif /* U_HIDE_INTERNAL_API */
282
283 private:
284 static void initializeHash(UErrorCode& errorCode);
285 static const ListFormatInternal* getListFormatInternal(const Locale& locale, const char *style, UErrorCode& errorCode);
286 struct ListPatternsSink;
287 static ListFormatInternal* loadListFormatInternal(const Locale& locale, const char* style, UErrorCode& errorCode);
288
289 UnicodeString& format_(
290 const UnicodeString items[], int32_t n_items, UnicodeString& appendTo,
291 int32_t index, int32_t &offset, FieldPositionHandler* handler, UErrorCode& errorCode) const;
292
293 ListFormatter();
294
295 ListFormatInternal* owned;
296 const ListFormatInternal* data;
297 };
298
299 U_NAMESPACE_END
300
301 #endif // __LISTFORMATTER_H__
formattedvalue.h
C++ API: Abstract operations for localized strings.
U_OVERRIDE
#define U_OVERRIDE
Defined to the C++11 "override" keyword if available.
Definition: umachine.h:129
icu::FormattedList::FormattedList
FormattedList()
Default constructor; makes an empty FormattedList.
Definition: listformatter.h:88
unistr.h
C++ API: Unicode String.
U_ZERO_ERROR
No error, no warning.
Definition: utypes.h:435
icu::FormattedValue
An abstract formatted value: a string with associated field attributes.
Definition: formattedvalue.h:241
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:301
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
icu::FieldPositionIterator
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:55
icu::ListFormatter
An immutable class for formatting a list, using data from CLDR (or supplied separately).
Definition: listformatter.h:149
icu::ConstrainedFieldPosition
Represents a span of a string containing a given field.
Definition: formattedvalue.h:40
U_NOEXCEPT
#define U_NOEXCEPT
"noexcept" if supported, otherwise empty.
Definition: platform.h:503
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition: utypes.h:401
locid.h
C++ API: Locale ID object.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::FormattedList
An immutable class containing the result of a list formatting operation.
Definition: listformatter.h:82
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:289
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
icu::UMemory
UMemory is the common ICU base class.
Definition: uobject.h:112
U_INVALID_STATE_ERROR
Requested operation can not be completed with ICU in its current state.
Definition: utypes.h:464
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225
icu::Appendable
Base class for objects to which Unicode characters and strings can be appended.
Definition: appendable.h:51
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:192