tzfmt.h

Go to the documentation of this file.
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 U_NAMESPACE_BEGIN
00145 
00146 class TimeZoneGenericNames;
00147 class UVector;
00148 
00164 class U_I18N_API TimeZoneFormat : public Format {
00165 public:
00170     TimeZoneFormat(const TimeZoneFormat& other);
00171 
00176     virtual ~TimeZoneFormat();
00177 
00182     TimeZoneFormat& operator=(const TimeZoneFormat& other);
00183 
00192     virtual UBool operator==(const Format& other) const;
00193 
00200     virtual Format* clone() const;
00201 
00210     static TimeZoneFormat* U_EXPORT2 createInstance(const Locale& locale, UErrorCode& status);
00211 
00217     const TimeZoneNames* getTimeZoneNames() const;
00218 
00226     void adoptTimeZoneNames(TimeZoneNames *tznames);
00227 
00233     void setTimeZoneNames(const TimeZoneNames &tznames);
00234 
00242     UnicodeString& getGMTPattern(UnicodeString& pattern) const;
00243 
00252     void setGMTPattern(const UnicodeString& pattern, UErrorCode& status);
00253 
00262     UnicodeString& getGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, UnicodeString& pattern) const;
00263 
00272     void setGMTOffsetPattern(UTimeZoneFormatGMTOffsetPatternType type, const UnicodeString& pattern, UErrorCode& status);
00273 
00283     UnicodeString& getGMTOffsetDigits(UnicodeString& digits) const;
00284 
00297     void setGMTOffsetDigits(const UnicodeString& digits, UErrorCode& status);
00298 
00306     UnicodeString& getGMTZeroFormat(UnicodeString& gmtZeroFormat) const;
00307 
00315     void setGMTZeroFormat(const UnicodeString& gmtZeroFormat, UErrorCode& status);
00316 
00324     uint32_t getDefaultParseOptions(void) const;
00325 
00334     void setDefaultParseOptions(uint32_t flags);
00335 
00346     UnicodeString& formatOffsetRFC822(int32_t offset, UnicodeString& result, UErrorCode& status) const;
00347 
00358     UnicodeString& formatOffsetISO8601(int32_t offset, UnicodeString& result, UErrorCode& status) const;
00359 
00376     UnicodeString& formatOffsetLocalizedGMT(int32_t offset, UnicodeString& result, UErrorCode& status) const;
00377 
00378     using Format::format;
00379 
00393     virtual UnicodeString& format(UTimeZoneFormatStyle style, const TimeZone& tz, UDate date,
00394         UnicodeString& name, UTimeZoneFormatTimeType* timeType = NULL) const;
00395 
00409     int32_t parseOffsetRFC822(const UnicodeString& text, ParsePosition& pos) const;
00410 
00424     int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos) const;
00425 
00438     int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos) const;
00439 
00456     virtual TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
00457         int32_t parseOptions, UTimeZoneFormatTimeType* timeType = NULL) const;
00458 
00474     TimeZone* parse(UTimeZoneFormatStyle style, const UnicodeString& text, ParsePosition& pos,
00475         UTimeZoneFormatTimeType* timeType = NULL) const;
00476 
00477     /* ----------------------------------------------
00478      * Format APIs
00479      * ---------------------------------------------- */
00480 
00492     virtual UnicodeString& format(const Formattable& obj, UnicodeString& appendTo,
00493         FieldPosition& pos, UErrorCode& status) const;
00494 
00507     virtual void parseObject(const UnicodeString& source, Formattable& result, ParsePosition& parse_pos) const;
00508 
00513     static UClassID U_EXPORT2 getStaticClassID(void);
00514 
00519     virtual UClassID getDynamicClassID() const;
00520 
00521 protected:
00528     TimeZoneFormat(const Locale& locale, UErrorCode& status);
00529 
00530 private:
00531     /* Locale of this object */
00532     Locale fLocale;
00533 
00534     /* Stores the region (could be implicit default) */ 
00535     char fTargetRegion[ULOC_COUNTRY_CAPACITY];
00536 
00537     /* TimeZoneNames object used by this formatter */
00538     TimeZoneNames* fTimeZoneNames;
00539 
00540     /* TimeZoneGenericNames object used by this formatter - lazily instantiated */
00541     TimeZoneGenericNames* fTimeZoneGenericNames;
00542 
00543     /* Localized GMT format pattern - e.g. "GMT{0}" */
00544     UnicodeString fGMTPattern;
00545 
00546     /* Array of offset patterns used by Localized GMT format - e.g. "+HH:mm" */
00547     UnicodeString fGMTOffsetPatterns[UTZFMT_PAT_NEGATIVE_HMS + 1];
00548 
00549     /* Localized decimal digits used by Localized GMT format */
00550     UChar32 fGMTOffsetDigits[10];
00551 
00552     /* Localized GMT zero format - e.g. "GMT" */
00553     UnicodeString fGMTZeroFormat;
00554 
00555     /* Bit flags representing parse options */
00556     uint32_t fDefParseOptionFlags;
00557 
00558     /* Constant parts of GMT format pattern, populated from localized GMT format pattern*/
00559     UnicodeString fGMTPatternPrefix;    /* Substring before {0} */
00560     UnicodeString fGMTPatternSuffix;    /* Substring after {0} */
00561 
00562     /* Compiled offset patterns generated from fGMTOffsetPatterns[] */
00563     UVector* fGMTOffsetPatternItems[UTZFMT_PAT_NEGATIVE_HMS + 1];
00564 
00575     UnicodeString& formatSpecific(const TimeZone& tz, UTimeZoneNameType stdType, UTimeZoneNameType dstType,
00576         UDate date, UnicodeString& name, UTimeZoneFormatTimeType *timeType) const;
00577 
00586     UnicodeString& formatGeneric(const TimeZone& tz, int32_t genType, UDate date, UnicodeString& name) const;
00587 
00593     const TimeZoneGenericNames* getTimeZoneGenericNames(UErrorCode& status) const;
00594 
00598     enum OffsetFields {
00599         FIELDS_H,
00600         FIELDS_HM,
00601         FIELDS_HMS
00602     };
00603 
00611     void initGMTPattern(const UnicodeString& gmtPattern, UErrorCode& status);
00612 
00621     static UVector* parseOffsetPattern(const UnicodeString& pattern, OffsetFields required, UErrorCode& status);
00622 
00630     static UnicodeString& expandOffsetPattern(const UnicodeString& offsetHM, UnicodeString& result);
00631 
00642     static UBool toCodePoints(const UnicodeString& str, UChar32* codeArray, int32_t capacity);
00643 
00658     int32_t parseOffsetISO8601(const UnicodeString& text, ParsePosition& pos, UBool extendedOnly,
00659         UBool* hasDigitOffset = NULL) const;
00660 
00668     void appendOffsetDigits(UnicodeString& buf, int32_t n, uint8_t minDigits) const;
00669 
00681     int32_t parseOffsetLocalizedGMT(const UnicodeString& text, ParsePosition& pos,
00682         UBool* hasDigitOffset) const;
00683 
00692     int32_t parseOffsetFields(const UnicodeString& text, int32_t start, UBool minimumHourWidth,
00693         int32_t& parsedLen) const;
00694 
00702     int32_t parseAbuttingOffsetFields(const UnicodeString& text, int32_t start, int32_t& parsedLen) const;
00703 
00711     int32_t parseOffsetDefaultLocalizedGMT(const UnicodeString& text, int start, int32_t& parsedLen) const;
00712 
00721     int32_t parseDefaultOffsetFields(const UnicodeString& text, int32_t start, UChar separator,
00722         int32_t& parsedLen) const;
00723 
00738     int32_t parseOffsetFieldWithLocalizedDigits(const UnicodeString& text, int32_t start,
00739         uint8_t minDigits, uint8_t maxDigits, uint16_t minVal, uint16_t maxVal, int32_t& parsedLen) const;
00740 
00750     int32_t parseSingleLocalizedDigit(const UnicodeString& text, int32_t start, int32_t& len) const;
00751 
00761     static UnicodeString& formatOffsetWithAsciiDigits(int32_t offset, UChar sep,
00762         OffsetFields minFields, OffsetFields maxFields, UnicodeString& result);
00763 
00776     static int32_t parseAbuttingAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos,
00777         OffsetFields minFields, OffsetFields maxFields, UBool fixedHourWidth);
00778 
00792     static int32_t parseAsciiOffsetFields(const UnicodeString& text, ParsePosition& pos, UChar sep,
00793         OffsetFields minFields, OffsetFields maxFields, UBool fixedHourWidth);
00794 
00801     static UnicodeString& unquote(const UnicodeString& pattern, UnicodeString& result);
00802 
00808     void initGMTOffsetPatterns(UErrorCode& status);
00809 
00815     TimeZone* createTimeZoneForOffset(int32_t offset) const;
00816 
00822     static UTimeZoneFormatTimeType getTimeType(UTimeZoneNameType nameType);
00823 
00824     /*
00825      * Returns the time zone ID of a match at the specified index within
00826      * the MatchInfoCollection.
00827      * @param matches the collection of matches
00828      * @param idx the index withing matches
00829      * @param tzID receives the resolved time zone ID
00830      * @return a reference to tzID.
00831      */
00832     UnicodeString& getTimeZoneID(const TimeZoneNames::MatchInfoCollection* matches, int32_t idx, UnicodeString& tzID) const;
00833 };
00834 
00835 U_NAMESPACE_END
00836 
00837 #endif  /* U_HIDE_INTERNAL_API */
00838 #endif
00839 #endif
00840 

Generated on 27 Oct 2013 for ICU 50.1.2 by  doxygen 1.4.7