ICU 63.1  63.1
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 
28 
29 class FieldPositionIterator;
30 class FieldPositionHandler;
31 
33 class Hashtable;
34 
36 struct ListFormatInternal;
37 
38 /* The following can't be #ifndef U_HIDE_INTERNAL_API, needed for other .h file declarations */
43 struct ListFormatData : public UMemory {
44  UnicodeString twoPattern;
45  UnicodeString startPattern;
46  UnicodeString middlePattern;
47  UnicodeString endPattern;
48 
49  ListFormatData(const UnicodeString& two, const UnicodeString& start, const UnicodeString& middle, const UnicodeString& end) :
50  twoPattern(two), startPattern(start), middlePattern(middle), endPattern(end) {}
51 };
72 
73  public:
74 
80 
85  ListFormatter& operator=(const ListFormatter& other);
86 
95  static ListFormatter* createInstance(UErrorCode& errorCode);
96 
106  static ListFormatter* createInstance(const Locale& locale, UErrorCode& errorCode);
107 
108 #ifndef U_HIDE_INTERNAL_API
109 
119  static ListFormatter* createInstance(const Locale& locale, const char* style, UErrorCode& errorCode);
120 #endif /* U_HIDE_INTERNAL_API */
121 
127  virtual ~ListFormatter();
128 
129 
140  UnicodeString& format(const UnicodeString items[], int32_t n_items,
141  UnicodeString& appendTo, UErrorCode& errorCode) const;
142 
143 #ifndef U_HIDE_DRAFT_API
144 
159  UnicodeString& format(const UnicodeString items[], int32_t n_items,
160  UnicodeString & appendTo, FieldPositionIterator* posIter,
161  UErrorCode& errorCode) const;
162 #endif /* U_HIDE_DRAFT_API */
163 
164 #ifndef U_HIDE_INTERNAL_API
165 
168  UnicodeString& format(
169  const UnicodeString items[],
170  int32_t n_items,
171  UnicodeString& appendTo,
172  int32_t index,
173  int32_t &offset,
174  UErrorCode& errorCode) const;
178  ListFormatter(const ListFormatData &data, UErrorCode &errorCode);
182  ListFormatter(const ListFormatInternal* listFormatterInternal);
183 #endif /* U_HIDE_INTERNAL_API */
184 
185  private:
186  static void initializeHash(UErrorCode& errorCode);
187  static const ListFormatInternal* getListFormatInternal(const Locale& locale, const char *style, UErrorCode& errorCode);
188  struct ListPatternsSink;
189  static ListFormatInternal* loadListFormatInternal(const Locale& locale, const char* style, UErrorCode& errorCode);
190 
191  UnicodeString& format_(
192  const UnicodeString items[], int32_t n_items, UnicodeString& appendTo,
193  int32_t index, int32_t &offset, FieldPositionHandler* handler, UErrorCode& errorCode) const;
194 
195  ListFormatter();
196 
197  ListFormatInternal* owned;
198  const ListFormatInternal* data;
199 };
200 
202 
203 #endif
C++ API: Unicode String.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:55
An immutable class for formatting a list, using data from CLDR (or supplied separately).
Definition: listformatter.h:71
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:401
C++ API: Locale ID object.
Basic definitions for ICU, for both C and C++ APIs.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:289
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:220
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:192