jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ******************************************************************************** jpayne@69: * Copyright (C) 1997-2016, International Business Machines jpayne@69: * Corporation and others. All Rights Reserved. jpayne@69: ******************************************************************************** jpayne@69: * jpayne@69: * File DTFMTSYM.H jpayne@69: * jpayne@69: * Modification History: jpayne@69: * jpayne@69: * Date Name Description jpayne@69: * 02/19/97 aliu Converted from java. jpayne@69: * 07/21/98 stephen Added getZoneIndex() jpayne@69: * Changed to match C++ conventions jpayne@69: ******************************************************************************** jpayne@69: */ jpayne@69: jpayne@69: #ifndef DTFMTSYM_H jpayne@69: #define DTFMTSYM_H jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: #if !UCONFIG_NO_FORMATTING jpayne@69: jpayne@69: #include "unicode/calendar.h" jpayne@69: #include "unicode/strenum.h" jpayne@69: #include "unicode/uobject.h" jpayne@69: #include "unicode/locid.h" jpayne@69: #include "unicode/udat.h" jpayne@69: #include "unicode/ures.h" jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C++ API: Symbols for formatting dates. jpayne@69: */ jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: /* forward declaration */ jpayne@69: class SimpleDateFormat; jpayne@69: class Hashtable; jpayne@69: jpayne@69: /** jpayne@69: * DateFormatSymbols is a public class for encapsulating localizable date-time jpayne@69: * formatting data -- including timezone data. DateFormatSymbols is used by jpayne@69: * DateFormat and SimpleDateFormat. jpayne@69: *

jpayne@69: * Rather than first creating a DateFormatSymbols to get a date-time formatter jpayne@69: * by using a SimpleDateFormat constructor, clients are encouraged to create a jpayne@69: * date-time formatter using the getTimeInstance(), getDateInstance(), or jpayne@69: * getDateTimeInstance() method in DateFormat. Each of these methods can return a jpayne@69: * date/time formatter initialized with a default format pattern along with the jpayne@69: * date-time formatting data for a given or default locale. After a formatter is jpayne@69: * created, clients may modify the format pattern using the setPattern function jpayne@69: * as so desired. For more information on using these formatter factory jpayne@69: * functions, see DateFormat. jpayne@69: *

jpayne@69: * If clients decide to create a date-time formatter with a particular format jpayne@69: * pattern and locale, they can do so with new SimpleDateFormat(aPattern, jpayne@69: * new DateFormatSymbols(aLocale)). This will load the appropriate date-time jpayne@69: * formatting data from the locale. jpayne@69: *

jpayne@69: * DateFormatSymbols objects are clonable. When clients obtain a jpayne@69: * DateFormatSymbols object, they can feel free to modify the date-time jpayne@69: * formatting data as necessary. For instance, clients can jpayne@69: * replace the localized date-time format pattern characters with the ones that jpayne@69: * they feel easy to remember. Or they can change the representative cities jpayne@69: * originally picked by default to using their favorite ones. jpayne@69: *

jpayne@69: * DateFormatSymbols are not expected to be subclassed. Data for a calendar is jpayne@69: * loaded out of resource bundles. The 'type' parameter indicates the type of jpayne@69: * calendar, for example, "gregorian" or "japanese". If the type is not gregorian jpayne@69: * (or NULL, or an empty string) then the type is appended to the resource name, jpayne@69: * for example, 'Eras_japanese' instead of 'Eras'. If the resource 'Eras_japanese' did jpayne@69: * not exist (even in root), then this class will fall back to just 'Eras', that is, jpayne@69: * Gregorian data. Therefore, the calendar implementor MUST ensure that the root jpayne@69: * locale at least contains any resources that are to be particularized for the jpayne@69: * calendar type. jpayne@69: */ jpayne@69: class U_I18N_API DateFormatSymbols U_FINAL : public UObject { jpayne@69: public: jpayne@69: /** jpayne@69: * Construct a DateFormatSymbols object by loading format data from jpayne@69: * resources for the default locale, in the default calendar (Gregorian). jpayne@69: *

jpayne@69: * NOTE: This constructor will never fail; if it cannot get resource jpayne@69: * data for the default locale, it will return a last-resort object jpayne@69: * based on hard-coded strings. jpayne@69: * jpayne@69: * @param status Status code. Failure jpayne@69: * results if the resources for the default cannot be jpayne@69: * found or cannot be loaded jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: DateFormatSymbols(UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Construct a DateFormatSymbols object by loading format data from jpayne@69: * resources for the given locale, in the default calendar (Gregorian). jpayne@69: * jpayne@69: * @param locale Locale to load format data from. jpayne@69: * @param status Status code. Failure jpayne@69: * results if the resources for the locale cannot be jpayne@69: * found or cannot be loaded jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: DateFormatSymbols(const Locale& locale, jpayne@69: UErrorCode& status); jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * Construct a DateFormatSymbols object by loading format data from jpayne@69: * resources for the default locale, in the default calendar (Gregorian). jpayne@69: *

jpayne@69: * NOTE: This constructor will never fail; if it cannot get resource jpayne@69: * data for the default locale, it will return a last-resort object jpayne@69: * based on hard-coded strings. jpayne@69: * jpayne@69: * @param type Type of calendar (as returned by Calendar::getType). jpayne@69: * Will be used to access the correct set of strings. jpayne@69: * (NULL or empty string defaults to "gregorian".) jpayne@69: * @param status Status code. Failure jpayne@69: * results if the resources for the default cannot be jpayne@69: * found or cannot be loaded jpayne@69: * @internal jpayne@69: */ jpayne@69: DateFormatSymbols(const char *type, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Construct a DateFormatSymbols object by loading format data from jpayne@69: * resources for the given locale, in the default calendar (Gregorian). jpayne@69: * jpayne@69: * @param locale Locale to load format data from. jpayne@69: * @param type Type of calendar (as returned by Calendar::getType). jpayne@69: * Will be used to access the correct set of strings. jpayne@69: * (NULL or empty string defaults to "gregorian".) jpayne@69: * @param status Status code. Failure jpayne@69: * results if the resources for the locale cannot be jpayne@69: * found or cannot be loaded jpayne@69: * @internal jpayne@69: */ jpayne@69: DateFormatSymbols(const Locale& locale, jpayne@69: const char *type, jpayne@69: UErrorCode& status); jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: /** jpayne@69: * Copy constructor. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: DateFormatSymbols(const DateFormatSymbols&); jpayne@69: jpayne@69: /** jpayne@69: * Assignment operator. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: DateFormatSymbols& operator=(const DateFormatSymbols&); jpayne@69: jpayne@69: /** jpayne@69: * Destructor. This is nonvirtual because this class is not designed to be jpayne@69: * subclassed. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual ~DateFormatSymbols(); jpayne@69: jpayne@69: /** jpayne@69: * Return true if another object is semantically equal to this one. jpayne@69: * jpayne@69: * @param other the DateFormatSymbols object to be compared with. jpayne@69: * @return true if other is semantically equal to this. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UBool operator==(const DateFormatSymbols& other) const; jpayne@69: jpayne@69: /** jpayne@69: * Return true if another object is semantically unequal to this one. jpayne@69: * jpayne@69: * @param other the DateFormatSymbols object to be compared with. jpayne@69: * @return true if other is semantically unequal to this. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UBool operator!=(const DateFormatSymbols& other) const { return !operator==(other); } jpayne@69: jpayne@69: /** jpayne@69: * Gets abbreviated era strings. For example: "AD" and "BC". jpayne@69: * jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @return the era strings. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: const UnicodeString* getEras(int32_t& count) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets abbreviated era strings. For example: "AD" and "BC". jpayne@69: * @param eras Array of era strings (DateFormatSymbols retains ownership.) jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setEras(const UnicodeString* eras, int32_t count); jpayne@69: jpayne@69: /** jpayne@69: * Gets era name strings. For example: "Anno Domini" and "Before Christ". jpayne@69: * jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @return the era name strings. jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: const UnicodeString* getEraNames(int32_t& count) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets era name strings. For example: "Anno Domini" and "Before Christ". jpayne@69: * @param eraNames Array of era name strings (DateFormatSymbols retains ownership.) jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @stable ICU 3.6 jpayne@69: */ jpayne@69: void setEraNames(const UnicodeString* eraNames, int32_t count); jpayne@69: jpayne@69: /** jpayne@69: * Gets narrow era strings. For example: "A" and "B". jpayne@69: * jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @return the narrow era strings. jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: const UnicodeString* getNarrowEras(int32_t& count) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets narrow era strings. For example: "A" and "B". jpayne@69: * @param narrowEras Array of narrow era strings (DateFormatSymbols retains ownership.) jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @stable ICU 4.2 jpayne@69: */ jpayne@69: void setNarrowEras(const UnicodeString* narrowEras, int32_t count); jpayne@69: jpayne@69: /** jpayne@69: * Gets month strings. For example: "January", "February", etc. jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @return the month strings. (DateFormatSymbols retains ownership.) jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: const UnicodeString* getMonths(int32_t& count) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets month strings. For example: "January", "February", etc. jpayne@69: * jpayne@69: * @param months the new month strings. (not adopted; caller retains ownership) jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setMonths(const UnicodeString* months, int32_t count); jpayne@69: jpayne@69: /** jpayne@69: * Gets short month strings. For example: "Jan", "Feb", etc. jpayne@69: * jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @return the short month strings. (DateFormatSymbols retains ownership.) jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: const UnicodeString* getShortMonths(int32_t& count) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets short month strings. For example: "Jan", "Feb", etc. jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @param shortMonths the new short month strings. (not adopted; caller retains ownership) jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setShortMonths(const UnicodeString* shortMonths, int32_t count); jpayne@69: jpayne@69: /** jpayne@69: * Selector for date formatting context jpayne@69: * @stable ICU 3.6 jpayne@69: */ jpayne@69: enum DtContextType { jpayne@69: FORMAT, jpayne@69: STANDALONE, jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * One more than the highest normal DtContextType value. jpayne@69: * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. jpayne@69: */ jpayne@69: DT_CONTEXT_COUNT jpayne@69: #endif // U_HIDE_DEPRECATED_API jpayne@69: }; jpayne@69: jpayne@69: /** jpayne@69: * Selector for date formatting width jpayne@69: * @stable ICU 3.6 jpayne@69: */ jpayne@69: enum DtWidthType { jpayne@69: ABBREVIATED, jpayne@69: WIDE, jpayne@69: NARROW, jpayne@69: /** jpayne@69: * Short width is currently only supported for weekday names. jpayne@69: * @stable ICU 51 jpayne@69: */ jpayne@69: SHORT, jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * One more than the highest normal DtWidthType value. jpayne@69: * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. jpayne@69: */ jpayne@69: DT_WIDTH_COUNT = 4 jpayne@69: #endif // U_HIDE_DEPRECATED_API jpayne@69: }; jpayne@69: jpayne@69: /** jpayne@69: * Gets month strings by width and context. For example: "January", "February", etc. jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @param context The formatting context, either FORMAT or STANDALONE jpayne@69: * @param width The width of returned strings, either WIDE, ABBREVIATED, or NARROW. jpayne@69: * @return the month strings. (DateFormatSymbols retains ownership.) jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: const UnicodeString* getMonths(int32_t& count, DtContextType context, DtWidthType width) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets month strings by width and context. For example: "January", "February", etc. jpayne@69: * jpayne@69: * @param months The new month strings. (not adopted; caller retains ownership) jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @param context The formatting context, either FORMAT or STANDALONE jpayne@69: * @param width The width of returned strings, either WIDE, ABBREVIATED, or NARROW. jpayne@69: * @stable ICU 3.6 jpayne@69: */ jpayne@69: void setMonths(const UnicodeString* months, int32_t count, DtContextType context, DtWidthType width); jpayne@69: jpayne@69: /** jpayne@69: * Gets wide weekday strings. For example: "Sunday", "Monday", etc. jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @return the weekday strings. (DateFormatSymbols retains ownership.) jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: const UnicodeString* getWeekdays(int32_t& count) const; jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Sets wide weekday strings. For example: "Sunday", "Monday", etc. jpayne@69: * @param weekdays the new weekday strings. (not adopted; caller retains ownership) jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setWeekdays(const UnicodeString* weekdays, int32_t count); jpayne@69: jpayne@69: /** jpayne@69: * Gets abbreviated weekday strings. For example: "Sun", "Mon", etc. (Note: The method name is jpayne@69: * misleading; it does not get the CLDR-style "short" weekday strings, e.g. "Su", "Mo", etc.) jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @return the abbreviated weekday strings. (DateFormatSymbols retains ownership.) jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: const UnicodeString* getShortWeekdays(int32_t& count) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets abbreviated weekday strings. For example: "Sun", "Mon", etc. (Note: The method name is jpayne@69: * misleading; it does not set the CLDR-style "short" weekday strings, e.g. "Su", "Mo", etc.) jpayne@69: * @param abbrevWeekdays the new abbreviated weekday strings. (not adopted; caller retains ownership) jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setShortWeekdays(const UnicodeString* abbrevWeekdays, int32_t count); jpayne@69: jpayne@69: /** jpayne@69: * Gets weekday strings by width and context. For example: "Sunday", "Monday", etc. jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @param context The formatting context, either FORMAT or STANDALONE jpayne@69: * @param width The width of returned strings, either WIDE, ABBREVIATED, SHORT, or NARROW jpayne@69: * @return the month strings. (DateFormatSymbols retains ownership.) jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: const UnicodeString* getWeekdays(int32_t& count, DtContextType context, DtWidthType width) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets weekday strings by width and context. For example: "Sunday", "Monday", etc. jpayne@69: * @param weekdays The new weekday strings. (not adopted; caller retains ownership) jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @param context The formatting context, either FORMAT or STANDALONE jpayne@69: * @param width The width of returned strings, either WIDE, ABBREVIATED, SHORT, or NARROW jpayne@69: * @stable ICU 3.6 jpayne@69: */ jpayne@69: void setWeekdays(const UnicodeString* weekdays, int32_t count, DtContextType context, DtWidthType width); jpayne@69: jpayne@69: /** jpayne@69: * Gets quarter strings by width and context. For example: "1st Quarter", "2nd Quarter", etc. jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @param context The formatting context, either FORMAT or STANDALONE jpayne@69: * @param width The width of returned strings, either WIDE or ABBREVIATED. There jpayne@69: * are no NARROW quarters. jpayne@69: * @return the quarter strings. (DateFormatSymbols retains ownership.) jpayne@69: * @stable ICU 3.6 jpayne@69: */ jpayne@69: const UnicodeString* getQuarters(int32_t& count, DtContextType context, DtWidthType width) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets quarter strings by width and context. For example: "1st Quarter", "2nd Quarter", etc. jpayne@69: * jpayne@69: * @param quarters The new quarter strings. (not adopted; caller retains ownership) jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @param context The formatting context, either FORMAT or STANDALONE jpayne@69: * @param width The width of returned strings, either WIDE or ABBREVIATED. There jpayne@69: * are no NARROW quarters. jpayne@69: * @stable ICU 3.6 jpayne@69: */ jpayne@69: void setQuarters(const UnicodeString* quarters, int32_t count, DtContextType context, DtWidthType width); jpayne@69: jpayne@69: /** jpayne@69: * Gets AM/PM strings. For example: "AM" and "PM". jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @return the weekday strings. (DateFormatSymbols retains ownership.) jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: const UnicodeString* getAmPmStrings(int32_t& count) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets ampm strings. For example: "AM" and "PM". jpayne@69: * @param ampms the new ampm strings. (not adopted; caller retains ownership) jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setAmPmStrings(const UnicodeString* ampms, int32_t count); jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * This default time separator is used for formatting when the locale jpayne@69: * doesn't specify any time separator, and always recognized when parsing. jpayne@69: * @internal jpayne@69: */ jpayne@69: static const char16_t DEFAULT_TIME_SEPARATOR = 0x003a; // ':' jpayne@69: jpayne@69: /** jpayne@69: * This alternate time separator is always recognized when parsing. jpayne@69: * @internal jpayne@69: */ jpayne@69: static const char16_t ALTERNATE_TIME_SEPARATOR = 0x002e; // '.' jpayne@69: jpayne@69: /** jpayne@69: * Gets the time separator string. For example: ":". jpayne@69: * @param result Output param which will receive the time separator string. jpayne@69: * @return A reference to 'result'. jpayne@69: * @internal jpayne@69: */ jpayne@69: UnicodeString& getTimeSeparatorString(UnicodeString& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets the time separator string. For example: ":". jpayne@69: * @param newTimeSeparator the new time separator string. jpayne@69: * @internal jpayne@69: */ jpayne@69: void setTimeSeparatorString(const UnicodeString& newTimeSeparator); jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: /** jpayne@69: * Gets cyclic year name strings if the calendar has them, by width and context. jpayne@69: * For example: "jia-zi", "yi-chou", etc. jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @param context The usage context: FORMAT, STANDALONE. jpayne@69: * @param width The requested name width: WIDE, ABBREVIATED, NARROW. jpayne@69: * @return The year name strings (DateFormatSymbols retains ownership), jpayne@69: * or null if they are not available for this calendar. jpayne@69: * @stable ICU 54 jpayne@69: */ jpayne@69: const UnicodeString* getYearNames(int32_t& count, jpayne@69: DtContextType context, DtWidthType width) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets cyclic year name strings by width and context. For example: "jia-zi", "yi-chou", etc. jpayne@69: * jpayne@69: * @param yearNames The new cyclic year name strings (not adopted; caller retains ownership). jpayne@69: * @param count The length of the array. jpayne@69: * @param context The usage context: FORMAT, STANDALONE (currently only FORMAT is supported). jpayne@69: * @param width The name width: WIDE, ABBREVIATED, NARROW (currently only ABBREVIATED is supported). jpayne@69: * @stable ICU 54 jpayne@69: */ jpayne@69: void setYearNames(const UnicodeString* yearNames, int32_t count, jpayne@69: DtContextType context, DtWidthType width); jpayne@69: jpayne@69: /** jpayne@69: * Gets calendar zodiac name strings if the calendar has them, by width and context. jpayne@69: * For example: "Rat", "Ox", "Tiger", etc. jpayne@69: * @param count Filled in with length of the array. jpayne@69: * @param context The usage context: FORMAT, STANDALONE. jpayne@69: * @param width The requested name width: WIDE, ABBREVIATED, NARROW. jpayne@69: * @return The zodiac name strings (DateFormatSymbols retains ownership), jpayne@69: * or null if they are not available for this calendar. jpayne@69: * @stable ICU 54 jpayne@69: */ jpayne@69: const UnicodeString* getZodiacNames(int32_t& count, jpayne@69: DtContextType context, DtWidthType width) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets calendar zodiac name strings by width and context. For example: "Rat", "Ox", "Tiger", etc. jpayne@69: * jpayne@69: * @param zodiacNames The new zodiac name strings (not adopted; caller retains ownership). jpayne@69: * @param count The length of the array. jpayne@69: * @param context The usage context: FORMAT, STANDALONE (currently only FORMAT is supported). jpayne@69: * @param width The name width: WIDE, ABBREVIATED, NARROW (currently only ABBREVIATED is supported). jpayne@69: * @stable ICU 54 jpayne@69: */ jpayne@69: void setZodiacNames(const UnicodeString* zodiacNames, int32_t count, jpayne@69: DtContextType context, DtWidthType width); jpayne@69: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * Somewhat temporary constants for leap month pattern types, adequate for supporting jpayne@69: * just leap month patterns as needed for Chinese lunar calendar. jpayne@69: * Eventually we will add full support for different month pattern types (needed for jpayne@69: * other calendars such as Hindu) at which point this approach will be replaced by a jpayne@69: * more complete approach. jpayne@69: * @internal jpayne@69: */ jpayne@69: enum EMonthPatternType jpayne@69: { jpayne@69: kLeapMonthPatternFormatWide, jpayne@69: kLeapMonthPatternFormatAbbrev, jpayne@69: kLeapMonthPatternFormatNarrow, jpayne@69: kLeapMonthPatternStandaloneWide, jpayne@69: kLeapMonthPatternStandaloneAbbrev, jpayne@69: kLeapMonthPatternStandaloneNarrow, jpayne@69: kLeapMonthPatternNumeric, jpayne@69: kMonthPatternsCount jpayne@69: }; jpayne@69: jpayne@69: /** jpayne@69: * Somewhat temporary function for getting complete set of leap month patterns for all jpayne@69: * contexts & widths, indexed by EMonthPatternType values. Returns NULL if calendar jpayne@69: * does not have leap month patterns. Note, there is currently no setter for this. jpayne@69: * Eventually we will add full support for different month pattern types (needed for jpayne@69: * other calendars such as Hindu) at which point this approach will be replaced by a jpayne@69: * more complete approach. jpayne@69: * @param count Filled in with length of the array (may be 0). jpayne@69: * @return The leap month patterns (DateFormatSymbols retains ownership). jpayne@69: * May be NULL if there are no leap month patterns for this calendar. jpayne@69: * @internal jpayne@69: */ jpayne@69: const UnicodeString* getLeapMonthPatterns(int32_t& count) const; jpayne@69: jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * Gets timezone strings. These strings are stored in a 2-dimensional array. jpayne@69: * @param rowCount Output param to receive number of rows. jpayne@69: * @param columnCount Output param to receive number of columns. jpayne@69: * @return The timezone strings as a 2-d array. (DateFormatSymbols retains ownership.) jpayne@69: * @deprecated ICU 3.6 jpayne@69: */ jpayne@69: const UnicodeString** getZoneStrings(int32_t& rowCount, int32_t& columnCount) const; jpayne@69: #endif /* U_HIDE_DEPRECATED_API */ jpayne@69: jpayne@69: /** jpayne@69: * Sets timezone strings. These strings are stored in a 2-dimensional array. jpayne@69: *

Note: SimpleDateFormat no longer use the zone strings stored in jpayne@69: * a DateFormatSymbols. Therefore, the time zone strings set by this mthod jpayne@69: * have no effects in an instance of SimpleDateFormat for formatting time jpayne@69: * zones. jpayne@69: * @param strings The timezone strings as a 2-d array to be copied. (not adopted; caller retains ownership) jpayne@69: * @param rowCount The number of rows (count of first index). jpayne@69: * @param columnCount The number of columns (count of second index). jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setZoneStrings(const UnicodeString* const* strings, int32_t rowCount, int32_t columnCount); jpayne@69: jpayne@69: /** jpayne@69: * Get the non-localized date-time pattern characters. jpayne@69: * @return the non-localized date-time pattern characters jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: static const char16_t * U_EXPORT2 getPatternUChars(void); jpayne@69: jpayne@69: /** jpayne@69: * Gets localized date-time pattern characters. For example: 'u', 't', etc. jpayne@69: *

jpayne@69: * Note: ICU no longer provides localized date-time pattern characters for a locale jpayne@69: * starting ICU 3.8. This method returns the non-localized date-time pattern jpayne@69: * characters unless user defined localized data is set by setLocalPatternChars. jpayne@69: * @param result Output param which will receive the localized date-time pattern characters. jpayne@69: * @return A reference to 'result'. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UnicodeString& getLocalPatternChars(UnicodeString& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets localized date-time pattern characters. For example: 'u', 't', etc. jpayne@69: * @param newLocalPatternChars the new localized date-time jpayne@69: * pattern characters. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setLocalPatternChars(const UnicodeString& newLocalPatternChars); jpayne@69: jpayne@69: /** jpayne@69: * Returns the locale for this object. Two flavors are available: jpayne@69: * valid and actual locale. jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const; jpayne@69: jpayne@69: /* The following type and kCapContextUsageTypeCount cannot be #ifndef U_HIDE_INTERNAL_API, jpayne@69: they are needed for .h file declarations. */ jpayne@69: /** jpayne@69: * Constants for capitalization context usage types. jpayne@69: * @internal jpayne@69: */ jpayne@69: enum ECapitalizationContextUsageType jpayne@69: { jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: kCapContextUsageOther = 0, jpayne@69: kCapContextUsageMonthFormat, /* except narrow */ jpayne@69: kCapContextUsageMonthStandalone, /* except narrow */ jpayne@69: kCapContextUsageMonthNarrow, jpayne@69: kCapContextUsageDayFormat, /* except narrow */ jpayne@69: kCapContextUsageDayStandalone, /* except narrow */ jpayne@69: kCapContextUsageDayNarrow, jpayne@69: kCapContextUsageEraWide, jpayne@69: kCapContextUsageEraAbbrev, jpayne@69: kCapContextUsageEraNarrow, jpayne@69: kCapContextUsageZoneLong, jpayne@69: kCapContextUsageZoneShort, jpayne@69: kCapContextUsageMetazoneLong, jpayne@69: kCapContextUsageMetazoneShort, jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: kCapContextUsageTypeCount = 14 jpayne@69: }; jpayne@69: jpayne@69: /** jpayne@69: * ICU "poor man's RTTI", returns a UClassID for the actual class. jpayne@69: * jpayne@69: * @stable ICU 2.2 jpayne@69: */ jpayne@69: virtual UClassID getDynamicClassID() const; jpayne@69: jpayne@69: /** jpayne@69: * ICU "poor man's RTTI", returns a UClassID for this class. jpayne@69: * jpayne@69: * @stable ICU 2.2 jpayne@69: */ jpayne@69: static UClassID U_EXPORT2 getStaticClassID(); jpayne@69: jpayne@69: private: jpayne@69: jpayne@69: friend class SimpleDateFormat; jpayne@69: friend class DateFormatSymbolsSingleSetter; // see udat.cpp jpayne@69: jpayne@69: /** jpayne@69: * Abbreviated era strings. For example: "AD" and "BC". jpayne@69: */ jpayne@69: UnicodeString* fEras; jpayne@69: int32_t fErasCount; jpayne@69: jpayne@69: /** jpayne@69: * Era name strings. For example: "Anno Domini" and "Before Christ". jpayne@69: */ jpayne@69: UnicodeString* fEraNames; jpayne@69: int32_t fEraNamesCount; jpayne@69: jpayne@69: /** jpayne@69: * Narrow era strings. For example: "A" and "B". jpayne@69: */ jpayne@69: UnicodeString* fNarrowEras; jpayne@69: int32_t fNarrowErasCount; jpayne@69: jpayne@69: /** jpayne@69: * Month strings. For example: "January", "February", etc. jpayne@69: */ jpayne@69: UnicodeString* fMonths; jpayne@69: int32_t fMonthsCount; jpayne@69: jpayne@69: /** jpayne@69: * Short month strings. For example: "Jan", "Feb", etc. jpayne@69: */ jpayne@69: UnicodeString* fShortMonths; jpayne@69: int32_t fShortMonthsCount; jpayne@69: jpayne@69: /** jpayne@69: * Narrow month strings. For example: "J", "F", etc. jpayne@69: */ jpayne@69: UnicodeString* fNarrowMonths; jpayne@69: int32_t fNarrowMonthsCount; jpayne@69: jpayne@69: /** jpayne@69: * Standalone Month strings. For example: "January", "February", etc. jpayne@69: */ jpayne@69: UnicodeString* fStandaloneMonths; jpayne@69: int32_t fStandaloneMonthsCount; jpayne@69: jpayne@69: /** jpayne@69: * Standalone Short month strings. For example: "Jan", "Feb", etc. jpayne@69: */ jpayne@69: UnicodeString* fStandaloneShortMonths; jpayne@69: int32_t fStandaloneShortMonthsCount; jpayne@69: jpayne@69: /** jpayne@69: * Standalone Narrow month strings. For example: "J", "F", etc. jpayne@69: */ jpayne@69: UnicodeString* fStandaloneNarrowMonths; jpayne@69: int32_t fStandaloneNarrowMonthsCount; jpayne@69: jpayne@69: /** jpayne@69: * CLDR-style format wide weekday strings. For example: "Sunday", "Monday", etc. jpayne@69: */ jpayne@69: UnicodeString* fWeekdays; jpayne@69: int32_t fWeekdaysCount; jpayne@69: jpayne@69: /** jpayne@69: * CLDR-style format abbreviated (not short) weekday strings. For example: "Sun", "Mon", etc. jpayne@69: */ jpayne@69: UnicodeString* fShortWeekdays; jpayne@69: int32_t fShortWeekdaysCount; jpayne@69: jpayne@69: /** jpayne@69: * CLDR-style format short weekday strings. For example: "Su", "Mo", etc. jpayne@69: */ jpayne@69: UnicodeString* fShorterWeekdays; jpayne@69: int32_t fShorterWeekdaysCount; jpayne@69: jpayne@69: /** jpayne@69: * CLDR-style format narrow weekday strings. For example: "S", "M", etc. jpayne@69: */ jpayne@69: UnicodeString* fNarrowWeekdays; jpayne@69: int32_t fNarrowWeekdaysCount; jpayne@69: jpayne@69: /** jpayne@69: * CLDR-style standalone wide weekday strings. For example: "Sunday", "Monday", etc. jpayne@69: */ jpayne@69: UnicodeString* fStandaloneWeekdays; jpayne@69: int32_t fStandaloneWeekdaysCount; jpayne@69: jpayne@69: /** jpayne@69: * CLDR-style standalone abbreviated (not short) weekday strings. For example: "Sun", "Mon", etc. jpayne@69: */ jpayne@69: UnicodeString* fStandaloneShortWeekdays; jpayne@69: int32_t fStandaloneShortWeekdaysCount; jpayne@69: jpayne@69: /** jpayne@69: * CLDR-style standalone short weekday strings. For example: "Su", "Mo", etc. jpayne@69: */ jpayne@69: UnicodeString* fStandaloneShorterWeekdays; jpayne@69: int32_t fStandaloneShorterWeekdaysCount; jpayne@69: jpayne@69: /** jpayne@69: * Standalone Narrow weekday strings. For example: "Sun", "Mon", etc. jpayne@69: */ jpayne@69: UnicodeString* fStandaloneNarrowWeekdays; jpayne@69: int32_t fStandaloneNarrowWeekdaysCount; jpayne@69: jpayne@69: /** jpayne@69: * Ampm strings. For example: "AM" and "PM". jpayne@69: */ jpayne@69: UnicodeString* fAmPms; jpayne@69: int32_t fAmPmsCount; jpayne@69: jpayne@69: /** jpayne@69: * Narrow Ampm strings. For example: "a" and "p". jpayne@69: */ jpayne@69: UnicodeString* fNarrowAmPms; jpayne@69: int32_t fNarrowAmPmsCount; jpayne@69: jpayne@69: /** jpayne@69: * Time separator string. For example: ":". jpayne@69: */ jpayne@69: UnicodeString fTimeSeparator; jpayne@69: jpayne@69: /** jpayne@69: * Quarter strings. For example: "1st quarter", "2nd quarter", etc. jpayne@69: */ jpayne@69: UnicodeString *fQuarters; jpayne@69: int32_t fQuartersCount; jpayne@69: jpayne@69: /** jpayne@69: * Short quarters. For example: "Q1", "Q2", etc. jpayne@69: */ jpayne@69: UnicodeString *fShortQuarters; jpayne@69: int32_t fShortQuartersCount; jpayne@69: jpayne@69: /** jpayne@69: * Standalone quarter strings. For example: "1st quarter", "2nd quarter", etc. jpayne@69: */ jpayne@69: UnicodeString *fStandaloneQuarters; jpayne@69: int32_t fStandaloneQuartersCount; jpayne@69: jpayne@69: /** jpayne@69: * Standalone short quarter strings. For example: "Q1", "Q2", etc. jpayne@69: */ jpayne@69: UnicodeString *fStandaloneShortQuarters; jpayne@69: int32_t fStandaloneShortQuartersCount; jpayne@69: jpayne@69: /** jpayne@69: * All leap month patterns, for example "{0}bis". jpayne@69: */ jpayne@69: UnicodeString *fLeapMonthPatterns; jpayne@69: int32_t fLeapMonthPatternsCount; jpayne@69: jpayne@69: /** jpayne@69: * Cyclic year names, for example: "jia-zi", "yi-chou", ... "gui-hai"; jpayne@69: * currently we only have data for format/abbreviated. jpayne@69: * For the others, just get from format/abbreviated, ignore set. jpayne@69: */ jpayne@69: UnicodeString *fShortYearNames; jpayne@69: int32_t fShortYearNamesCount; jpayne@69: jpayne@69: /** jpayne@69: * Cyclic zodiac names, for example "Rat", "Ox", "Tiger", etc.; jpayne@69: * currently we only have data for format/abbreviated. jpayne@69: * For the others, just get from format/abbreviated, ignore set. jpayne@69: */ jpayne@69: UnicodeString *fShortZodiacNames; jpayne@69: int32_t fShortZodiacNamesCount; jpayne@69: jpayne@69: /** jpayne@69: * Localized names of time zones in this locale. This is a jpayne@69: * two-dimensional array of strings of size n by m, jpayne@69: * where m is at least 5 and up to 7. Each of the n rows is an jpayne@69: * entry containing the localized names for a single TimeZone. jpayne@69: * jpayne@69: * Each such row contains (with i ranging from 0..n-1): jpayne@69: * jpayne@69: * zoneStrings[i][0] - time zone ID jpayne@69: * example: America/Los_Angeles jpayne@69: * zoneStrings[i][1] - long name of zone in standard time jpayne@69: * example: Pacific Standard Time jpayne@69: * zoneStrings[i][2] - short name of zone in standard time jpayne@69: * example: PST jpayne@69: * zoneStrings[i][3] - long name of zone in daylight savings time jpayne@69: * example: Pacific Daylight Time jpayne@69: * zoneStrings[i][4] - short name of zone in daylight savings time jpayne@69: * example: PDT jpayne@69: * zoneStrings[i][5] - location name of zone jpayne@69: * example: United States (Los Angeles) jpayne@69: * zoneStrings[i][6] - long generic name of zone jpayne@69: * example: Pacific Time jpayne@69: * zoneStrings[i][7] - short generic of zone jpayne@69: * example: PT jpayne@69: * jpayne@69: * The zone ID is not localized; it corresponds to the ID jpayne@69: * value associated with a system time zone object. All other entries jpayne@69: * are localized names. If a zone does not implement daylight savings jpayne@69: * time, the daylight savings time names are ignored. jpayne@69: * jpayne@69: * Note:CLDR 1.5 introduced metazone and its historical mappings. jpayne@69: * This simple two-dimensional array is no longer sufficient to represent jpayne@69: * localized names and its historic changes. Since ICU 3.8.1, localized jpayne@69: * zone names extracted from ICU locale data is stored in a ZoneStringFormat jpayne@69: * instance. But we still need to support the old way of customizing jpayne@69: * localized zone names, so we keep this field for the purpose. jpayne@69: */ jpayne@69: UnicodeString **fZoneStrings; // Zone string array set by setZoneStrings jpayne@69: UnicodeString **fLocaleZoneStrings; // Zone string array created by the locale jpayne@69: int32_t fZoneStringsRowCount; jpayne@69: int32_t fZoneStringsColCount; jpayne@69: jpayne@69: Locale fZSFLocale; // Locale used for getting ZoneStringFormat jpayne@69: jpayne@69: /** jpayne@69: * Localized date-time pattern characters. For example: use 'u' as 'y'. jpayne@69: */ jpayne@69: UnicodeString fLocalPatternChars; jpayne@69: jpayne@69: /** jpayne@69: * Capitalization transforms. For each usage type, the first array element indicates jpayne@69: * whether to titlecase for uiListOrMenu context, the second indicates whether to jpayne@69: * titlecase for stand-alone context. jpayne@69: */ jpayne@69: UBool fCapitalization[kCapContextUsageTypeCount][2]; jpayne@69: jpayne@69: /** jpayne@69: * Abbreviated (== short) day period strings. jpayne@69: */ jpayne@69: UnicodeString *fAbbreviatedDayPeriods; jpayne@69: int32_t fAbbreviatedDayPeriodsCount; jpayne@69: jpayne@69: /** jpayne@69: * Wide day period strings. jpayne@69: */ jpayne@69: UnicodeString *fWideDayPeriods; jpayne@69: int32_t fWideDayPeriodsCount; jpayne@69: jpayne@69: /** jpayne@69: * Narrow day period strings. jpayne@69: */ jpayne@69: UnicodeString *fNarrowDayPeriods; jpayne@69: int32_t fNarrowDayPeriodsCount; jpayne@69: jpayne@69: /** jpayne@69: * Stand-alone abbreviated (== short) day period strings. jpayne@69: */ jpayne@69: UnicodeString *fStandaloneAbbreviatedDayPeriods; jpayne@69: int32_t fStandaloneAbbreviatedDayPeriodsCount; jpayne@69: jpayne@69: /** jpayne@69: * Stand-alone wide day period strings. jpayne@69: */ jpayne@69: UnicodeString *fStandaloneWideDayPeriods; jpayne@69: int32_t fStandaloneWideDayPeriodsCount; jpayne@69: jpayne@69: /** jpayne@69: * Stand-alone narrow day period strings. jpayne@69: */ jpayne@69: UnicodeString *fStandaloneNarrowDayPeriods; jpayne@69: int32_t fStandaloneNarrowDayPeriodsCount; jpayne@69: jpayne@69: private: jpayne@69: /** valid/actual locale information jpayne@69: * these are always ICU locales, so the length should not be a problem jpayne@69: */ jpayne@69: char validLocale[ULOC_FULLNAME_CAPACITY]; jpayne@69: char actualLocale[ULOC_FULLNAME_CAPACITY]; jpayne@69: jpayne@69: DateFormatSymbols(); // default constructor not implemented jpayne@69: jpayne@69: /** jpayne@69: * Called by the constructors to actually load data from the resources jpayne@69: * jpayne@69: * @param locale The locale to get symbols for. jpayne@69: * @param type Calendar Type (as from Calendar::getType()) jpayne@69: * @param status Input/output parameter, set to success or jpayne@69: * failure code upon return. jpayne@69: * @param useLastResortData determine if use last resort data jpayne@69: */ jpayne@69: void initializeData(const Locale& locale, const char *type, UErrorCode& status, UBool useLastResortData = FALSE); jpayne@69: jpayne@69: /** jpayne@69: * Copy or alias an array in another object, as appropriate. jpayne@69: * jpayne@69: * @param dstArray the copy destination array. jpayne@69: * @param dstCount fill in with the lenth of 'dstArray'. jpayne@69: * @param srcArray the source array to be copied. jpayne@69: * @param srcCount the length of items to be copied from the 'srcArray'. jpayne@69: */ jpayne@69: static void assignArray(UnicodeString*& dstArray, jpayne@69: int32_t& dstCount, jpayne@69: const UnicodeString* srcArray, jpayne@69: int32_t srcCount); jpayne@69: jpayne@69: /** jpayne@69: * Return true if the given arrays' contents are equal, or if the arrays are jpayne@69: * identical (pointers are equal). jpayne@69: * jpayne@69: * @param array1 one array to be compared with. jpayne@69: * @param array2 another array to be compared with. jpayne@69: * @param count the length of items to be copied. jpayne@69: * @return true if the given arrays' contents are equal, or if the arrays are jpayne@69: * identical (pointers are equal). jpayne@69: */ jpayne@69: static UBool arrayCompare(const UnicodeString* array1, jpayne@69: const UnicodeString* array2, jpayne@69: int32_t count); jpayne@69: jpayne@69: /** jpayne@69: * Create a copy, in fZoneStrings, of the given zone strings array. The jpayne@69: * member variables fZoneStringsRowCount and fZoneStringsColCount should be jpayne@69: * set already by the caller. jpayne@69: */ jpayne@69: void createZoneStrings(const UnicodeString *const * otherStrings); jpayne@69: jpayne@69: /** jpayne@69: * Delete all the storage owned by this object. jpayne@69: */ jpayne@69: void dispose(void); jpayne@69: jpayne@69: /** jpayne@69: * Copy all of the other's data to this. jpayne@69: * @param other the object to be copied. jpayne@69: */ jpayne@69: void copyData(const DateFormatSymbols& other); jpayne@69: jpayne@69: /** jpayne@69: * Create zone strings array by locale if not yet available jpayne@69: */ jpayne@69: void initZoneStringsArray(void); jpayne@69: jpayne@69: /** jpayne@69: * Delete just the zone strings. jpayne@69: */ jpayne@69: void disposeZoneStrings(void); jpayne@69: jpayne@69: /** jpayne@69: * Returns the date format field index of the pattern character c, jpayne@69: * or UDAT_FIELD_COUNT if c is not a pattern character. jpayne@69: */ jpayne@69: static UDateFormatField U_EXPORT2 getPatternCharIndex(char16_t c); jpayne@69: jpayne@69: /** jpayne@69: * Returns TRUE if f (with its pattern character repeated count times) is a numeric field. jpayne@69: */ jpayne@69: static UBool U_EXPORT2 isNumericField(UDateFormatField f, int32_t count); jpayne@69: jpayne@69: /** jpayne@69: * Returns TRUE if c (repeated count times) is the pattern character for a numeric field. jpayne@69: */ jpayne@69: static UBool U_EXPORT2 isNumericPatternChar(char16_t c, int32_t count); jpayne@69: public: jpayne@69: #ifndef U_HIDE_INTERNAL_API jpayne@69: /** jpayne@69: * Gets a DateFormatSymbols by locale. jpayne@69: * Unlike the constructors which always use gregorian calendar, this jpayne@69: * method uses the calendar in the locale. If the locale contains no jpayne@69: * explicit calendar, this method uses the default calendar for that jpayne@69: * locale. jpayne@69: * @param locale the locale. jpayne@69: * @param status error returned here. jpayne@69: * @return the new DateFormatSymbols which the caller owns. jpayne@69: * @internal For ICU use only. jpayne@69: */ jpayne@69: static DateFormatSymbols * U_EXPORT2 createForLocale( jpayne@69: const Locale &locale, UErrorCode &status); jpayne@69: #endif /* U_HIDE_INTERNAL_API */ jpayne@69: }; jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif /* #if !UCONFIG_NO_FORMATTING */ jpayne@69: jpayne@69: #endif /* U_SHOW_CPLUSPLUS_API */ jpayne@69: jpayne@69: #endif // _DTFMTSYM jpayne@69: //eof