|
ICU 73.2
73.2
|
00001 // © 2016 and later: Unicode, Inc. and others. 00002 // License & terms of use: http://www.unicode.org/copyright.html 00003 /* 00004 ******************************************************************************* 00005 * Copyright (C) 2008-2014, Google, International Business Machines Corporation 00006 * and others. All Rights Reserved. 00007 ******************************************************************************* 00008 */ 00009 00010 #ifndef __TMUTFMT_H__ 00011 #define __TMUTFMT_H__ 00012 00013 #include "unicode/utypes.h" 00014 00021 #if U_SHOW_CPLUSPLUS_API 00022 00023 #if !UCONFIG_NO_FORMATTING 00024 00025 #include "unicode/unistr.h" 00026 #include "unicode/tmunit.h" 00027 #include "unicode/tmutamt.h" 00028 #include "unicode/measfmt.h" 00029 #include "unicode/numfmt.h" 00030 #include "unicode/plurrule.h" 00031 00032 #ifndef U_HIDE_DEPRECATED_API 00033 00041 enum UTimeUnitFormatStyle { 00043 UTMUTFMT_FULL_STYLE, 00045 UTMUTFMT_ABBREVIATED_STYLE, 00047 UTMUTFMT_FORMAT_STYLE_COUNT 00048 }; 00049 typedef enum UTimeUnitFormatStyle UTimeUnitFormatStyle; 00052 U_NAMESPACE_BEGIN 00053 00054 class Hashtable; 00055 class UVector; 00056 00057 struct TimeUnitFormatReadSink; 00058 00089 class U_I18N_API TimeUnitFormat: public MeasureFormat { 00090 public: 00091 00097 TimeUnitFormat(UErrorCode& status); 00098 00103 TimeUnitFormat(const Locale& locale, UErrorCode& status); 00104 00109 TimeUnitFormat(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status); 00110 00115 TimeUnitFormat(const TimeUnitFormat&); 00116 00121 virtual ~TimeUnitFormat(); 00122 00129 virtual TimeUnitFormat* clone() const override; 00130 00135 TimeUnitFormat& operator=(const TimeUnitFormat& other); 00136 00143 void setLocale(const Locale& locale, UErrorCode& status); 00144 00145 00152 void setNumberFormat(const NumberFormat& format, UErrorCode& status); 00153 00159 virtual void parseObject(const UnicodeString& source, 00160 Formattable& result, 00161 ParsePosition& pos) const override; 00162 00174 static UClassID U_EXPORT2 getStaticClassID(void); 00175 00187 virtual UClassID getDynamicClassID(void) const override; 00188 00189 private: 00190 Hashtable* fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT]; 00191 UTimeUnitFormatStyle fStyle; 00192 00193 void create(UTimeUnitFormatStyle style, UErrorCode& status); 00194 00195 // it might actually be simpler to make them Decimal Formats later. 00196 // initialize all private data members 00197 void setup(UErrorCode& status); 00198 00199 // initialize data member without fill in data for fTimeUnitToCountToPattern 00200 void initDataMembers(UErrorCode& status); 00201 00202 // initialize fTimeUnitToCountToPatterns from current locale's resource. 00203 void readFromCurrentLocale(UTimeUnitFormatStyle style, const char* key, const UVector& pluralCounts, 00204 UErrorCode& status); 00205 00206 // check completeness of fTimeUnitToCountToPatterns against all time units, 00207 // and all plural rules, fill in fallback as necessary. 00208 void checkConsistency(UTimeUnitFormatStyle style, const char* key, UErrorCode& status); 00209 00210 // fill in fTimeUnitToCountToPatterns from locale fall-back chain 00211 void searchInLocaleChain(UTimeUnitFormatStyle style, const char* key, const char* localeName, 00212 TimeUnit::UTimeUnitFields field, const UnicodeString&, 00213 const char*, Hashtable*, UErrorCode&); 00214 00215 // initialize hash table 00216 Hashtable* initHash(UErrorCode& status); 00217 00218 // delete hash table 00219 void deleteHash(Hashtable* htable); 00220 00221 // copy hash table 00222 void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status); 00223 // get time unit name, such as "year", from time unit field enum, such as 00224 // UTIMEUNIT_YEAR. 00225 static const char* getTimeUnitName(TimeUnit::UTimeUnitFields field, UErrorCode& status); 00226 00227 friend struct TimeUnitFormatReadSink; 00228 }; 00229 00230 U_NAMESPACE_END 00231 00232 #endif /* U_HIDE_DEPRECATED_API */ 00233 #endif /* #if !UCONFIG_NO_FORMATTING */ 00234 00235 #endif /* U_SHOW_CPLUSPLUS_API */ 00236 00237 #endif // __TMUTFMT_H__ 00238 //eof
1.7.6.1