ICU 4.8.1.1
4.8.1.1
|
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 00035 enum UTimeUnitFormatStyle { 00037 UTMUTFMT_FULL_STYLE, 00039 UTMUTFMT_ABBREVIATED_STYLE, 00041 UTMUTFMT_FORMAT_STYLE_COUNT 00042 }; 00043 typedef enum UTimeUnitFormatStyle UTimeUnitFormatStyle; 00045 U_NAMESPACE_BEGIN 00046 00047 class Hashtable; 00048 00049 00080 class U_I18N_API TimeUnitFormat: public MeasureFormat { 00081 public: 00082 00088 TimeUnitFormat(UErrorCode& status); 00089 00094 TimeUnitFormat(const Locale& locale, UErrorCode& status); 00095 00100 TimeUnitFormat(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status); 00101 00106 TimeUnitFormat(const TimeUnitFormat&); 00107 00112 virtual ~TimeUnitFormat(); 00113 00120 virtual Format* clone(void) const; 00121 00126 TimeUnitFormat& operator=(const TimeUnitFormat& other); 00127 00128 00136 virtual UBool operator==(const Format& other) const; 00137 00145 UBool operator!=(const Format& other) const; 00146 00153 void setLocale(const Locale& locale, UErrorCode& status); 00154 00155 00162 void setNumberFormat(const NumberFormat& format, UErrorCode& status); 00163 00164 00165 using MeasureFormat::format; 00166 00175 virtual UnicodeString& format(const Formattable& obj, 00176 UnicodeString& toAppendTo, 00177 FieldPosition& pos, 00178 UErrorCode& status) const; 00179 00185 virtual void parseObject(const UnicodeString& source, 00186 Formattable& result, 00187 ParsePosition& pos) const; 00188 00200 static UClassID U_EXPORT2 getStaticClassID(void); 00201 00213 virtual UClassID getDynamicClassID(void) const; 00214 00215 private: 00216 NumberFormat* fNumberFormat; 00217 Locale fLocale; 00218 Hashtable* fTimeUnitToCountToPatterns[TimeUnit::UTIMEUNIT_FIELD_COUNT]; 00219 PluralRules* fPluralRules; 00220 UTimeUnitFormatStyle fStyle; 00221 00222 void create(const Locale& locale, UTimeUnitFormatStyle style, UErrorCode& status); 00223 00224 // it might actually be simpler to make them Decimal Formats later. 00225 // initialize all private data members 00226 void setup(UErrorCode& status); 00227 00228 // initialize data member without fill in data for fTimeUnitToCountToPattern 00229 void initDataMembers(UErrorCode& status); 00230 00231 // initialize fTimeUnitToCountToPatterns from current locale's resource. 00232 void readFromCurrentLocale(UTimeUnitFormatStyle style, const char* key, UErrorCode& status); 00233 00234 // check completeness of fTimeUnitToCountToPatterns against all time units, 00235 // and all plural rules, fill in fallback as necessary. 00236 void checkConsistency(UTimeUnitFormatStyle style, const char* key, UErrorCode& status); 00237 00238 // fill in fTimeUnitToCountToPatterns from locale fall-back chain 00239 void searchInLocaleChain(UTimeUnitFormatStyle style, const char* key, const char* localeName, 00240 TimeUnit::UTimeUnitFields field, const UnicodeString&, 00241 const char*, Hashtable*, UErrorCode&); 00242 00243 // initialize hash table 00244 Hashtable* initHash(UErrorCode& status); 00245 00246 // delete hash table 00247 void deleteHash(Hashtable* htable); 00248 00249 // copy hash table 00250 void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status); 00251 // get time unit name, such as "year", from time unit field enum, such as 00252 // UTIMEUNIT_YEAR. 00253 static const char* getTimeUnitName(TimeUnit::UTimeUnitFields field, UErrorCode& status); 00254 }; 00255 00256 00257 00258 inline UBool 00259 TimeUnitFormat::operator!=(const Format& other) const { 00260 return !operator==(other); 00261 } 00262 00263 00264 00265 U_NAMESPACE_END 00266 00267 #endif /* #if !UCONFIG_NO_FORMATTING */ 00268 00269 #endif // __TMUTFMT_H__ 00270 //eof