- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

# smpdtfmt.h

Go to the documentation of this file.

    00001 /*
    00002 * Copyright (C) 1997-2010, International Business Machines Corporation and
    00003 * others. All Rights Reserved.
    00004 *******************************************************************************
    00005 *
    00006 * File SMPDTFMT.H
    00007 *
    00008 * Modification History:
    00009 *
    00010 *   Date        Name        Description
    00011 *   02/19/97    aliu        Converted from java.
    00012 *   07/09/97    helena      Make ParsePosition into a class.
    00013 *   07/21/98    stephen     Added GMT_PLUS, GMT_MINUS
    00014 *                            Changed setTwoDigitStartDate to set2DigitYearStart
    00015 *                            Changed getTwoDigitStartDate to get2DigitYearStart
    00016 *                            Removed subParseLong
    00017 *                            Removed getZoneIndex (added in DateFormatSymbols)
    00018 *   06/14/99    stephen     Removed fgTimeZoneDataSuffix
    00019 *   10/14/99    aliu        Updated class doc to describe 2-digit year parsing
    00020 *                           {j28 4182066}.
    00021 *******************************************************************************
    00022 */
    00023
    00024 #ifndef SMPDTFMT_H
    00025 #define SMPDTFMT_H
    00026
    00027 #include "unicode/utypes.h"
    00028
    00034 #if !UCONFIG_NO_FORMATTING
    00035
    00036 #include "unicode/datefmt.h"
    00037
    00038 U_NAMESPACE_BEGIN
    00039
    00040 class DateFormatSymbols;
    00041 class DateFormat;
    00042 class MessageFormat;
    00043 class FieldPositionHandler;
    00044
    00215 class U_I18N_API SimpleDateFormat: public DateFormat {
    00216 public:
    00226     SimpleDateFormat(UErrorCode& status);
    00227
    00239     SimpleDateFormat(const UnicodeString& pattern,
    00240                      UErrorCode& status);
    00241
    00263     SimpleDateFormat(const UnicodeString& pattern,
    00264                      const UnicodeString& override,
    00265                      UErrorCode& status);
    00266
    00279     SimpleDateFormat(const UnicodeString& pattern,
    00280                      const Locale& locale,
    00281                      UErrorCode& status);
    00282
    00304     SimpleDateFormat(const UnicodeString& pattern,
    00305                      const UnicodeString& override,
    00306                      const Locale& locale,
    00307                      UErrorCode& status);
    00308
    00318     SimpleDateFormat(const UnicodeString& pattern,
    00319                      DateFormatSymbols* formatDataToAdopt,
    00320                      UErrorCode& status);
    00321
    00331     SimpleDateFormat(const UnicodeString& pattern,
    00332                      const DateFormatSymbols& formatData,
    00333                      UErrorCode& status);
    00334
    00339     SimpleDateFormat(const SimpleDateFormat&);
    00340
    00345     SimpleDateFormat& operator=(const SimpleDateFormat&);
    00346
    00351     virtual ~SimpleDateFormat();
    00352
    00359     virtual Format* clone(void) const;
    00360
    00368     virtual UBool operator==(const Format& other) const;
    00369
    00370
    00371     using DateFormat::format;
    00372
    00389     virtual UnicodeString& format(  Calendar& cal,
    00390                                     UnicodeString& appendTo,
    00391                                     FieldPosition& pos) const;
    00392
    00411     virtual UnicodeString& format(  Calendar& cal,
    00412                                     UnicodeString& appendTo,
    00413                                     FieldPositionIterator* posIter,
    00414                                     UErrorCode& status) const;
    00415
    00435     virtual UnicodeString& format(  const Formattable& obj,
    00436                                     UnicodeString& appendTo,
    00437                                     FieldPosition& pos,
    00438                                     UErrorCode& status) const;
    00439
    00460     virtual UnicodeString& format(  const Formattable& obj,
    00461                                     UnicodeString& appendTo,
    00462                                     FieldPositionIterator* posIter,
    00463                                     UErrorCode& status) const;
    00464
    00475     UnicodeString& format(UDate date,
    00476                           UnicodeString& appendTo,
    00477                           FieldPosition& fieldPosition) const;
    00478
    00491     UnicodeString& format(UDate date,
    00492                           UnicodeString& appendTo,
    00493                           FieldPositionIterator* posIter,
    00494                           UErrorCode& status) const;
    00495
    00505     UnicodeString& format(const Formattable& obj,
    00506                           UnicodeString& appendTo,
    00507                           UErrorCode& status) const;
    00508
    00517     UnicodeString& format(UDate date, UnicodeString& appendTo) const;
    00518
    00538     virtual void parse( const UnicodeString& text,
    00539                         Calendar& cal,
    00540                         ParsePosition& pos) const;
    00541
    00561     UDate parse( const UnicodeString& text,
    00562                  ParsePosition& pos) const;
    00563
    00564
    00580     virtual UDate parse( const UnicodeString& text,
    00581                         UErrorCode& status) const;
    00582
    00599     virtual void set2DigitYearStart(UDate d, UErrorCode& status);
    00600
    00616     UDate get2DigitYearStart(UErrorCode& status) const;
    00617
    00624     virtual UnicodeString& toPattern(UnicodeString& result) const;
    00625
    00642     virtual UnicodeString& toLocalizedPattern(UnicodeString& result,
    00643                                               UErrorCode& status) const;
    00644
    00653     virtual void applyPattern(const UnicodeString& pattern);
    00654
    00665     virtual void applyLocalizedPattern(const UnicodeString& pattern,
    00666                                        UErrorCode& status);
    00667
    00676     virtual const DateFormatSymbols* getDateFormatSymbols(void) const;
    00677
    00684     virtual void adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols);
    00685
    00691     virtual void setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols);
    00692
    00704     static UClassID U_EXPORT2 getStaticClassID(void);
    00705
    00717     virtual UClassID getDynamicClassID(void) const;
    00718
    00728     virtual void adoptCalendar(Calendar* calendarToAdopt);
    00729
    00740     UBool isFieldUnitIgnored(UCalendarDateFields field) const;
    00741
    00742
    00754     static UBool isFieldUnitIgnored(const UnicodeString& pattern,
    00755                                     UCalendarDateFields field);
    00756
    00757
    00758
    00767     const Locale& getSmpFmtLocale(void) const;
    00768
    00769
    00770 private:
    00771     friend class DateFormat;
    00772
    00773     void initializeDefaultCentury(void);
    00774
    00775     SimpleDateFormat(); // default constructor not implemented
    00776
    00785     SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
    00786
    00795     SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
    00796
    00800     UnicodeString& _format(Calendar& cal, UnicodeString& appendTo, FieldPositionHandler& handler,
    00801            UErrorCode& status) const;
    00802
    00816     void subFormat(UnicodeString &appendTo,
    00817                    UChar ch,
    00818                    int32_t count,
    00819                    FieldPositionHandler& handler,
    00820                    Calendar& cal,
    00821                    UErrorCode& status) const; // in case of illegal argument
    00822
    00835     void zeroPaddingNumber(NumberFormat *currentNumberFormat,
    00836                            UnicodeString &appendTo,
    00837                            int32_t value,
    00838                            int32_t minDigits,
    00839                            int32_t maxDigits) const;
    00840
    00845     static UBool isNumeric(UChar formatChar, int32_t count);
    00846
    00854     Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status);
    00855
    00862     void initializeSymbols(const Locale& locale, Calendar* calendar, UErrorCode& status);
    00863
    00873     void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
    00874
    00881     void initialize(const Locale& locale, UErrorCode& status);
    00882
    00895     int32_t matchString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
    00896                         const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const;
    00897
    00910     int32_t matchQuarterString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
    00911                                const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const;
    00912
    00928     int32_t subParse(const UnicodeString& text, int32_t& start, UChar ch, int32_t count,
    00929                      UBool obeyCount, UBool allowNegative, UBool ambiguousYear[], int32_t& saveHebrewMonth, Calendar& cal,
    00930                      int32_t patLoc) const;
    00931
    00932     void parseInt(const UnicodeString& text,
    00933                   Formattable& number,
    00934                   ParsePosition& pos,
    00935                   UBool allowNegative,
    00936                   NumberFormat *fmt) const;
    00937
    00938     void parseInt(const UnicodeString& text,
    00939                   Formattable& number,
    00940                   int32_t maxDigits,
    00941                   ParsePosition& pos,
    00942                   UBool allowNegative,
    00943                   NumberFormat *fmt) const;
    00944
    00945     int32_t checkIntSuffix(const UnicodeString& text, int32_t start,
    00946                            int32_t patLoc, UBool isNegative) const;
    00947
    00960     static void translatePattern(const UnicodeString& originalPattern,
    00961                                 UnicodeString& translatedPattern,
    00962                                 const UnicodeString& from,
    00963                                 const UnicodeString& to,
    00964                                 UErrorCode& status);
    00965
    00973     void         parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status);
    00974
    00984     int32_t compareSimpleAffix(const UnicodeString& affix,
    00985                    const UnicodeString& input,
    00986                    int32_t pos) const;
    00987
    00992     int32_t skipRuleWhiteSpace(const UnicodeString& text, int32_t pos) const;
    00993
    00998     int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const;
    00999
    01003     void appendGMT(NumberFormat *currentNumberFormat,UnicodeString &appendTo, Calendar& cal, UErrorCode& status) const;
    01004     void formatGMTDefault(NumberFormat *currentNumberFormat,UnicodeString &appendTo, int32_t offset) const;
    01005     int32_t parseGMT(const UnicodeString &text, ParsePosition &pos) const;
    01006     int32_t parseGMTDefault(const UnicodeString &text, ParsePosition &pos) const;
    01007     UBool isDefaultGMTFormat() const;
    01008
    01009     void formatRFC822TZ(UnicodeString &appendTo, int32_t offset) const;
    01010
    01014     void initGMTFormatters(UErrorCode &status);
    01015
    01019     void initNumberFormatters(const Locale &locale,UErrorCode &status);
    01020
    01024     using DateFormat::getNumberFormat;    // Do not hide visibility of base class function
    01025     NumberFormat * getNumberFormat(UDateFormatField index) const;
    01026
    01030     void processOverrideString(const Locale &locale, const UnicodeString &str, int8_t type, UErrorCode &status);
    01031
    01035     static const UCalendarDateFields fgPatternIndexToCalendarField[];
    01036
    01040     static const UDateFormatField fgPatternIndexToDateFormatField[];
    01041
    01048     static const int32_t fgCalendarFieldToLevel[];
    01049     static const int32_t fgPatternCharToLevel[];
    01050
    01054     UnicodeString       fPattern;
    01055
    01059     UnicodeString       fDateOverride;
    01060
    01064     UnicodeString       fTimeOverride;
    01065
    01066
    01070     Locale              fLocale;
    01071
    01076     DateFormatSymbols*  fSymbols;   // Owned
    01077
    01086     UDate                fDefaultCenturyStart;
    01087
    01091     /*transient*/ int32_t   fDefaultCenturyStartYear;
    01092
    01093     enum ParsedTZType {
    01094         TZTYPE_UNK,
    01095         TZTYPE_STD,
    01096         TZTYPE_DST
    01097     };
    01098
    01099     ParsedTZType tztype; // here to avoid api change
    01100
    01101     typedef struct NSOverride {
    01102         NumberFormat *nf;
    01103         int32_t hash;
    01104         NSOverride *next;
    01105     } NSOverride;
    01106
    01107     /*
    01108      * MessageFormat instances used for localized GMT format
    01109      */
    01110     enum {
    01111         kGMTNegativeHMS = 0,
    01112         kGMTNegativeHM,
    01113         kGMTPositiveHMS,
    01114         kGMTPositiveHM,
    01115
    01116         kNumGMTFormatters
    01117     };
    01118     enum {
    01119         kGMTNegativeHMSMinLenIdx = 0,
    01120         kGMTPositiveHMSMinLenIdx,
    01121
    01122         kNumGMTFormatMinLengths
    01123     };
    01124
    01125     MessageFormat   **fGMTFormatters;
    01126     // If a GMT hour format has a second field, we need to make sure
    01127     // the length of input localized GMT string must match the expected
    01128     // length.  Otherwise, sub DateForamt handling offset format may
    01129     // unexpectedly success parsing input GMT string without second field.
    01130     // See #6880 about this issue.
    01131     // TODO: SimpleDateFormat should provide an option to invalidate
    01132     //
    01133     int32_t         fGMTFormatHmsMinLen[kNumGMTFormatMinLengths];
    01134
    01135     NumberFormat    **fNumberFormatters;
    01136
    01137     NSOverride      *fOverrideList;
    01138
    01139     UBool fHaveDefaultCentury;
    01140 };
    01141
    01142 inline UDate
    01143 SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const
    01144 {
    01145     return fDefaultCenturyStart;
    01146 }
    01147
    01148 inline UnicodeString&
    01149 SimpleDateFormat::format(const Formattable& obj,
    01150                          UnicodeString& appendTo,
    01151                          UErrorCode& status) const {
    01152     // Don't use Format:: - use immediate base class only,
    01153     // in case immediate base modifies behavior later.
    01154     return DateFormat::format(obj, appendTo, status);
    01155 }
    01156
    01157 inline UnicodeString&
    01158 SimpleDateFormat::format(const Formattable& obj,
    01159                          UnicodeString& appendTo,
    01160                          FieldPosition& pos,
    01161                          UErrorCode& status) const
    01162 {
    01163     // Don't use Format:: - use immediate base class only,
    01164     // in case immediate base modifies behavior later.
    01165     return DateFormat::format(obj, appendTo, pos, status);
    01166 }
    01167
    01168 inline UnicodeString&
    01169 SimpleDateFormat::format(const Formattable& obj,
    01170                          UnicodeString& appendTo,
    01171                          FieldPositionIterator* posIter,
    01172                          UErrorCode& status) const
    01173 {
    01174     // Don't use Format:: - use immediate base class only,
    01175     // in case immediate base modifies behavior later.
    01176     return DateFormat::format(obj, appendTo, posIter, status);
    01177 }
    01178
    01179 inline UnicodeString&
    01180 SimpleDateFormat::format(UDate date,
    01181                          UnicodeString& appendTo,
    01182                          FieldPosition& fieldPosition) const {
    01183     // Don't use Format:: - use immediate base class only,
    01184     // in case immediate base modifies behavior later.
    01185     return DateFormat::format(date, appendTo, fieldPosition);
    01186 }
    01187
    01188 inline UnicodeString&
    01189 SimpleDateFormat::format(UDate date,
    01190                          UnicodeString& appendTo,
    01191                          FieldPositionIterator* posIter,
    01192                          UErrorCode& status) const {
    01193     // Don't use Format:: - use immediate base class only,
    01194     // in case immediate base modifies behavior later.
    01195     return DateFormat::format(date, appendTo, posIter, status);
    01196 }
    01197
    01198 inline UnicodeString&
    01199 SimpleDateFormat::format(UDate date, UnicodeString& appendTo) const {
    01200     return DateFormat::format(date, appendTo);
    01201 }
    01202
    01203 U_NAMESPACE_END
    01204
    01205 #endif /* #if !UCONFIG_NO_FORMATTING */
    01206
    01207 #endif // _SMPDTFMT
    01208 //eof

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines