ICU 77.1 77.1

tmutfmt.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 * 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 U_SHOW_CPLUSPLUS_API
22
23 #if !UCONFIG_NO_FORMATTING
24
25 #include "unicode/unistr.h"
26 #include "unicode/tmunit.h"
27 #include "unicode/tmutamt.h"
28 #include "unicode/measfmt.h"
29 #include "unicode/numfmt.h"
30 #include "unicode/plurrule.h"
31
32 #ifndef U_HIDE_DEPRECATED_API
33
41 enum UTimeUnitFormatStyle {
43 UTMUTFMT_FULL_STYLE,
45 UTMUTFMT_ABBREVIATED_STYLE,
47 UTMUTFMT_FORMAT_STYLE_COUNT
48 };
49 typedef enum UTimeUnitFormatStyle UTimeUnitFormatStyle;
52 U_NAMESPACE_BEGIN
53
54 class Hashtable;
55 class UVector;
56
57 struct TimeUnitFormatReadSink;
58
89 class U_I18N_API TimeUnitFormat: public MeasureFormat {
90 public:
91
97 TimeUnitFormat(UErrorCode& status);
98
103 TimeUnitFormat(const Locale& locale, UErrorCode& status);
104
109 TimeUnitFormat(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status);
110
115 TimeUnitFormat(const TimeUnitFormat&);
116
121 virtual ~TimeUnitFormat();
122
129 virtual TimeUnitFormat* clone() const override;
130
135 TimeUnitFormat& operator=(const TimeUnitFormat& other);
136
143 void setLocale(const Locale& locale, UErrorCode& status);
144
145
152 void setNumberFormat(const NumberFormat& format, UErrorCode& status);
153
159 virtual void parseObject(const UnicodeString& source,
160 Formattable& result,
161 ParsePosition& pos) const override;
162
174 static UClassID U_EXPORT2 getStaticClassID();
175
187 virtual UClassID getDynamicClassID() const override;
188
189 private:
190 Hashtable* fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT];
191 UTimeUnitFormatStyle fStyle;
192
193 void create(UTimeUnitFormatStyle style, UErrorCode& status);
194
195 // it might actually be simpler to make them Decimal Formats later.
196 // initialize all private data members
197 void setup(UErrorCode& status);
198
199 // initialize data member without fill in data for fTimeUnitToCountToPattern
200 void initDataMembers(UErrorCode& status);
201
202 // initialize fTimeUnitToCountToPatterns from current locale's resource.
203 void readFromCurrentLocale(UTimeUnitFormatStyle style, const char* key, const UVector& pluralCounts,
204 UErrorCode& status);
205
206 // check completeness of fTimeUnitToCountToPatterns against all time units,
207 // and all plural rules, fill in fallback as necessary.
208 void checkConsistency(UTimeUnitFormatStyle style, const char* key, UErrorCode& status);
209
210 // fill in fTimeUnitToCountToPatterns from locale fall-back chain
211 void searchInLocaleChain(UTimeUnitFormatStyle style, const char* key, const char* localeName,
212 TimeUnit::UTimeUnitFields field, const UnicodeString&,
213 const char*, Hashtable*, UErrorCode&);
214
215 // initialize hash table
216 Hashtable* initHash(UErrorCode& status);
217
218 // delete hash table
219 void deleteHash(Hashtable* htable);
220
221 // copy hash table
222 void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status);
223 // get time unit name, such as "year", from time unit field enum, such as
224 // UTIMEUNIT_YEAR.
225 static const char* getTimeUnitName(TimeUnit::UTimeUnitFields field, UErrorCode& status);
226
227 friend struct TimeUnitFormatReadSink;
228 };
229
230 U_NAMESPACE_END
231
232 #endif /* U_HIDE_DEPRECATED_API */
233 #endif /* #if !UCONFIG_NO_FORMATTING */
234
235 #endif /* U_SHOW_CPLUSPLUS_API */
236
237 #endif // __TMUTFMT_H__
238 //eof
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:63
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::MeasureFormat
Definition: measfmt.h:101
icu::NumberFormat
Definition: numfmt.h:175
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:52
icu::TimeUnitFormat
Format or parse a TimeUnitAmount, using plural rules for the units where available.
Definition: tmutfmt.h:89
icu::TimeUnitFormat::TimeUnitFormat
TimeUnitFormat(const Locale &locale, UErrorCode &status)
Create TimeUnitFormat given locale, and full name style.
icu::TimeUnitFormat::TimeUnitFormat
TimeUnitFormat(const TimeUnitFormat &)
Copy constructor.
icu::TimeUnitFormat::getStaticClassID
static UClassID getStaticClassID()
Return the class ID for this class.
icu::TimeUnitFormat::setNumberFormat
void setNumberFormat(const NumberFormat &format, UErrorCode &status)
Set the number format used for formatting or parsing.
icu::TimeUnitFormat::getDynamicClassID
virtual UClassID getDynamicClassID() const override
Returns a unique class ID POLYMORPHICALLY.
icu::TimeUnitFormat::TimeUnitFormat
TimeUnitFormat(UErrorCode &status)
Create TimeUnitFormat with default locale, and full name style.
icu::TimeUnitFormat::TimeUnitFormat
TimeUnitFormat(const Locale &locale, UTimeUnitFormatStyle style, UErrorCode &status)
Create TimeUnitFormat given locale and style.
icu::TimeUnitFormat::setLocale
void setLocale(const Locale &locale, UErrorCode &status)
Set the locale used for formatting or parsing.
icu::TimeUnitFormat::operator=
TimeUnitFormat & operator=(const TimeUnitFormat &other)
Assignment operator.
icu::TimeUnitFormat::~TimeUnitFormat
virtual ~TimeUnitFormat()
deconstructor
icu::TimeUnitFormat::parseObject
virtual void parseObject(const UnicodeString &source, Formattable &result, ParsePosition &pos) const override
Parse a TimeUnitAmount.
icu::TimeUnitFormat::clone
virtual TimeUnitFormat * clone() const override
Clone this Format object polymorphically.
icu::TimeUnit::UTimeUnitFields
UTimeUnitFields
Constants for all the time units we supported.
Definition: tmunit.h:41
icu::TimeUnit::UTIMEUNIT_FIELD_COUNT
@ UTIMEUNIT_FIELD_COUNT
One more than the highest normal UTimeUnitFields value.
Definition: tmunit.h:54
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
measfmt.h
C++ API: Compatibility APIs for measure formatting.
numfmt.h
C++ API: Compatibility APIs for number formatting.
plurrule.h
C++ API: PluralRules object.
tmunit.h
C++ API: time unit object.
tmutamt.h
C++ API: time unit amount object.
UTimeUnitFormatStyle
UTimeUnitFormatStyle
Constants for various styles.
Definition: tmutfmt.h:41
UTMUTFMT_ABBREVIATED_STYLE
@ UTMUTFMT_ABBREVIATED_STYLE
Definition: tmutfmt.h:45
UTMUTFMT_FORMAT_STYLE_COUNT
@ UTMUTFMT_FORMAT_STYLE_COUNT
Definition: tmutfmt.h:47
UTMUTFMT_FULL_STYLE
@ UTMUTFMT_FULL_STYLE
Definition: tmutfmt.h:43
unistr.h
C++ API: Unicode String.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:430
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:316