ICU 62.1 62.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
30class Hashtable;
31
33struct ListFormatInternal;
34
35/* The following can't be #ifndef U_HIDE_INTERNAL_API, needed for other .h file declarations */
37struct ListFormatData : public UMemory {
38 UnicodeString twoPattern;
39 UnicodeString startPattern;
40 UnicodeString middlePattern;
41 UnicodeString endPattern;
42
43 ListFormatData(const UnicodeString& two, const UnicodeString& start, const UnicodeString& middle, const UnicodeString& end) :
44 twoPattern(two), startPattern(start), middlePattern(middle), endPattern(end) {}
45};
46
47
65
66 public:
67
73
79
89
99 static ListFormatter* createInstance(const Locale& locale, UErrorCode& errorCode);
100
101#ifndef U_HIDE_INTERNAL_API
112 static ListFormatter* createInstance(const Locale& locale, const char* style, UErrorCode& errorCode);
113#endif /* U_HIDE_INTERNAL_API */
114
120 virtual ~ListFormatter();
121
122
133 UnicodeString& format(const UnicodeString items[], int32_t n_items,
134 UnicodeString& appendTo, UErrorCode& errorCode) const;
135
136#ifndef U_HIDE_INTERNAL_API
141 const UnicodeString items[],
142 int32_t n_items,
143 UnicodeString& appendTo,
144 int32_t index,
145 int32_t &offset,
146 UErrorCode& errorCode) const;
150 ListFormatter(const ListFormatData &data, UErrorCode &errorCode);
154 ListFormatter(const ListFormatInternal* listFormatterInternal);
155#endif /* U_HIDE_INTERNAL_API */
156
157 private:
158 static void initializeHash(UErrorCode& errorCode);
159 static const ListFormatInternal* getListFormatInternal(const Locale& locale, const char *style, UErrorCode& errorCode);
160 struct ListPatternsSink;
161 static ListFormatInternal* loadListFormatInternal(const Locale& locale, const char* style, UErrorCode& errorCode);
162
164
165 ListFormatInternal* owned;
166 const ListFormatInternal* data;
167};
168
170
171#endif
An immutable class for formatting a list, using data from CLDR (or supplied separately).
static ListFormatter * createInstance(const Locale &locale, UErrorCode &errorCode)
Creates a ListFormatter appropriate for a locale.
ListFormatter(const ListFormatInternal *listFormatterInternal)
virtual ~ListFormatter()
Destructor.
static ListFormatter * createInstance(UErrorCode &errorCode)
Creates a ListFormatter appropriate for the default locale.
UnicodeString & format(const UnicodeString items[], int32_t n_items, UnicodeString &appendTo, UErrorCode &errorCode) const
Formats a list of strings.
static ListFormatter * createInstance(const Locale &locale, const char *style, UErrorCode &errorCode)
Creates a ListFormatter appropriate for a locale and style.
ListFormatter & operator=(const ListFormatter &other)
Assignment operator.
ListFormatter(const ListFormatter &)
Copy constructor.
UnicodeString & format(const UnicodeString items[], int32_t n_items, UnicodeString &appendTo, int32_t index, int32_t &offset, UErrorCode &errorCode) const
ListFormatter(const ListFormatData &data, UErrorCode &errorCode)
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:188
UMemory is the common ICU base class.
Definition uobject.h:112
UObject is the common ICU "boilerplate" class.
Definition uobject.h:223
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:287
C++ API: Locale ID object.
C++ API: Unicode String.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:396
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition utypes.h:359
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:138
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:137