]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/unicode/dtfmtsym.h
ICU-400.37.tar.gz
[apple/icu.git] / icuSources / i18n / unicode / dtfmtsym.h
index 80eb670da88a91173a962b7e7223dbe957cf763d..a4b08bc3bd1177e548e2af304bf3c8cf4be73d45 100644 (file)
@@ -1,6 +1,6 @@
 /*  
 ********************************************************************************
-*   Copyright (C) 1997-2003, International Business Machines
+*   Copyright (C) 1997-2008, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 ********************************************************************************
 *
 
 #if !UCONFIG_NO_FORMATTING
 
+#include "unicode/calendar.h"
 #include "unicode/uobject.h"
 #include "unicode/locid.h"
-#include "unicode/resbund.h"
+#include "unicode/ures.h"
+
+/**
+ * \file 
+ * \brief C++ API: Symbols for formatting dates.
+ */
 
 U_NAMESPACE_BEGIN
 
 /* forward declaration */
 class SimpleDateFormat;
+class Hashtable;
+class ZoneStringFormat;
+class SafeZoneStringFormatPtr;
 
 /**
  * DateFormatSymbols is a public class for encapsulating localizable date-time
@@ -150,7 +159,7 @@ public:
      * subclassed.
      * @stable ICU 2.0
      */
-    ~DateFormatSymbols();
+    virtual ~DateFormatSymbols();
 
     /**
      * Return true if another object is semantically equal to this one.
@@ -171,7 +180,7 @@ public:
     UBool operator!=(const DateFormatSymbols& other) const { return !operator==(other); }
 
     /**
-     * Gets era strings. For example: "AD" and "BC".
+     * Gets abbreviated era strings. For example: "AD" and "BC".
      *
      * @param count    Filled in with length of the array.
      * @return         the era strings.
@@ -180,13 +189,47 @@ public:
     const UnicodeString* getEras(int32_t& count) const;
 
     /**
-     * Sets era strings. For example: "AD" and "BC".
+     * Sets abbreviated era strings. For example: "AD" and "BC".
      * @param eras  Array of era strings (DateFormatSymbols retains ownership.)
      * @param count Filled in with length of the array.
      * @stable ICU 2.0
      */
     void setEras(const UnicodeString* eras, int32_t count);
 
+    /**
+     * Gets era name strings. For example: "Anno Domini" and "Before Christ".
+     *
+     * @param count    Filled in with length of the array.
+     * @return         the era name strings.
+     * @stable ICU 3.4
+     */
+    const UnicodeString* getEraNames(int32_t& count) const;
+
+    /**
+     * Sets era name strings. For example: "Anno Domini" and "Before Christ".
+     * @param eraNames  Array of era name strings (DateFormatSymbols retains ownership.)
+     * @param count Filled in with length of the array.
+     * @stable ICU 3.6
+     */
+    void setEraNames(const UnicodeString* eraNames, int32_t count);
+
+    /**
+     * Gets narrow era strings. For example: A" and "D".
+     *
+     * @param count    Filled in with length of the array.
+     * @return         the narrow era strings.
+     * @draft ICU 4.2
+     */
+    const UnicodeString* getNarrowEras(int32_t& count) const;
+
+    /**
+     * Sets narrow era strings. For example: "A" and "B".
+     * @param narrowEras  Array of narrow era strings (DateFormatSymbols retains ownership.)
+     * @param count Filled in with length of the array.
+     * @draft ICU 4.2
+     */
+    void setNarrowEras(const UnicodeString* narrowEras, int32_t count);
+
     /**
      * Gets month strings. For example: "January", "February", etc.
      * @param count Filled in with length of the array.
@@ -221,6 +264,48 @@ public:
      */
     void setShortMonths(const UnicodeString* shortMonths, int32_t count);
 
+    /**
+     * Selector for date formatting context
+     * @stable ICU 3.6
+     */
+    enum DtContextType {
+         FORMAT,
+         STANDALONE,
+         DT_CONTEXT_COUNT
+    };
+
+    /**
+     * Selector for date formatting width
+     * @stable ICU 3.6
+     */
+    enum DtWidthType {
+         ABBREVIATED,
+         WIDE,
+         NARROW,
+         DT_WIDTH_COUNT
+    };
+
+    /**
+     * Gets month strings by width and context. For example: "January", "February", etc.
+     * @param count Filled in with length of the array.
+     * @param context The formatting context, either FORMAT or STANDALONE
+     * @param width   The width of returned strings, either WIDE, ABBREVIATED, or NARROW.
+     * @return the month strings. (DateFormatSymbols retains ownership.)
+     * @stable ICU 3.4
+     */
+    const UnicodeString* getMonths(int32_t& count, DtContextType context, DtWidthType width) const;
+
+    /**
+     * Sets month strings by width and context. For example: "January", "February", etc.
+     *
+     * @param months  The new month strings. (not adopted; caller retains ownership)
+     * @param count   Filled in with length of the array.
+     * @param context The formatting context, either FORMAT or STANDALONE
+     * @param width   The width of returned strings, either WIDE, ABBREVIATED, or NARROW.
+     * @stable ICU 3.6
+     */
+    void setMonths(const UnicodeString* months, int32_t count, DtContextType context, DtWidthType width);
+
     /**
      * Gets weekday strings. For example: "Sunday", "Monday", etc.
      * @param count        Filled in with length of the array.
@@ -229,6 +314,7 @@ public:
      */
     const UnicodeString* getWeekdays(int32_t& count) const;
 
+
     /**
      * Sets weekday strings. For example: "Sunday", "Monday", etc.
      * @param weekdays     the new weekday strings. (not adopted; caller retains ownership)
@@ -253,6 +339,49 @@ public:
      */
     void setShortWeekdays(const UnicodeString* shortWeekdays, int32_t count);
 
+    /**
+     * Gets weekday strings by width and context. For example: "Sunday", "Monday", etc.
+     * @param count   Filled in with length of the array.
+     * @param context The formatting context, either FORMAT or STANDALONE
+     * @param width   The width of returned strings, either WIDE, ABBREVIATED, or NARROW
+     * @return the month strings. (DateFormatSymbols retains ownership.)
+     * @stable ICU 3.4
+     */
+    const UnicodeString* getWeekdays(int32_t& count, DtContextType context, DtWidthType width) const;
+
+    /**
+     * Sets weekday strings by width and context. For example: "Sunday", "Monday", etc.
+     * @param weekdays  The new weekday strings. (not adopted; caller retains ownership)
+     * @param count     Filled in with length of the array.
+     * @param context   The formatting context, either FORMAT or STANDALONE
+     * @param width     The width of returned strings, either WIDE, ABBREVIATED, or NARROW
+     * @stable ICU 3.6
+     */
+    void setWeekdays(const UnicodeString* weekdays, int32_t count, DtContextType context, DtWidthType width);
+
+    /**
+     * Gets quarter strings by width and context. For example: "1st Quarter", "2nd Quarter", etc.
+     * @param count Filled in with length of the array.
+     * @param context The formatting context, either FORMAT or STANDALONE
+     * @param width   The width of returned strings, either WIDE or ABBREVIATED. There
+     *                are no NARROW quarters.
+     * @return the quarter strings. (DateFormatSymbols retains ownership.)
+     * @stable ICU 3.6
+     */
+    const UnicodeString* getQuarters(int32_t& count, DtContextType context, DtWidthType width) const;
+
+    /**
+     * Sets quarter strings by width and context. For example: "1st Quarter", "2nd Quarter", etc.
+     *
+     * @param quarters  The new quarter strings. (not adopted; caller retains ownership)
+     * @param count   Filled in with length of the array.
+     * @param context The formatting context, either FORMAT or STANDALONE
+     * @param width   The width of returned strings, either WIDE or ABBREVIATED. There
+     *                are no NARROW quarters.
+     * @stable ICU 3.6
+     */
+    void setQuarters(const UnicodeString* quarters, int32_t count, DtContextType context, DtWidthType width);
+
     /**
      * Gets AM/PM strings. For example: "AM" and "PM".
      * @param count        Filled in with length of the array.
@@ -274,7 +403,7 @@ public:
      * @param rowCount      Output param to receive number of rows.
      * @param columnCount   Output param to receive number of columns.
      * @return              The timezone strings as a 2-d array. (DateFormatSymbols retains ownership.)
-     * @stable ICU 2.0
+     * @deprecated ICU 3.6
      */
     const UnicodeString** getZoneStrings(int32_t& rowCount, int32_t& columnCount) const;
 
@@ -292,10 +421,14 @@ public:
      * @return    the non-localized date-time pattern characters
      * @stable ICU 2.0
      */
-    static const UChar *getPatternUChars(void);
+    static const UChar * U_EXPORT2 getPatternUChars(void);
 
     /**
      * Gets localized date-time pattern characters. For example: 'u', 't', etc.
+     * <p>
+     * Note: ICU no longer provides localized date-time pattern characters for a locale
+     * starting ICU 3.8.  This method returns the non-localized date-time pattern
+     * characters unless user defined localized data is set by setLocalPatternChars.
      * @param result    Output param which will receive the localized date-time pattern characters.
      * @return          A reference to 'result'.
      * @stable ICU 2.0
@@ -310,43 +443,50 @@ public:
      */
     void setLocalPatternChars(const UnicodeString& newLocalPatternChars);
 
+    /**
+     * Returns the locale for this object. Two flavors are available:
+     * valid and actual locale.
+     * @stable ICU 2.8
+     */
+    Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
+
     /**
      * ICU "poor man's RTTI", returns a UClassID for the actual class.
      *
-     * @draft ICU 2.2
+     * @stable ICU 2.2
      */
-    virtual inline UClassID getDynamicClassID() const;
+    virtual UClassID getDynamicClassID() const;
 
     /**
      * ICU "poor man's RTTI", returns a UClassID for this class.
      *
-     * @draft ICU 2.2
+     * @stable ICU 2.2
      */
-    static inline UClassID getStaticClassID();
+    static UClassID U_EXPORT2 getStaticClassID();
 
 private:
-    /**
-     * Tag names used by this class.
-     */
-    static const char fgErasTag[];   // resource bundle tag for era names
-    static const char fgMonthNamesTag[]; // resource bundle tag for month names
-    static const char fgMonthAbbreviationsTag[]; // resource bundle tag for month abbreviations
-    static const char fgDayNamesTag[];   // resource bundle tag for day names
-    static const char fgDayAbbreviationsTag[];   // resource bundle tag for day abbreviations
-    static const char fgAmPmMarkersTag[];    // resource bundle tag for AM/PM strings
-
-    static const char fgZoneStringsTag[];    // resource bundle tag for time zone names
-    static const char fgLocalPatternCharsTag[];  // resource bundle tag for localized pattern characters
 
     friend class SimpleDateFormat;
     friend class DateFormatSymbolsSingleSetter; // see udat.cpp
 
     /**
-     * Era strings. For example: "AD" and "BC".
+     * Abbreviated era strings. For example: "AD" and "BC".
      */
     UnicodeString*  fEras;
     int32_t         fErasCount;
 
+    /**
+     * Era name strings. For example: "Anno Domini" and "Before Christ".
+     */
+    UnicodeString*  fEraNames;
+    int32_t         fEraNamesCount;
+
+    /**
+     * Narrow era strings. For example: "A" and "B".
+     */
+    UnicodeString*  fNarrowEras;
+    int32_t         fNarrowErasCount;
+
     /**
      * Month strings. For example: "January", "February", etc.
      */
@@ -359,6 +499,30 @@ private:
     UnicodeString*  fShortMonths;
     int32_t         fShortMonthsCount;
 
+    /**
+     * Narrow month strings. For example: "J", "F", etc.
+     */
+    UnicodeString*  fNarrowMonths;
+    int32_t         fNarrowMonthsCount;
+
+    /**
+     * Standalone Month strings. For example: "January", "February", etc.
+     */
+    UnicodeString*  fStandaloneMonths;
+    int32_t         fStandaloneMonthsCount;
+
+    /**
+     * Standalone Short month strings. For example: "Jan", "Feb", etc.
+     */
+    UnicodeString*  fStandaloneShortMonths;
+    int32_t         fStandaloneShortMonthsCount;
+
+    /**
+     * Standalone Narrow month strings. For example: "J", "F", etc.
+     */
+    UnicodeString*  fStandaloneNarrowMonths;
+    int32_t         fStandaloneNarrowMonthsCount;
+
     /**
      * Weekday strings. For example: "Sunday", "Monday", etc.
      */
@@ -371,6 +535,30 @@ private:
     UnicodeString*  fShortWeekdays;
     int32_t         fShortWeekdaysCount;
 
+    /**
+     * Narrow weekday strings. For example: "Sun", "Mon", etc.
+     */
+    UnicodeString*  fNarrowWeekdays;
+    int32_t         fNarrowWeekdaysCount;
+
+    /**
+     * Standalone Weekday strings. For example: "Sunday", "Monday", etc.
+     */
+    UnicodeString*  fStandaloneWeekdays;
+    int32_t         fStandaloneWeekdaysCount;
+
+    /**
+     * Standalone Short weekday strings. For example: "Sun", "Mon", etc.
+     */
+    UnicodeString*  fStandaloneShortWeekdays;
+    int32_t         fStandaloneShortWeekdaysCount;
+
+    /**
+     * Standalone Narrow weekday strings. For example: "Sun", "Mon", etc.
+     */
+    UnicodeString*  fStandaloneNarrowWeekdays;
+    int32_t         fStandaloneNarrowWeekdaysCount;
+
     /**
      * Ampm strings. For example: "AM" and "PM".
      */
@@ -378,60 +566,74 @@ private:
     int32_t         fAmPmsCount;
 
     /**
-     * The format data of all the timezones in this locale.
+     * Quarter strings. For example: "1st quarter", "2nd quarter", etc.
      */
-    UnicodeString** fZoneStrings;
-    int32_t         fZoneStringsRowCount;
-    int32_t         fZoneStringsColCount;
+    UnicodeString  *fQuarters;
+    int32_t         fQuartersCount;
 
     /**
-     * Localized date-time pattern characters. For example: use 'u' as 'y'.
+     * Short quarters. For example: "Q1", "Q2", etc.
      */
-    UnicodeString   fLocalPatternChars;
+    UnicodeString  *fShortQuarters;
+    int32_t         fShortQuartersCount;
 
     /**
-     * The address of this static class variable serves as this class's ID
-     * for ICU "poor man's RTTI".
+     * Standalone quarter strings. For example: "1st quarter", "2nd quarter", etc.
      */
-    static const char fgClassID;
-
-private:
+    UnicodeString  *fStandaloneQuarters;
+    int32_t         fStandaloneQuartersCount;
 
-    /* Sizes for the last resort string arrays */
-    typedef enum LastResortSize {
-        kMonthNum = 13,
-        kMonthLen = 3,
-
-        kDayNum = 8,
-        kDayLen = 2,
+    /**
+     * Standalone short quarter strings. For example: "Q1", "Q2", etc.
+     */
+    UnicodeString  *fStandaloneShortQuarters;
+    int32_t         fStandaloneShortQuartersCount;
 
-        kAmPmNum = 2,
-        kAmPmLen = 3,
+    /**
+     * The format data of all the timezones in this locale.
+     */
+    UnicodeString   **fZoneStrings;         // Zone string array set by setZoneStrings
+    UnicodeString   **fLocaleZoneStrings;   // Zone string array created by the locale
+    int32_t         fZoneStringsRowCount;
+    int32_t         fZoneStringsColCount;
 
-        kEraNum = 2,
-        kEraLen = 3,
+    const ZoneStringFormat  *fZoneStringFormat;
+    ZoneStringFormat        *fZSFLocal;         // Local ZoneStringFormat instance
+    SafeZoneStringFormatPtr *fZSFCachePtr;      // Cached ZoneStringFormat
+    Locale                  fZSFLocale;         // Locale used for getting ZoneStringFormat
 
-        kZoneNum = 5,
-        kZoneLen = 4
-    } LastResortSize;
+    /**
+     * Pattern string used for localized time zone GMT format.  For example, "GMT{0}"
+     */
+    UnicodeString   fGmtFormat;
 
-    DateFormatSymbols(); // default constructor not implemented
+    /**
+     * Pattern strings used for formatting zone offset in a localized time zone GMT string.
+     */
+    UnicodeString  *fGmtHourFormats;
+    int32_t         fGmtHourFormatsCount; 
 
-    void initField(UnicodeString **field, int32_t& length, const ResourceBundle data, UErrorCode &status);
-    void initField(UnicodeString **field, int32_t& length, const UChar *data, LastResortSize numStr, LastResortSize strLen, UErrorCode &status);
+    enum GMTHourType {
+        GMT_NEGATIVE_HMS = 0,
+        GMT_NEGATIVE_HM,
+        GMT_POSITIVE_HMS,
+        GMT_POSITIVE_HM,
+        GMT_HOUR_COUNT
+    };
 
     /**
-     * Load data for specified 'type', falling back to gregorian if needed
-     *
-     * @param rb ResourceBundle
-     * @param tag Resource key to data
-     * @param type Calendar type
-     * @param status Error Status
-     * @internal
+     * Localized date-time pattern characters. For example: use 'u' as 'y'.
+     */
+    UnicodeString   fLocalPatternChars;
+
+private:
+    /** valid/actual locale information 
+     *  these are always ICU locales, so the length should not be a problem
      */
-    static ResourceBundle
-      getData(ResourceBundle &rb, const char *tag, const char *type, UErrorCode& status);
+    char validLocale[ULOC_FULLNAME_CAPACITY];
+    char actualLocale[ULOC_FULLNAME_CAPACITY];
 
+    DateFormatSymbols(); // default constructor not implemented
 
     /**
      * Called by the constructors to actually load data from the resources
@@ -478,21 +680,6 @@ private:
      */
     void createZoneStrings(const UnicodeString *const * otherStrings);
 
-    /**
-     * Package private: used by SimpleDateFormat
-     * Gets the index for the given time zone ID to obtain the timezone
-     * strings for formatting. The time zone ID is just for programmatic
-     * lookup. NOT LOCALIZED!!!
-     * @param ID the given time zone ID.
-     * @return the index of the given time zone ID.  Returns -1 if
-     * the given time zone ID can't be located in the DateFormatSymbols object.
-     * @see java.util.SimpleTimeZone
-     */
-    int32_t getZoneIndex(const UnicodeString& ID) const;
-
-    // Internal method; see source for documentation
-    int32_t _getZoneIndex(const UnicodeString& id) const;
-
     /**
      * Delete all the storage owned by this object.
      */
@@ -504,20 +691,28 @@ private:
      */
     void copyData(const DateFormatSymbols& other);
 
+
+    /**
+     * Returns a ZoneStringFormat, used only by SimpleDateFormat for now.
+     */
+    const ZoneStringFormat* getZoneStringFormat(void) const;
+
+    /**
+     * Create a ZoneStringFormat by locale if not yet availble
+     */
+    void initZoneStringFormat(void);
+
+    /**
+     * Create zone strings array by locale if not yet available
+     */
+    void initZoneStringsArray(void);
+
     /**
      * Delete just the zone strings.
      */
     void disposeZoneStrings(void);
 };
 
-inline UClassID
-DateFormatSymbols::getStaticClassID()
-{ return (UClassID)&fgClassID; }
-
-inline UClassID
-DateFormatSymbols::getDynamicClassID() const
-{ return DateFormatSymbols::getStaticClassID(); }
-
 U_NAMESPACE_END
 
 #endif /* #if !UCONFIG_NO_FORMATTING */