ICU 4.8 4.8
|
00001 /* 00002 ******************************************************************************* 00003 * Copyright (C) 2008-2011, Google, International Business Machines Corporation 00004 * and others. All Rights Reserved. 00005 ******************************************************************************* 00006 */ 00007 00008 #ifndef __TMUTFMT_H__ 00009 #define __TMUTFMT_H__ 00010 00011 #include "unicode/utypes.h" 00012 00019 #if !UCONFIG_NO_FORMATTING 00020 00021 #include "unicode/unistr.h" 00022 #include "unicode/tmunit.h" 00023 #include "unicode/tmutamt.h" 00024 #include "unicode/measfmt.h" 00025 #include "unicode/numfmt.h" 00026 #include "unicode/plurrule.h" 00027 00032 union UHashTok; 00033 00041 enum UTimeUnitFormatStyle { 00043 UTMUTFMT_FULL_STYLE, 00045 UTMUTFMT_ABBREVIATED_STYLE, 00047 UTMUTFMT_FORMAT_STYLE_COUNT 00048 }; 00049 typedef enum UTimeUnitFormatStyle UTimeUnitFormatStyle; 00051 U_NAMESPACE_BEGIN 00052 00053 class Hashtable; 00054 00055 00086 class U_I18N_API TimeUnitFormat: public MeasureFormat { 00087 public: 00088 00094 TimeUnitFormat(UErrorCode& status); 00095 00100 TimeUnitFormat(const Locale& locale, UErrorCode& status); 00101 00106 TimeUnitFormat(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status); 00107 00112 TimeUnitFormat(const TimeUnitFormat&); 00113 00118 virtual ~TimeUnitFormat(); 00119 00126 virtual Format* clone(void) const; 00127 00132 TimeUnitFormat& operator=(const TimeUnitFormat& other); 00133 00134 00142 virtual UBool operator==(const Format& other) const; 00143 00151 UBool operator!=(const Format& other) const; 00152 00159 void setLocale(const Locale& locale, UErrorCode& status); 00160 00161 00168 void setNumberFormat(const NumberFormat& format, UErrorCode& status); 00169 00170 00171 using MeasureFormat::format; 00172 00181 virtual UnicodeString& format(const Formattable& obj, 00182 UnicodeString& toAppendTo, 00183 FieldPosition& pos, 00184 UErrorCode& status) const; 00185 00191 virtual void parseObject(const UnicodeString& source, 00192 Formattable& result, 00193 ParsePosition& pos) const; 00194 00206 static UClassID U_EXPORT2 getStaticClassID(void); 00207 00219 virtual UClassID getDynamicClassID(void) const; 00220 00221 private: 00222 NumberFormat* fNumberFormat; 00223 Locale fLocale; 00224 Hashtable* fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT]; 00225 PluralRules* fPluralRules; 00226 UTimeUnitFormatStyle fStyle; 00227 00228 void create(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status); 00229 00230 // it might actually be simpler to make them Decimal Formats later. 00231 // initialize all private data members 00232 void setup(UErrorCode& status); 00233 00234 // initialize data member without fill in data for fTimeUnitToCountToPattern 00235 void initDataMembers(UErrorCode& status); 00236 00237 // initialize fTimeUnitToCountToPatterns from current locale's resource. 00238 void readFromCurrentLocale(UTimeUnitFormatStyle style, const char* key, UErrorCode& status); 00239 00240 // check completeness of fTimeUnitToCountToPatterns against all time units, 00241 // and all plural rules, fill in fallback as necessary. 00242 void checkConsistency(UTimeUnitFormatStyle style, const char* key, UErrorCode& status); 00243 00244 // fill in fTimeUnitToCountToPatterns from locale fall-back chain 00245 void searchInLocaleChain(UTimeUnitFormatStyle style, const char* key, const char* localeName, 00246 TimeUnit::UTimeUnitFields field, const char*, 00247 const char*, Hashtable*, UErrorCode&); 00248 00249 // initialize hash table 00250 Hashtable* initHash(UErrorCode& status); 00251 00252 // delete hash table 00253 void deleteHash(Hashtable* htable); 00254 00255 // copy hash table 00256 void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status); 00257 // get time unit name, such as "year", from time unit field enum, such as 00258 // UTIMEUNIT_YEAR. 00259 static const char* getTimeUnitName(TimeUnit::UTimeUnitFields field, UErrorCode& status); 00260 }; 00261 00262 00263 00264 inline UBool 00265 TimeUnitFormat::operator!=(const Format& other) const { 00266 return !operator==(other); 00267 } 00268 00269 00270 00271 U_NAMESPACE_END 00272 00273 #endif /* #if !UCONFIG_NO_FORMATTING */ 00274 00275 #endif // __TMUTFMT_H__ 00276 //eof