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

- Search for |

- File List
- Globals

# smpdtfmt.h

Go to the documentation of this file.

    00001 /*
    00002 * Copyright (C) 1997-2009, International Business Machines Corporation and others. All Rights Reserved.
    00003 *******************************************************************************
    00004 *
    00005 * File SMPDTFMT.H
    00006 *
    00007 * Modification History:
    00008 *
    00009 *   Date        Name        Description
    00010 *   02/19/97    aliu        Converted from java.
    00011 *   07/09/97    helena      Make ParsePosition into a class.
    00012 *   07/21/98    stephen     Added GMT_PLUS, GMT_MINUS
    00013 *                            Changed setTwoDigitStartDate to set2DigitYearStart
    00014 *                            Changed getTwoDigitStartDate to get2DigitYearStart
    00015 *                            Removed subParseLong
    00016 *                            Removed getZoneIndex (added in DateFormatSymbols)
    00017 *   06/14/99    stephen     Removed fgTimeZoneDataSuffix
    00018 *   10/14/99    aliu        Updated class doc to describe 2-digit year parsing
    00019 *                           {j28 4182066}.
    00020 *******************************************************************************
    00021 */
    00022
    00023 #ifndef SMPDTFMT_H
    00024 #define SMPDTFMT_H
    00025
    00026 #include "unicode/utypes.h"
    00027
    00033 #if !UCONFIG_NO_FORMATTING
    00034
    00035 #include "unicode/datefmt.h"
    00036
    00037 U_NAMESPACE_BEGIN
    00038
    00039 class DateFormatSymbols;
    00040 class DateFormat;
    00041 class MessageFormat;
    00042
    00213 class U_I18N_API SimpleDateFormat: public DateFormat {
    00214 public:
    00224     SimpleDateFormat(UErrorCode& status);
    00225
    00237     SimpleDateFormat(const UnicodeString& pattern,
    00238                      UErrorCode& status);
    00239
    00261     SimpleDateFormat(const UnicodeString& pattern,
    00262                      const UnicodeString& override,
    00263                      UErrorCode& status);
    00264
    00277     SimpleDateFormat(const UnicodeString& pattern,
    00278                      const Locale& locale,
    00279                      UErrorCode& status);
    00280
    00302     SimpleDateFormat(const UnicodeString& pattern,
    00303                      const UnicodeString& override,
    00304                      const Locale& locale,
    00305                      UErrorCode& status);
    00306
    00316     SimpleDateFormat(const UnicodeString& pattern,
    00317                      DateFormatSymbols* formatDataToAdopt,
    00318                      UErrorCode& status);
    00319
    00329     SimpleDateFormat(const UnicodeString& pattern,
    00330                      const DateFormatSymbols& formatData,
    00331                      UErrorCode& status);
    00332
    00337     SimpleDateFormat(const SimpleDateFormat&);
    00338
    00343     SimpleDateFormat& operator=(const SimpleDateFormat&);
    00344
    00349     virtual ~SimpleDateFormat();
    00350
    00357     virtual Format* clone(void) const;
    00358
    00366     virtual UBool operator==(const Format& other) const;
    00367
    00384     virtual UnicodeString& format(  Calendar& cal,
    00385                                     UnicodeString& appendTo,
    00386                                     FieldPosition& pos) const;
    00387
    00407     virtual UnicodeString& format(  const Formattable& obj,
    00408                                     UnicodeString& appendTo,
    00409                                     FieldPosition& pos,
    00410                                     UErrorCode& status) const;
    00411
    00422     UnicodeString& format(UDate date,
    00423                           UnicodeString& appendTo,
    00424                           FieldPosition& fieldPosition) const;
    00425
    00435     UnicodeString& format(const Formattable& obj,
    00436                           UnicodeString& appendTo,
    00437                           UErrorCode& status) const;
    00438
    00447     UnicodeString& format(UDate date, UnicodeString& appendTo) const;
    00448
    00468     virtual void parse( const UnicodeString& text,
    00469                         Calendar& cal,
    00470                         ParsePosition& pos) const;
    00471
    00491     UDate parse( const UnicodeString& text,
    00492                  ParsePosition& pos) const;
    00493
    00494
    00510     virtual UDate parse( const UnicodeString& text,
    00511                         UErrorCode& status) const;
    00512
    00529     virtual void set2DigitYearStart(UDate d, UErrorCode& status);
    00530
    00546     UDate get2DigitYearStart(UErrorCode& status) const;
    00547
    00554     virtual UnicodeString& toPattern(UnicodeString& result) const;
    00555
    00572     virtual UnicodeString& toLocalizedPattern(UnicodeString& result,
    00573                                               UErrorCode& status) const;
    00574
    00583     virtual void applyPattern(const UnicodeString& pattern);
    00584
    00595     virtual void applyLocalizedPattern(const UnicodeString& pattern,
    00596                                        UErrorCode& status);
    00597
    00606     virtual const DateFormatSymbols* getDateFormatSymbols(void) const;
    00607
    00614     virtual void adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols);
    00615
    00621     virtual void setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols);
    00622
    00634     static UClassID U_EXPORT2 getStaticClassID(void);
    00635
    00647     virtual UClassID getDynamicClassID(void) const;
    00648
    00658     virtual void adoptCalendar(Calendar* calendarToAdopt);
    00659
    00670     UBool isFieldUnitIgnored(UCalendarDateFields field) const;
    00671
    00672
    00684     static UBool isFieldUnitIgnored(const UnicodeString& pattern,
    00685                                     UCalendarDateFields field);
    00686
    00687
    00688
    00697     const Locale& getSmpFmtLocale(void) const;
    00698
    00699
    00700 private:
    00701     friend class DateFormat;
    00702
    00703     void initializeDefaultCentury(void);
    00704
    00705     SimpleDateFormat(); // default constructor not implemented
    00706
    00715     SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
    00716
    00725     SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
    00726
    00743     void subFormat(             UnicodeString &appendTo,
    00744                                 UChar ch,
    00745                                 int32_t count,
    00746                                 FieldPosition& pos,
    00747                                 Calendar& cal,
    00748                                 UErrorCode& status) const; // in case of illegal argument
    00749
    00762     void zeroPaddingNumber(          NumberFormat *currentNumberFormat,
    00763                                      UnicodeString &appendTo,
    00764                                      int32_t value,
    00765                                      int32_t minDigits,
    00766                                      int32_t maxDigits) const;
    00767
    00772     static UBool isNumeric(UChar formatChar, int32_t count);
    00773
    00781     Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status);
    00782
    00789     void initializeSymbols(const Locale& locale, Calendar* calendar, UErrorCode& status);
    00790
    00800     void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
    00801
    00808     void initialize(const Locale& locale, UErrorCode& status);
    00809
    00822     int32_t matchString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
    00823                         const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const;
    00824
    00837     int32_t matchQuarterString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
    00838                                const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const;
    00839
    00854     int32_t subParse(const UnicodeString& text, int32_t& start, UChar ch, int32_t count,
    00855                      UBool obeyCount, UBool allowNegative, UBool ambiguousYear[], Calendar& cal,
    00856                      int32_t patLoc) const;
    00857
    00858     void parseInt(const UnicodeString& text,
    00859                   Formattable& number,
    00860                   ParsePosition& pos,
    00861                   UBool allowNegative,
    00862                   NumberFormat *fmt) const;
    00863
    00864     void parseInt(const UnicodeString& text,
    00865                   Formattable& number,
    00866                   int32_t maxDigits,
    00867                   ParsePosition& pos,
    00868                   UBool allowNegative,
    00869                   NumberFormat *fmt) const;
    00870
    00871     int32_t checkIntSuffix(const UnicodeString& text, int32_t start,
    00872                            int32_t patLoc, UBool isNegative) const;
    00873
    00886     static void translatePattern(const UnicodeString& originalPattern,
    00887                                 UnicodeString& translatedPattern,
    00888                                 const UnicodeString& from,
    00889                                 const UnicodeString& to,
    00890                                 UErrorCode& status);
    00891
    00899     void         parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status);
    00900
    00910     int32_t compareSimpleAffix(const UnicodeString& affix,
    00911                    const UnicodeString& input,
    00912                    int32_t pos) const;
    00913
    00918     int32_t skipRuleWhiteSpace(const UnicodeString& text, int32_t pos) const;
    00919
    00924     int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const;
    00925
    00929     void appendGMT(NumberFormat *currentNumberFormat,UnicodeString &appendTo, Calendar& cal, UErrorCode& status) const;
    00930     void formatGMTDefault(NumberFormat *currentNumberFormat,UnicodeString &appendTo, int32_t offset) const;
    00931     int32_t parseGMT(const UnicodeString &text, ParsePosition &pos) const;
    00932     int32_t parseGMTDefault(const UnicodeString &text, ParsePosition &pos) const;
    00933     UBool isDefaultGMTFormat() const;
    00934
    00935     void formatRFC822TZ(UnicodeString &appendTo, int32_t offset) const;
    00936
    00940     void initGMTFormatters(UErrorCode &status);
    00941
    00945     void initNumberFormatters(const Locale &locale,UErrorCode &status);
    00946
    00950     NumberFormat * getNumberFormat(UDateFormatField index) const;
    00951
    00955     void processOverrideString(const Locale &locale, const UnicodeString &str, int8_t type, UErrorCode &status);
    00956
    00960     static const UCalendarDateFields fgPatternIndexToCalendarField[];
    00961
    00965     static const UDateFormatField fgPatternIndexToDateFormatField[];
    00966
    00973     static const int32_t fgCalendarFieldToLevel[];
    00974     static const int32_t fgPatternCharToLevel[];
    00975
    00979     UnicodeString       fPattern;
    00980
    00984     UnicodeString       fDateOverride;
    00985
    00989     UnicodeString       fTimeOverride;
    00990
    00991
    00995     Locale              fLocale;
    00996
    01001     DateFormatSymbols*  fSymbols;   // Owned
    01002
    01011     UDate                fDefaultCenturyStart;
    01012
    01016     /*transient*/ int32_t   fDefaultCenturyStartYear;
    01017
    01018     enum ParsedTZType {
    01019         TZTYPE_UNK,
    01020         TZTYPE_STD,
    01021         TZTYPE_DST
    01022     };
    01023
    01024     ParsedTZType tztype; // here to avoid api change
    01025
    01026     typedef struct NSOverride {
    01027         NumberFormat *nf;
    01028         int32_t hash;
    01029         NSOverride *next;
    01030     } NSOverride;
    01031
    01032     /*
    01033      * MessageFormat instances used for localized GMT format
    01034      */
    01035     MessageFormat   **fGMTFormatters;
    01036
    01037     NumberFormat    **fNumberFormatters;
    01038
    01039     NSOverride      *fOverrideList;
    01040
    01041     UBool fHaveDefaultCentury;
    01042 };
    01043
    01044 inline UDate
    01045 SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const
    01046 {
    01047     return fDefaultCenturyStart;
    01048 }
    01049
    01050 inline UnicodeString&
    01051 SimpleDateFormat::format(const Formattable& obj,
    01052                          UnicodeString& appendTo,
    01053                          UErrorCode& status) const {
    01054     // Don't use Format:: - use immediate base class only,
    01055     // in case immediate base modifies behavior later.
    01056     return DateFormat::format(obj, appendTo, status);
    01057 }
    01058
    01059 inline UnicodeString&
    01060 SimpleDateFormat::format(UDate date,
    01061                          UnicodeString& appendTo,
    01062                          FieldPosition& fieldPosition) const {
    01063     // Don't use Format:: - use immediate base class only,
    01064     // in case immediate base modifies behavior later.
    01065     return DateFormat::format(date, appendTo, fieldPosition);
    01066 }
    01067
    01068 inline UnicodeString&
    01069 SimpleDateFormat::format(UDate date, UnicodeString& appendTo) const {
    01070     return DateFormat::format(date, appendTo);
    01071 }
    01072
    01073 U_NAMESPACE_END
    01074
    01075 #endif /* #if !UCONFIG_NO_FORMATTING */
    01076
    01077 #endif // _SMPDTFMT
    01078 //eof