ICU 78.1  78.1
dtfmtsym.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 ********************************************************************************
5 * Copyright (C) 1997-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 ********************************************************************************
8 *
9 * File DTFMTSYM.H
10 *
11 * Modification History:
12 *
13 * Date Name Description
14 * 02/19/97 aliu Converted from java.
15 * 07/21/98 stephen Added getZoneIndex()
16 * Changed to match C++ conventions
17 ********************************************************************************
18 */
19 
20 #ifndef DTFMTSYM_H
21 #define DTFMTSYM_H
22 
23 #include "unicode/utypes.h"
24 
25 #if U_SHOW_CPLUSPLUS_API
26 
27 #if !UCONFIG_NO_FORMATTING
28 
29 #include "unicode/calendar.h"
30 #include "unicode/strenum.h"
31 #include "unicode/uobject.h"
32 #include "unicode/locid.h"
33 #include "unicode/udat.h"
34 #include "unicode/ures.h"
35 
41 U_NAMESPACE_BEGIN
42 
43 /* forward declaration */
44 class SimpleDateFormat;
45 class Hashtable;
46 
85 public:
100 
112 
113 #ifndef U_HIDE_INTERNAL_API
130  U_I18N_API DateFormatSymbols(const char* type, UErrorCode& status);
131 
145  U_I18N_API DateFormatSymbols(const Locale& locale, const char* type, UErrorCode& status);
146 #endif /* U_HIDE_INTERNAL_API */
147 
153 
159 
166 
174  U_I18N_API bool operator==(const DateFormatSymbols& other) const;
175 
183  U_I18N_API bool operator!=(const DateFormatSymbols& other) const { return !operator==(other); }
184 
192  U_I18N_API const UnicodeString* getEras(int32_t& count) const;
193 
200  U_I18N_API void setEras(const UnicodeString* eras, int32_t count);
201 
209  U_I18N_API const UnicodeString* getEraNames(int32_t& count) const;
210 
217  U_I18N_API void setEraNames(const UnicodeString* eraNames, int32_t count);
218 
226  U_I18N_API const UnicodeString* getNarrowEras(int32_t& count) const;
227 
234  U_I18N_API void setNarrowEras(const UnicodeString* narrowEras, int32_t count);
235 
242  U_I18N_API const UnicodeString* getMonths(int32_t& count) const;
243 
251  U_I18N_API void setMonths(const UnicodeString* months, int32_t count);
252 
260  U_I18N_API const UnicodeString* getShortMonths(int32_t& count) const;
261 
268  U_I18N_API void setShortMonths(const UnicodeString* shortMonths, int32_t count);
269 
275  FORMAT,
276  STANDALONE,
277 #ifndef U_HIDE_DEPRECATED_API
282  DT_CONTEXT_COUNT
283 #endif // U_HIDE_DEPRECATED_API
284  };
285 
290  enum DtWidthType {
291  ABBREVIATED,
292  WIDE,
293  NARROW,
299 #ifndef U_HIDE_DEPRECATED_API
304  DT_WIDTH_COUNT = 4
305 #endif // U_HIDE_DEPRECATED_API
306  };
307 
316  U_I18N_API const UnicodeString* getMonths(int32_t& count,
317  DtContextType context,
318  DtWidthType width) const;
319 
329  U_I18N_API void setMonths(const UnicodeString* months,
330  int32_t count,
331  DtContextType context,
332  DtWidthType width);
333 
340  U_I18N_API const UnicodeString* getWeekdays(int32_t& count) const;
341 
348  U_I18N_API void setWeekdays(const UnicodeString* weekdays, int32_t count);
349 
357  U_I18N_API const UnicodeString* getShortWeekdays(int32_t& count) const;
358 
366  U_I18N_API void setShortWeekdays(const UnicodeString* abbrevWeekdays, int32_t count);
367 
376  U_I18N_API const UnicodeString* getWeekdays(int32_t& count,
377  DtContextType context,
378  DtWidthType width) const;
379 
388  U_I18N_API void setWeekdays(const UnicodeString* weekdays,
389  int32_t count,
390  DtContextType context,
391  DtWidthType width);
392 
401  U_I18N_API const UnicodeString* getQuarters(int32_t& count,
402  DtContextType context,
403  DtWidthType width) const;
404 
414  U_I18N_API void setQuarters(const UnicodeString* quarters,
415  int32_t count,
416  DtContextType context,
417  DtWidthType width);
418 
425  U_I18N_API const UnicodeString* getAmPmStrings(int32_t& count) const;
426 
433  U_I18N_API void setAmPmStrings(const UnicodeString* ampms, int32_t count);
434 
435 #ifndef U_HIDE_DRAFT_API
444  U_I18N_API const UnicodeString* getAmPmStrings(int32_t& count,
445  DtContextType context,
446  DtWidthType width) const;
447 
457  int32_t count,
458  DtContextType context,
459  DtWidthType width);
460 #endif /* U_HIDE_DRAFT_API */
461 
462 #ifndef U_HIDE_INTERNAL_API
468  U_I18N_API static const char16_t DEFAULT_TIME_SEPARATOR = 0x003a; // ':'
469 
474  U_I18N_API static const char16_t ALTERNATE_TIME_SEPARATOR = 0x002e; // '.'
475 
483 
489  U_I18N_API void setTimeSeparatorString(const UnicodeString& newTimeSeparator);
490 #endif /* U_HIDE_INTERNAL_API */
491 
502  U_I18N_API const UnicodeString* getYearNames(int32_t& count,
503  DtContextType context,
504  DtWidthType width) const;
505 
515  U_I18N_API void setYearNames(const UnicodeString* yearNames,
516  int32_t count,
517  DtContextType context,
518  DtWidthType width);
519 
530  U_I18N_API const UnicodeString* getZodiacNames(int32_t& count,
531  DtContextType context,
532  DtWidthType width) const;
533 
543  U_I18N_API void setZodiacNames(const UnicodeString* zodiacNames,
544  int32_t count,
545  DtContextType context,
546  DtWidthType width);
547 
548 #ifndef U_HIDE_INTERNAL_API
558  {
559  kLeapMonthPatternFormatWide,
560  kLeapMonthPatternFormatAbbrev,
561  kLeapMonthPatternFormatNarrow,
562  kLeapMonthPatternStandaloneWide,
563  kLeapMonthPatternStandaloneAbbrev,
564  kLeapMonthPatternStandaloneNarrow,
565  kLeapMonthPatternNumeric,
566  kMonthPatternsCount
567  };
568 
581  U_I18N_API const UnicodeString* getLeapMonthPatterns(int32_t& count) const;
582 
583 #endif /* U_HIDE_INTERNAL_API */
584 
585 #ifndef U_HIDE_DEPRECATED_API
593  U_I18N_API const UnicodeString** getZoneStrings(int32_t& rowCount, int32_t& columnCount) const;
594 #endif /* U_HIDE_DEPRECATED_API */
595 
607  U_I18N_API void setZoneStrings(const UnicodeString* const* strings,
608  int32_t rowCount,
609  int32_t columnCount);
610 
616  U_I18N_API static const char16_t* getPatternUChars();
617 
629 
636  U_I18N_API void setLocalPatternChars(const UnicodeString& newLocalPatternChars);
637 
644 
645  /* The following type and kCapContextUsageTypeCount cannot be #ifndef U_HIDE_INTERNAL_API,
646  they are needed for .h file declarations. */
652  {
653 #ifndef U_HIDE_INTERNAL_API
654  kCapContextUsageOther = 0,
655  kCapContextUsageMonthFormat, /* except narrow */
656  kCapContextUsageMonthStandalone, /* except narrow */
657  kCapContextUsageMonthNarrow,
658  kCapContextUsageDayFormat, /* except narrow */
659  kCapContextUsageDayStandalone, /* except narrow */
660  kCapContextUsageDayNarrow,
661  kCapContextUsageEraWide,
662  kCapContextUsageEraAbbrev,
663  kCapContextUsageEraNarrow,
664  kCapContextUsageZoneLong,
665  kCapContextUsageZoneShort,
666  kCapContextUsageMetazoneLong,
667  kCapContextUsageMetazoneShort,
668 #endif /* U_HIDE_INTERNAL_API */
669  kCapContextUsageTypeCount = 14
670  };
671 
677  U_I18N_API virtual UClassID getDynamicClassID() const override;
678 
685 
686 private:
687 
688  friend class SimpleDateFormat;
689  friend class DateFormatSymbolsSingleSetter; // see udat.cpp
690 
694  UnicodeString* fEras;
695  int32_t fErasCount;
696 
700  UnicodeString* fEraNames;
701  int32_t fEraNamesCount;
702 
706  UnicodeString* fNarrowEras;
707  int32_t fNarrowErasCount;
708 
712  UnicodeString* fMonths;
713  int32_t fMonthsCount;
714 
718  UnicodeString* fShortMonths;
719  int32_t fShortMonthsCount;
720 
724  UnicodeString* fNarrowMonths;
725  int32_t fNarrowMonthsCount;
726 
730  UnicodeString* fStandaloneMonths;
731  int32_t fStandaloneMonthsCount;
732 
736  UnicodeString* fStandaloneShortMonths;
737  int32_t fStandaloneShortMonthsCount;
738 
742  UnicodeString* fStandaloneNarrowMonths;
743  int32_t fStandaloneNarrowMonthsCount;
744 
748  UnicodeString* fWeekdays;
749  int32_t fWeekdaysCount;
750 
754  UnicodeString* fShortWeekdays;
755  int32_t fShortWeekdaysCount;
756 
760  UnicodeString* fShorterWeekdays;
761  int32_t fShorterWeekdaysCount;
762 
766  UnicodeString* fNarrowWeekdays;
767  int32_t fNarrowWeekdaysCount;
768 
772  UnicodeString* fStandaloneWeekdays;
773  int32_t fStandaloneWeekdaysCount;
774 
778  UnicodeString* fStandaloneShortWeekdays;
779  int32_t fStandaloneShortWeekdaysCount;
780 
784  UnicodeString* fStandaloneShorterWeekdays;
785  int32_t fStandaloneShorterWeekdaysCount;
786 
790  UnicodeString* fStandaloneNarrowWeekdays;
791  int32_t fStandaloneNarrowWeekdaysCount;
792 
796  UnicodeString* fAmPms;
797  int32_t fAmPmsCount;
798 
803  UnicodeString* fWideAmPms;
804  int32_t fWideAmPmsCount;
805 
809  UnicodeString* fNarrowAmPms;
810  int32_t fNarrowAmPmsCount;
811 
815  UnicodeString fTimeSeparator;
816 
820  UnicodeString *fQuarters;
821  int32_t fQuartersCount;
822 
826  UnicodeString *fShortQuarters;
827  int32_t fShortQuartersCount;
828 
833  UnicodeString *fNarrowQuarters;
834  int32_t fNarrowQuartersCount;
835 
839  UnicodeString *fStandaloneQuarters;
840  int32_t fStandaloneQuartersCount;
841 
845  UnicodeString *fStandaloneShortQuarters;
846  int32_t fStandaloneShortQuartersCount;
847 
852  UnicodeString *fStandaloneNarrowQuarters;
853  int32_t fStandaloneNarrowQuartersCount;
854 
858  UnicodeString *fLeapMonthPatterns;
859  int32_t fLeapMonthPatternsCount;
860 
866  UnicodeString *fShortYearNames;
867  int32_t fShortYearNamesCount;
868 
874  UnicodeString *fShortZodiacNames;
875  int32_t fShortZodiacNamesCount;
876 
914  UnicodeString **fZoneStrings; // Zone string array set by setZoneStrings
915  UnicodeString **fLocaleZoneStrings; // Zone string array created by the locale
916  int32_t fZoneStringsRowCount;
917  int32_t fZoneStringsColCount;
918 
919  Locale fZSFLocale; // Locale used for getting ZoneStringFormat
920 
924  UnicodeString fLocalPatternChars;
925 
931  UBool fCapitalization[kCapContextUsageTypeCount][2];
932 
936  UnicodeString *fAbbreviatedDayPeriods;
937  int32_t fAbbreviatedDayPeriodsCount;
938 
942  UnicodeString *fWideDayPeriods;
943  int32_t fWideDayPeriodsCount;
944 
948  UnicodeString *fNarrowDayPeriods;
949  int32_t fNarrowDayPeriodsCount;
950 
954  UnicodeString *fStandaloneAbbreviatedDayPeriods;
955  int32_t fStandaloneAbbreviatedDayPeriodsCount;
956 
960  UnicodeString *fStandaloneWideDayPeriods;
961  int32_t fStandaloneWideDayPeriodsCount;
962 
966  UnicodeString *fStandaloneNarrowDayPeriods;
967  int32_t fStandaloneNarrowDayPeriodsCount;
968 
969 private:
973  Locale validLocale;
974  Locale actualLocale;
975 
976  DateFormatSymbols() = delete; // default constructor not implemented
977 
987  void initializeData(const Locale& locale, const char *type,
988  UErrorCode& status, UBool useLastResortData = false);
989 
998  static void assignArray(UnicodeString*& dstArray,
999  int32_t& dstCount,
1000  const UnicodeString* srcArray,
1001  int32_t srcCount);
1002 
1013  static UBool arrayCompare(const UnicodeString* array1,
1014  const UnicodeString* array2,
1015  int32_t count);
1016 
1022  void createZoneStrings(const UnicodeString *const * otherStrings);
1023 
1027  void dispose();
1028 
1033  void copyData(const DateFormatSymbols& other);
1034 
1038  void initZoneStringsArray();
1039 
1043  void disposeZoneStrings();
1044 
1049  static UDateFormatField U_EXPORT2 getPatternCharIndex(char16_t c);
1050 
1054  static UBool U_EXPORT2 isNumericField(UDateFormatField f, int32_t count);
1055 
1059  static UBool U_EXPORT2 isNumericPatternChar(char16_t c, int32_t count);
1060 public:
1061 #ifndef U_HIDE_INTERNAL_API
1074 #endif /* U_HIDE_INTERNAL_API */
1075 };
1076 
1077 U_NAMESPACE_END
1078 
1079 #endif /* #if !UCONFIG_NO_FORMATTING */
1080 
1081 #endif /* U_SHOW_CPLUSPLUS_API */
1082 
1083 #endif // _DTFMTSYM
1084 //eof
C++ API: Calendar object.
DateFormatSymbols is a public class for encapsulating localizable date-time formatting data – includi...
Definition: dtfmtsym.h:84
U_I18N_API const UnicodeString * getMonths(int32_t &count, DtContextType context, DtWidthType width) const
Gets month strings by width and context.
U_I18N_API void setMonths(const UnicodeString *months, int32_t count, DtContextType context, DtWidthType width)
Sets month strings by width and context.
U_I18N_API DateFormatSymbols(const Locale &locale, const char *type, UErrorCode &status)
Construct a DateFormatSymbols object by loading format data from resources for the given locale,...
U_I18N_API void setTimeSeparatorString(const UnicodeString &newTimeSeparator)
Sets the time separator string.
U_I18N_API const UnicodeString * getShortMonths(int32_t &count) const
Gets short month strings.
U_I18N_API DateFormatSymbols(const Locale &locale, UErrorCode &status)
Construct a DateFormatSymbols object by loading format data from resources for the given locale,...
U_I18N_API const UnicodeString * getLeapMonthPatterns(int32_t &count) const
Somewhat temporary function for getting complete set of leap month patterns for all contexts & widths...
U_I18N_API const UnicodeString ** getZoneStrings(int32_t &rowCount, int32_t &columnCount) const
Gets timezone strings.
U_I18N_API void setAmPmStrings(const UnicodeString *ampms, int32_t count, DtContextType context, DtWidthType width)
Sets AM/PM strings with the specified width.
U_I18N_API const UnicodeString * getNarrowEras(int32_t &count) const
Gets narrow era strings.
U_I18N_API bool operator==(const DateFormatSymbols &other) const
Return true if another object is semantically equal to this one.
virtual U_I18N_API ~DateFormatSymbols()
Destructor.
U_I18N_API void setZoneStrings(const UnicodeString *const *strings, int32_t rowCount, int32_t columnCount)
Sets timezone strings.
U_I18N_API DateFormatSymbols & operator=(const DateFormatSymbols &)
Assignment operator.
U_I18N_API const UnicodeString * getYearNames(int32_t &count, DtContextType context, DtWidthType width) const
Gets cyclic year name strings if the calendar has them, by width and context.
U_I18N_API const UnicodeString * getQuarters(int32_t &count, DtContextType context, DtWidthType width) const
Gets quarter strings by width and context.
DtWidthType
Selector for date formatting width.
Definition: dtfmtsym.h:290
@ SHORT
Short width is currently only supported for weekday names.
Definition: dtfmtsym.h:298
U_I18N_API const UnicodeString * getMonths(int32_t &count) const
Gets month strings.
U_I18N_API void setLocalPatternChars(const UnicodeString &newLocalPatternChars)
Sets localized date-time pattern characters.
U_I18N_API const UnicodeString * getShortWeekdays(int32_t &count) const
Gets abbreviated weekday strings.
static U_I18N_API const char16_t * getPatternUChars()
Get the non-localized date-time pattern characters.
U_I18N_API void setShortWeekdays(const UnicodeString *abbrevWeekdays, int32_t count)
Sets abbreviated weekday strings.
U_I18N_API void setWeekdays(const UnicodeString *weekdays, int32_t count, DtContextType context, DtWidthType width)
Sets weekday strings by width and context.
U_I18N_API const UnicodeString * getWeekdays(int32_t &count, DtContextType context, DtWidthType width) const
Gets weekday strings by width and context.
U_I18N_API void setMonths(const UnicodeString *months, int32_t count)
Sets month strings.
virtual U_I18N_API UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
static U_I18N_API UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
static U_I18N_API DateFormatSymbols * createForLocale(const Locale &locale, UErrorCode &status)
Gets a DateFormatSymbols by locale.
U_I18N_API UnicodeString & getTimeSeparatorString(UnicodeString &result) const
Gets the time separator string.
U_I18N_API const UnicodeString * getEraNames(int32_t &count) const
Gets era name strings.
U_I18N_API void setEras(const UnicodeString *eras, int32_t count)
Sets abbreviated era strings.
U_I18N_API void setShortMonths(const UnicodeString *shortMonths, int32_t count)
Sets short month strings.
U_I18N_API void setYearNames(const UnicodeString *yearNames, int32_t count, DtContextType context, DtWidthType width)
Sets cyclic year name strings by width and context.
U_I18N_API void setEraNames(const UnicodeString *eraNames, int32_t count)
Sets era name strings.
U_I18N_API const UnicodeString * getWeekdays(int32_t &count) const
Gets wide weekday strings.
U_I18N_API Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const
Returns the locale for this object.
U_I18N_API DateFormatSymbols(const DateFormatSymbols &)
Copy constructor.
U_I18N_API const UnicodeString * getAmPmStrings(int32_t &count, DtContextType context, DtWidthType width) const
Gets AM/PM strings with the specified width.
U_I18N_API DateFormatSymbols(UErrorCode &status)
Construct a DateFormatSymbols object by loading format data from resources for the default locale,...
U_I18N_API const UnicodeString * getAmPmStrings(int32_t &count) const
Gets AM/PM strings.
U_I18N_API const UnicodeString * getEras(int32_t &count) const
Gets abbreviated era strings.
U_I18N_API void setAmPmStrings(const UnicodeString *ampms, int32_t count)
Sets ampm strings.
U_I18N_API const UnicodeString * getZodiacNames(int32_t &count, DtContextType context, DtWidthType width) const
Gets calendar zodiac name strings if the calendar has them, by width and context.
U_I18N_API bool operator!=(const DateFormatSymbols &other) const
Return true if another object is semantically unequal to this one.
Definition: dtfmtsym.h:183
U_I18N_API void setQuarters(const UnicodeString *quarters, int32_t count, DtContextType context, DtWidthType width)
Sets quarter strings by width and context.
DtContextType
Selector for date formatting context.
Definition: dtfmtsym.h:274
U_I18N_API UnicodeString & getLocalPatternChars(UnicodeString &result) const
Gets localized date-time pattern characters.
U_I18N_API void setNarrowEras(const UnicodeString *narrowEras, int32_t count)
Sets narrow era strings.
ECapitalizationContextUsageType
Constants for capitalization context usage types.
Definition: dtfmtsym.h:652
U_I18N_API void setWeekdays(const UnicodeString *weekdays, int32_t count)
Sets wide weekday strings.
EMonthPatternType
Somewhat temporary constants for leap month pattern types, adequate for supporting just leap month pa...
Definition: dtfmtsym.h:558
U_I18N_API DateFormatSymbols(const char *type, UErrorCode &status)
Construct a DateFormatSymbols object by loading format data from resources for the default locale,...
U_I18N_API void setZodiacNames(const UnicodeString *zodiacNames, int32_t count, DtContextType context, DtWidthType width)
Sets calendar zodiac name strings by width and context.
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:198
SimpleDateFormat is a concrete class for formatting and parsing dates in a language-independent manne...
Definition: smpdtfmt.h:385
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:222
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:303
C++ API: Locale ID object.
U_COMMON_API UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
C++ API: String Enumeration.
C API: DateFormat.
UDateFormatField
FieldPosition and UFieldPosition selectors for format fields defined by DateFormat and UDateFormat.
Definition: udat.h:515
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested,...
Definition: uloc.h:338
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
C++ API: Common ICU base class UObject.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
C API: Resource Bundle.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:509
#define U_I18N_API_CLASS
Set to export library symbols from inside the i18n library, and to import them from outside,...
Definition: utypes.h:457
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:316