ICU 49.1.1
49.1.1
|
00001 /* 00002 ******************************************************************************* 00003 * Copyright (C) 2011-2012, International Business Machines Corporation and * 00004 * others. All Rights Reserved. * 00005 ******************************************************************************* 00006 */ 00007 #ifndef __TZFMT_H 00008 #define __TZFMT_H 00009 00015 #include "unicode/utypes.h" 00016 00017 #if !UCONFIG_NO_FORMATTING 00018 #ifndef U_HIDE_INTERNAL_API 00019 00020 #include "unicode/format.h" 00021 #include "unicode/timezone.h" 00022 #include "unicode/tznames.h" 00023 00024 U_CDECL_BEGIN 00030 typedef enum UTimeZoneFormatStyle { 00035 UTZFMT_STYLE_GENERIC_LOCATION, 00040 UTZFMT_STYLE_GENERIC_LONG, 00045 UTZFMT_STYLE_GENERIC_SHORT, 00050 UTZFMT_STYLE_SPECIFIC_LONG, 00055 UTZFMT_STYLE_SPECIFIC_SHORT, 00060 UTZFMT_STYLE_RFC822, 00065 UTZFMT_STYLE_LOCALIZED_GMT, 00070 UTZFMT_STYLE_ISO8601 00071 } UTimeZoneFormatStyle; 00072 00077 typedef enum UTimeZoneFormatGMTOffsetPatternType { 00082 UTZFMT_PAT_POSITIVE_HM, 00087 UTZFMT_PAT_POSITIVE_HMS, 00092 UTZFMT_PAT_NEGATIVE_HM, 00097 UTZFMT_PAT_NEGATIVE_HMS 00098 } UTimeZoneFormatGMTOffsetPatternType; 00099 00105 typedef enum UTimeZoneFormatTimeType { 00110 UTZFMT_TIME_TYPE_UNKNOWN, 00115 UTZFMT_TIME_TYPE_STANDARD, 00120 UTZFMT_TIME_TYPE_DAYLIGHT 00121 } UTimeZoneFormatTimeType; 00122 00127 typedef enum UTimeZoneFormatParseOption { 00132 UTZFMT_PARSE_OPTION_NONE = 0x00, 00139 UTZFMT_PARSE_OPTION_ALL_STYLES = 0x01 00140 } UTimeZoneFormatParseOption; 00141 00142 U_CDECL_END 00143 00144 typedef void *UMTX; 00145 00146 U_NAMESPACE_BEGIN 00147 00148 class TimeZoneGenericNames; 00149 class UVector; 00150 00166 class U_I18N_API TimeZoneFormat : public Format { 00167 public: 00172 TimeZoneFormat(const TimeZoneFormat& other); 00173 00178 virtual ~TimeZoneFormat(); 00179 00184 TimeZoneFormat& operator=(const TimeZoneFormat& other); 00185 00194 virtual UBool operator==(const Format& other) const; 00195 00202 virtual Format* clone() const; 00203 00212 static TimeZoneFormat* U_EXPORT2 createInstance(const Locale& locale, UErrorCode& status); 00213 00219 const TimeZoneNames* getTimeZoneNames() const; 00220 00228 void adoptTimeZoneNames(TimeZoneNames *tznames); 00229 00235 void setTimeZoneNames(const TimeZoneNames &tznames); 00236 00244 UnicodeString& getGMTPattern(UnicodeString& pattern) const; 00245 00254 void setGMTPattern(const UnicodeString& pattern, UErrorCode& status); 00255 00264 UnicodeString& getGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, UnicodeString& pattern) const; 00265 00274 void setGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, const UnicodeString& pattern, UErrorCode& status); 00275 00282 UnicodeString& getGMTOffsetDigits(UnicodeString& digits) const; 00283 00290 void setGMTOffsetDigits(const UnicodeString& digits, UErrorCode& status); 00291 00298 UnicodeString& getGMTZeroFormat(UnicodeString& gmtZeroFormat) const; 00299 00306 void setGMTZeroFormat(const UnicodeString& gmtZeroFormat, UErrorCode& status); 00307 00315 int32_t getDefaultParseOptions(void) const; 00316 00325 void setDefaultParseOptions(int32_t flags); 00326 00336 UnicodeString& formatOffsetRFC822(int32_t offset, UnicodeString& result, UErrorCode& status) const; 00337 00347 UnicodeString& formatOffsetISO8601(int32_t offset, UnicodeString& result, UErrorCode& status) const; 00348 00364 UnicodeString& formatOffsetLocalizedGMT(int32_t offset, UnicodeString& result, UErrorCode& status) const; 00365 00379 virtual UnicodeString& format(UTimeZoneFormatStyle style, const TimeZone& tz, UDate date, 00380 UnicodeString& name, UTimeZoneFormatTimeType* timeType = NULL) const; 00381 00395 int32_t parseOffsetRFC822(const UnicodeString& text, ParsePosition& pos) const; 00396 00410 int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos) const; 00411 00424 int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const; 00425 00442 virtual TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos, 00443 int32_t parseOptions, UTimeZoneFormatTimeType* timeType = NULL) const; 00444 00460 TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos, 00461 UTimeZoneFormatTimeType* timeType = NULL) const; 00462 00463 /* ---------------------------------------------- 00464 * Format APIs 00465 * ---------------------------------------------- */ 00466 00478 virtual UnicodeString& format(const Formattable& obj, UnicodeString& appendTo, 00479 FieldPosition& pos, UErrorCode& status) const; 00480 00493 virtual void parseObject(const UnicodeString& source, Formattable& result, ParsePosition& parse_pos) const; 00494 00499 static UClassID U_EXPORT2 getStaticClassID(void); 00500 00505 virtual UClassID getDynamicClassID() const; 00506 00507 protected: 00514 TimeZoneFormat(const Locale& locale, UErrorCode& status); 00515 00516 private: 00517 /* mutex */ 00518 UMTX fLock; 00519 00520 /* Locale of this object */ 00521 Locale fLocale; 00522 00523 /* Stores the region (could be implicit default) */ 00524 char fTargetRegion[ULOC_COUNTRY_CAPACITY]; 00525 00526 /* TimeZoneNames object used by this formatter */ 00527 TimeZoneNames* fTimeZoneNames; 00528 00529 /* TimeZoneGenericNames object used by this formatter - lazily instantiated */ 00530 TimeZoneGenericNames* fTimeZoneGenericNames; 00531 00532 /* Localized GMT format pattern - e.g. "GMT{0}" */ 00533 UnicodeString fGMTPattern; 00534 00535 /* Array of offset patterns used by Localized GMT format - e.g. "+HH:mm" */ 00536 UnicodeString fGMTOffsetPatterns[UTZFMT_PAT_NEGATIVE_HMS + 1]; 00537 00538 /* Localized decimal digits used by Localized GMT format */ 00539 UChar32 fGMTOffsetDigits[10]; 00540 00541 /* Localized GMT zero format - e.g. "GMT" */ 00542 UnicodeString fGMTZeroFormat; 00543 00544 /* Bit flags representing parse options */ 00545 int32_t fDefParseOptionFlags; 00546 00547 /* Constant parts of GMT format pattern, populated from localized GMT format pattern*/ 00548 UnicodeString fGMTPatternPrefix; /* Substring before {0} */ 00549 UnicodeString fGMTPatternSuffix; /* Substring after {0} */ 00550 00551 /* Compiled offset patterns generated from fGMTOffsetPatterns[] */ 00552 UVector* fGMTOffsetPatternItems[UTZFMT_PAT_NEGATIVE_HMS + 1]; 00553 00564 UnicodeString& formatSpecific(const TimeZone& tz, UTimeZoneNameType stdType, UTimeZoneNameType dstType, 00565 UDate date, UnicodeString& name, UTimeZoneFormatTimeType *timeType) const; 00566 00575 UnicodeString& formatGeneric(const TimeZone& tz, int32_t genType, UDate date, UnicodeString& name) const; 00576 00582 const TimeZoneGenericNames* getTimeZoneGenericNames(UErrorCode& status) const; 00583 00587 enum OffsetFields { 00588 FIELDS_H, 00589 FIELDS_HM, 00590 FIELDS_HMS 00591 }; 00592 00600 void initGMTPattern(const UnicodeString& gmtPattern, UErrorCode& status); 00601 00610 static UVector* parseOffsetPattern(const UnicodeString& pattern, OffsetFields required, UErrorCode& status); 00611 00619 static UnicodeString& expandOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result); 00620 00631 static UBool toCodePoints(const UnicodeString& str, UChar32* codeArray, int32_t capacity); 00632 00647 int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos, UBool extendedOnly, 00648 UBool* hasDigitOffset = NULL) const; 00649 00657 void appendOffsetDigits(UnicodeString& buf, int32_t n, uint8_t minDigits) const; 00658 00670 int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos, 00671 UBool* hasDigitOffset) const; 00672 00681 int32_t parseOffsetFields(const UnicodeString& text, int32_t start, UBool minimumHourWidth, 00682 int32_t& parsedLen) const; 00683 00691 int32_t parseAbuttingOffsetFields(const UnicodeString& text, int32_t start, int32_t& parsedLen) const; 00692 00700 int32_t parseOffsetDefaultLocalizedGMT(const UnicodeString& text, int start, int32_t& parsedLen) const; 00701 00710 int32_t parseDefaultOffsetFields(const UnicodeString& text, int32_t start, UChar separator, 00711 int32_t& parsedLen) const; 00712 00727 int32_t parseOffsetFieldWithLocalizedDigits(const UnicodeString& text, int32_t start, 00728 uint8_t minDigits, uint8_t maxDigits, uint16_t minVal, uint16_t maxVal, int32_t& parsedLen) const; 00729 00739 int32_t parseSingleLocalizedDigit(const UnicodeString& text, int32_t start, int32_t& len) const; 00740 00750 static UnicodeString& formatOffsetWithAsciiDigits(int32_t offset, UChar sep, 00751 OffsetFields minFields, OffsetFields maxFields, UnicodeString& result); 00752 00765 static int32_t parseAbuttingAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos, 00766 OffsetFields minFields, OffsetFields maxFields, UBool fixedHourWidth); 00767 00781 static int32_t parseAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos, UChar sep, 00782 OffsetFields minFields, OffsetFields maxFields, UBool fixedHourWidth); 00783 00790 static UnicodeString& unquote(const UnicodeString& pattern, UnicodeString& result); 00791 00797 void initGMTOffsetPatterns(UErrorCode& status); 00798 00804 TimeZone* createTimeZoneForOffset(int32_t offset) const; 00805 00811 static UTimeZoneFormatTimeType getTimeType(UTimeZoneNameType nameType); 00812 00813 /* 00814 * Returns the time zone ID of a match at the specified index within 00815 * the MatchInfoCollection. 00816 * @param matches the collection of matches 00817 * @param idx the index withing matches 00818 * @param tzID receives the resolved time zone ID 00819 * @return a reference to tzID. 00820 */ 00821 UnicodeString& getTimeZoneID(const TimeZoneNames::MatchInfoCollection* matches, int32_t idx, UnicodeString& tzID) const; 00822 }; 00823 00824 U_NAMESPACE_END 00825 00826 #endif /* U_HIDE_INTERNAL_API */ 00827 #endif 00828 #endif 00829