ICU 58.2 58.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

tmutfmt.h
Go to the documentation of this file.
1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 * Copyright (C) 2008-2014, Google, International Business Machines Corporation
6 * and others. All Rights Reserved.
7 *******************************************************************************
8 */
9
10 #ifndef __TMUTFMT_H__
11 #define __TMUTFMT_H__
12
13 #include "unicode/utypes.h"
14
21 #if !UCONFIG_NO_FORMATTING
22 #ifndef U_HIDE_DEPRECATED_API
23
24 #include "unicode/unistr.h"
25 #include "unicode/tmunit.h"
26 #include "unicode/tmutamt.h"
27 #include "unicode/measfmt.h"
28 #include "unicode/numfmt.h"
29 #include "unicode/plurrule.h"
30
31
39 enum UTimeUnitFormatStyle {
41 UTMUTFMT_FULL_STYLE,
43 UTMUTFMT_ABBREVIATED_STYLE,
45 UTMUTFMT_FORMAT_STYLE_COUNT
46 };
47 typedef enum UTimeUnitFormatStyle UTimeUnitFormatStyle;
50 U_NAMESPACE_BEGIN
51
52 class Hashtable;
53 class UVector;
54
55 struct TimeUnitFormatReadSink;
56
87 class U_I18N_API TimeUnitFormat: public MeasureFormat {
88 public:
89
95 TimeUnitFormat(UErrorCode& status);
96
101 TimeUnitFormat(const Locale& locale, UErrorCode& status);
102
107 TimeUnitFormat(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status);
108
113 TimeUnitFormat(const TimeUnitFormat&);
114
119 virtual ~TimeUnitFormat();
120
127 virtual Format* clone(void) const;
128
133 TimeUnitFormat& operator=(const TimeUnitFormat& other);
134
142 UBool operator!=(const Format& other) const;
143
150 void setLocale(const Locale& locale, UErrorCode& status);
151
152
159 void setNumberFormat(const NumberFormat& format, UErrorCode& status);
160
166 virtual void parseObject(const UnicodeString& source,
167 Formattable& result,
168 ParsePosition& pos) const;
169
181 static UClassID U_EXPORT2 getStaticClassID(void);
182
194 virtual UClassID getDynamicClassID(void) const;
195
196 private:
197 Hashtable* fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT];
198 UTimeUnitFormatStyle fStyle;
199
200 void create(UTimeUnitFormatStyle style, UErrorCode& status);
201
202 // it might actually be simpler to make them Decimal Formats later.
203 // initialize all private data members
204 void setup(UErrorCode& status);
205
206 // initialize data member without fill in data for fTimeUnitToCountToPattern
207 void initDataMembers(UErrorCode& status);
208
209 // initialize fTimeUnitToCountToPatterns from current locale's resource.
210 void readFromCurrentLocale(UTimeUnitFormatStyle style, const char* key, const UVector& pluralCounts,
211 UErrorCode& status);
212
213 // check completeness of fTimeUnitToCountToPatterns against all time units,
214 // and all plural rules, fill in fallback as necessary.
215 void checkConsistency(UTimeUnitFormatStyle style, const char* key, UErrorCode& status);
216
217 // fill in fTimeUnitToCountToPatterns from locale fall-back chain
218 void searchInLocaleChain(UTimeUnitFormatStyle style, const char* key, const char* localeName,
219 TimeUnit::UTimeUnitFields field, const UnicodeString&,
220 const char*, Hashtable*, UErrorCode&);
221
222 // initialize hash table
223 Hashtable* initHash(UErrorCode& status);
224
225 // delete hash table
226 void deleteHash(Hashtable* htable);
227
228 // copy hash table
229 void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status);
230 // get time unit name, such as "year", from time unit field enum, such as
231 // UTIMEUNIT_YEAR.
232 static const char* getTimeUnitName(TimeUnit::UTimeUnitFields field, UErrorCode& status);
233
234 friend struct TimeUnitFormatReadSink;
235 };
236
237 inline UBool
238 TimeUnitFormat::operator!=(const Format& other) const {
239 return !operator==(other);
240 }
241
242 U_NAMESPACE_END
243
244 #endif /* U_HIDE_DEPRECATED_API */
245 #endif /* #if !UCONFIG_NO_FORMATTING */
246
247 #endif // __TMUTFMT_H__
248 //eof
icu::TimeUnitFormat
Format or parse a TimeUnitAmount, using plural rules for the units where available.
Definition: tmutfmt.h:87
icu::TimeUnitFormat::operator!=
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition: tmutfmt.h:238
icu::Format
Base class for all formats.
Definition: format.h:96
icu::TimeUnit::UTimeUnitFields
UTimeUnitFields
Constants for all the time units we supported.
Definition: tmunit.h:38
icu::MeasureFormat::getStaticClassID
static UClassID getStaticClassID(void)
Return the class ID for this class.
icu::MeasureFormat::getDynamicClassID
virtual UClassID getDynamicClassID(void) const
Returns a unique class ID POLYMORPHICALLY.
icu::MeasureFormat
A formatter for measure objects.
Definition: measfmt.h:97
icu::NumberFormat
Abstract base class for all number formats.
Definition: numfmt.h:169
unistr.h
C++ API: Unicode String.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:93
icu::MeasureFormat::operator=
MeasureFormat & operator=(const MeasureFormat &rhs)
Assignment operator.
plurrule.h
C++ API: PluralRules object.
tmunit.h
C++ API: time unit object.
UTMUTFMT_ABBREVIATED_STYLE
Definition: tmutfmt.h:43
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:360
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
UTimeUnitFormatStyle
UTimeUnitFormatStyle
Constants for various styles.
Definition: tmutfmt.h:39
UTMUTFMT_FULL_STYLE
Definition: tmutfmt.h:41
icu::TimeUnit::UTIMEUNIT_FIELD_COUNT
One more than the highest normal UTimeUnitFields value.
Definition: tmunit.h:51
measfmt.h
C++ API: Formatter for measure objects.
icu::MeasureFormat::clone
virtual Format * clone() const
Clones this object polymorphically.
tmutamt.h
C++ API: time unit amount object.
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:49
icu::MeasureFormat::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &reslt, ParsePosition &pos) const
Parse a string to produce an object.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::Format::operator!=
UBool operator!=(const Format &other) const
Return true if the given Format objects are not semantically equal.
Definition: format.h:121
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:68
icu::MeasureFormat::operator==
virtual UBool operator==(const Format &other) const
Return true if given Format objects are semantically equal.
numfmt.h
C++ API: Abstract base class for all number formats.
UTMUTFMT_FORMAT_STYLE_COUNT
Definition: tmutfmt.h:45
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:259
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:187