ICU 50.2 50.2
listformatter.h
Go to the documentation of this file.
1/*
2*******************************************************************************
3*
4* Copyright (C) 2012, International Business Machines
5* Corporation and others. All Rights Reserved.
6*
7*******************************************************************************
8* file name: listformatter.h
9* encoding: US-ASCII
10* tab size: 8 (not used)
11* indentation:4
12*
13* created on: 20120426
14* created by: Umesh P. Nair
15*/
16
17#ifndef __LISTFORMATTER_H__
18#define __LISTFORMATTER_H__
19
20#include "unicode/unistr.h"
21#include "unicode/locid.h"
22
23
25
27class Hashtable;
28
30struct ListFormatData : public UMemory {
31 UnicodeString twoPattern;
32 UnicodeString startPattern;
33 UnicodeString middlePattern;
34 UnicodeString endPattern;
35
36 ListFormatData(const UnicodeString& two, const UnicodeString& start, const UnicodeString& middle, const UnicodeString& end) :
37 twoPattern(two), startPattern(start), middlePattern(middle), endPattern(end) {}
38};
39
40
45
46
57
58 public:
68
78 static ListFormatter* createInstance(const Locale& locale, UErrorCode& errorCode);
79
80
86 virtual ~ListFormatter();
87
88
99 UnicodeString& format(const UnicodeString items[], int32_t n_items,
100 UnicodeString& appendTo, UErrorCode& errorCode) const;
101
109 static void getFallbackLocale(const Locale& in, Locale& out, UErrorCode& errorCode);
110
114 ListFormatter(const ListFormatData& listFormatterData);
115
116 private:
117 static void initializeHash(UErrorCode& errorCode);
118 static void addDataToHash(const char* locale, const char* two, const char* start, const char* middle, const char* end, UErrorCode& errorCode);
119 static const ListFormatData* getListFormatData(const Locale& locale, UErrorCode& errorCode);
120
123
124 ListFormatter& operator = (const ListFormatter&);
125 void addNewString(const UnicodeString& pattern, UnicodeString& originalString,
126 const UnicodeString& newString, UErrorCode& errorCode) const;
127 virtual UClassID getDynamicClassID() const;
128
129 const ListFormatData& data;
130};
131
133
134#endif
static ListFormatter * createInstance(UErrorCode &errorCode)
Creates a ListFormatter appropriate for the default locale.
ListFormatter(const ListFormatData &listFormatterData)
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, 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.
virtual ~ListFormatter()
Destructor.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:182
UMemory is the common ICU base class.
Definition uobject.h:115
UObject is the common ICU "boilerplate" class.
Definition uobject.h:229
virtual UClassID getDynamicClassID() const =0
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:247
C++ API: Locale ID object.
C++ API: Unicode String.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:476
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition utypes.h:357
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:129