ICU 77.1 77.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
40
41U_NAMESPACE_BEGIN
42
43/* forward declaration */
44class SimpleDateFormat;
45class Hashtable;
46class CharString;
47
85class U_I18N_API DateFormatSymbols final : public UObject {
86public:
101
113 UErrorCode& status);
114
115#ifndef U_HIDE_INTERNAL_API
132 DateFormatSymbols(const char *type, UErrorCode& status);
133
148 const char *type,
149 UErrorCode& status);
150#endif /* U_HIDE_INTERNAL_API */
151
157
163
170
178 bool operator==(const DateFormatSymbols& other) const;
179
187 bool operator!=(const DateFormatSymbols& other) const { return !operator==(other); }
188
196 const UnicodeString* getEras(int32_t& count) const;
197
204 void setEras(const UnicodeString* eras, int32_t count);
205
213 const UnicodeString* getEraNames(int32_t& count) const;
214
221 void setEraNames(const UnicodeString* eraNames, int32_t count);
222
230 const UnicodeString* getNarrowEras(int32_t& count) const;
231
238 void setNarrowEras(const UnicodeString* narrowEras, int32_t count);
239
246 const UnicodeString* getMonths(int32_t& count) const;
247
255 void setMonths(const UnicodeString* months, int32_t count);
256
264 const UnicodeString* getShortMonths(int32_t& count) const;
265
272 void setShortMonths(const UnicodeString* shortMonths, int32_t count);
273
279 FORMAT,
280 STANDALONE,
281#ifndef U_HIDE_DEPRECATED_API
287#endif // U_HIDE_DEPRECATED_API
288 };
289
295 ABBREVIATED,
296 WIDE,
297 NARROW,
303#ifndef U_HIDE_DEPRECATED_API
309#endif // U_HIDE_DEPRECATED_API
310 };
311
320 const UnicodeString* getMonths(int32_t& count, DtContextType context, DtWidthType width) const;
321
331 void setMonths(const UnicodeString* months, int32_t count, DtContextType context, DtWidthType width);
332
339 const UnicodeString* getWeekdays(int32_t& count) const;
340
341
348 void setWeekdays(const UnicodeString* weekdays, int32_t count);
349
357 const UnicodeString* getShortWeekdays(int32_t& count) const;
358
366 void setShortWeekdays(const UnicodeString* abbrevWeekdays, int32_t count);
367
376 const UnicodeString* getWeekdays(int32_t& count, DtContextType context, DtWidthType width) const;
377
386 void setWeekdays(const UnicodeString* weekdays, int32_t count, DtContextType context, DtWidthType width);
387
396 const UnicodeString* getQuarters(int32_t& count, DtContextType context, DtWidthType width) const;
397
407 void setQuarters(const UnicodeString* quarters, int32_t count, DtContextType context, DtWidthType width);
408
415 const UnicodeString* getAmPmStrings(int32_t& count) const;
416
423 void setAmPmStrings(const UnicodeString* ampms, int32_t count);
424
425#ifndef U_HIDE_INTERNAL_API
431 static const char16_t DEFAULT_TIME_SEPARATOR = 0x003a; // ':'
432
437 static const char16_t ALTERNATE_TIME_SEPARATOR = 0x002e; // '.'
438
446
452 void setTimeSeparatorString(const UnicodeString& newTimeSeparator);
453#endif /* U_HIDE_INTERNAL_API */
454
465 const UnicodeString* getYearNames(int32_t& count,
466 DtContextType context, DtWidthType width) const;
467
477 void setYearNames(const UnicodeString* yearNames, int32_t count,
478 DtContextType context, DtWidthType width);
479
490 const UnicodeString* getZodiacNames(int32_t& count,
491 DtContextType context, DtWidthType width) const;
492
502 void setZodiacNames(const UnicodeString* zodiacNames, int32_t count,
503 DtContextType context, DtWidthType width);
504
505#ifndef U_HIDE_INTERNAL_API
515 {
516 kLeapMonthPatternFormatWide,
517 kLeapMonthPatternFormatAbbrev,
518 kLeapMonthPatternFormatNarrow,
519 kLeapMonthPatternStandaloneWide,
520 kLeapMonthPatternStandaloneAbbrev,
521 kLeapMonthPatternStandaloneNarrow,
522 kLeapMonthPatternNumeric,
523 kMonthPatternsCount
524 };
525
538 const UnicodeString* getLeapMonthPatterns(int32_t& count) const;
539
540#endif /* U_HIDE_INTERNAL_API */
541
542#ifndef U_HIDE_DEPRECATED_API
550 const UnicodeString** getZoneStrings(int32_t& rowCount, int32_t& columnCount) const;
551#endif /* U_HIDE_DEPRECATED_API */
552
564 void setZoneStrings(const UnicodeString* const* strings, int32_t rowCount, int32_t columnCount);
565
571 static const char16_t* U_EXPORT2 getPatternUChars();
572
584
591 void setLocalPatternChars(const UnicodeString& newLocalPatternChars);
592
599
600 /* The following type and kCapContextUsageTypeCount cannot be #ifndef U_HIDE_INTERNAL_API,
601 they are needed for .h file declarations. */
607 {
608#ifndef U_HIDE_INTERNAL_API
609 kCapContextUsageOther = 0,
610 kCapContextUsageMonthFormat, /* except narrow */
611 kCapContextUsageMonthStandalone, /* except narrow */
612 kCapContextUsageMonthNarrow,
613 kCapContextUsageDayFormat, /* except narrow */
614 kCapContextUsageDayStandalone, /* except narrow */
615 kCapContextUsageDayNarrow,
616 kCapContextUsageEraWide,
617 kCapContextUsageEraAbbrev,
618 kCapContextUsageEraNarrow,
619 kCapContextUsageZoneLong,
620 kCapContextUsageZoneShort,
621 kCapContextUsageMetazoneLong,
622 kCapContextUsageMetazoneShort,
623#endif /* U_HIDE_INTERNAL_API */
624 kCapContextUsageTypeCount = 14
625 };
626
632 virtual UClassID getDynamicClassID() const override;
633
639 static UClassID U_EXPORT2 getStaticClassID();
640
641private:
642
643 friend class SimpleDateFormat;
644 friend class DateFormatSymbolsSingleSetter; // see udat.cpp
645
649 UnicodeString* fEras;
650 int32_t fErasCount;
651
655 UnicodeString* fEraNames;
656 int32_t fEraNamesCount;
657
661 UnicodeString* fNarrowEras;
662 int32_t fNarrowErasCount;
663
667 UnicodeString* fMonths;
668 int32_t fMonthsCount;
669
673 UnicodeString* fShortMonths;
674 int32_t fShortMonthsCount;
675
679 UnicodeString* fNarrowMonths;
680 int32_t fNarrowMonthsCount;
681
685 UnicodeString* fStandaloneMonths;
686 int32_t fStandaloneMonthsCount;
687
691 UnicodeString* fStandaloneShortMonths;
692 int32_t fStandaloneShortMonthsCount;
693
697 UnicodeString* fStandaloneNarrowMonths;
698 int32_t fStandaloneNarrowMonthsCount;
699
703 UnicodeString* fWeekdays;
704 int32_t fWeekdaysCount;
705
709 UnicodeString* fShortWeekdays;
710 int32_t fShortWeekdaysCount;
711
715 UnicodeString* fShorterWeekdays;
716 int32_t fShorterWeekdaysCount;
717
721 UnicodeString* fNarrowWeekdays;
722 int32_t fNarrowWeekdaysCount;
723
727 UnicodeString* fStandaloneWeekdays;
728 int32_t fStandaloneWeekdaysCount;
729
733 UnicodeString* fStandaloneShortWeekdays;
734 int32_t fStandaloneShortWeekdaysCount;
735
739 UnicodeString* fStandaloneShorterWeekdays;
740 int32_t fStandaloneShorterWeekdaysCount;
741
745 UnicodeString* fStandaloneNarrowWeekdays;
746 int32_t fStandaloneNarrowWeekdaysCount;
747
751 UnicodeString* fAmPms;
752 int32_t fAmPmsCount;
753
757 UnicodeString* fNarrowAmPms;
758 int32_t fNarrowAmPmsCount;
759
763 UnicodeString fTimeSeparator;
764
768 UnicodeString *fQuarters;
769 int32_t fQuartersCount;
770
774 UnicodeString *fShortQuarters;
775 int32_t fShortQuartersCount;
776
781 UnicodeString *fNarrowQuarters;
782 int32_t fNarrowQuartersCount;
783
787 UnicodeString *fStandaloneQuarters;
788 int32_t fStandaloneQuartersCount;
789
793 UnicodeString *fStandaloneShortQuarters;
794 int32_t fStandaloneShortQuartersCount;
795
800 UnicodeString *fStandaloneNarrowQuarters;
801 int32_t fStandaloneNarrowQuartersCount;
802
806 UnicodeString *fLeapMonthPatterns;
807 int32_t fLeapMonthPatternsCount;
808
814 UnicodeString *fShortYearNames;
815 int32_t fShortYearNamesCount;
816
822 UnicodeString *fShortZodiacNames;
823 int32_t fShortZodiacNamesCount;
824
862 UnicodeString **fZoneStrings; // Zone string array set by setZoneStrings
863 UnicodeString **fLocaleZoneStrings; // Zone string array created by the locale
864 int32_t fZoneStringsRowCount;
865 int32_t fZoneStringsColCount;
866
867 Locale fZSFLocale; // Locale used for getting ZoneStringFormat
868
872 UnicodeString fLocalPatternChars;
873
879 UBool fCapitalization[kCapContextUsageTypeCount][2];
880
884 UnicodeString *fAbbreviatedDayPeriods;
885 int32_t fAbbreviatedDayPeriodsCount;
886
890 UnicodeString *fWideDayPeriods;
891 int32_t fWideDayPeriodsCount;
892
896 UnicodeString *fNarrowDayPeriods;
897 int32_t fNarrowDayPeriodsCount;
898
902 UnicodeString *fStandaloneAbbreviatedDayPeriods;
903 int32_t fStandaloneAbbreviatedDayPeriodsCount;
904
908 UnicodeString *fStandaloneWideDayPeriods;
909 int32_t fStandaloneWideDayPeriodsCount;
910
914 UnicodeString *fStandaloneNarrowDayPeriods;
915 int32_t fStandaloneNarrowDayPeriodsCount;
916
917private:
921 CharString* validLocale = nullptr;
922 CharString* actualLocale = nullptr;
923
924 DateFormatSymbols() = delete; // default constructor not implemented
925
935 void initializeData(const Locale& locale, const char *type,
936 UErrorCode& status, UBool useLastResortData = false);
937
946 static void assignArray(UnicodeString*& dstArray,
947 int32_t& dstCount,
948 const UnicodeString* srcArray,
949 int32_t srcCount);
950
961 static UBool arrayCompare(const UnicodeString* array1,
962 const UnicodeString* array2,
963 int32_t count);
964
970 void createZoneStrings(const UnicodeString *const * otherStrings);
971
975 void dispose();
976
981 void copyData(const DateFormatSymbols& other);
982
986 void initZoneStringsArray();
987
991 void disposeZoneStrings();
992
997 static UDateFormatField U_EXPORT2 getPatternCharIndex(char16_t c);
998
1002 static UBool U_EXPORT2 isNumericField(UDateFormatField f, int32_t count);
1003
1007 static UBool U_EXPORT2 isNumericPatternChar(char16_t c, int32_t count);
1008public:
1009#ifndef U_HIDE_INTERNAL_API
1022 const Locale &locale, UErrorCode &status);
1023#endif /* U_HIDE_INTERNAL_API */
1024};
1025
1026U_NAMESPACE_END
1027
1028#endif /* #if !UCONFIG_NO_FORMATTING */
1029
1030#endif /* U_SHOW_CPLUSPLUS_API */
1031
1032#endif // _DTFMTSYM
1033//eof
C++ API: Calendar object.
UnicodeString & getTimeSeparatorString(UnicodeString &result) const
Gets the time separator string.
void setYearNames(const UnicodeString *yearNames, int32_t count, DtContextType context, DtWidthType width)
Sets cyclic year name strings by width and context.
void setWeekdays(const UnicodeString *weekdays, int32_t count)
Sets wide weekday strings.
const UnicodeString * getAmPmStrings(int32_t &count) const
Gets AM/PM strings.
void setShortMonths(const UnicodeString *shortMonths, int32_t count)
Sets short month strings.
void setLocalPatternChars(const UnicodeString &newLocalPatternChars)
Sets localized date-time pattern characters.
const UnicodeString ** getZoneStrings(int32_t &rowCount, int32_t &columnCount) const
Gets timezone strings.
DateFormatSymbols(const char *type, UErrorCode &status)
Construct a DateFormatSymbols object by loading format data from resources for the default locale,...
const UnicodeString * getWeekdays(int32_t &count, DtContextType context, DtWidthType width) const
Gets weekday strings by width and context.
const UnicodeString * getShortMonths(int32_t &count) const
Gets short month strings.
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.
const UnicodeString * getShortWeekdays(int32_t &count) const
Gets abbreviated weekday strings.
Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const
Returns the locale for this object.
static const char16_t ALTERNATE_TIME_SEPARATOR
This alternate time separator is always recognized when parsing.
Definition dtfmtsym.h:437
static DateFormatSymbols * createForLocale(const Locale &locale, UErrorCode &status)
Gets a DateFormatSymbols by locale.
void setEras(const UnicodeString *eras, int32_t count)
Sets abbreviated era strings.
const UnicodeString * getEraNames(int32_t &count) const
Gets era name strings.
void setQuarters(const UnicodeString *quarters, int32_t count, DtContextType context, DtWidthType width)
Sets quarter strings by width and context.
bool operator!=(const DateFormatSymbols &other) const
Return true if another object is semantically unequal to this one.
Definition dtfmtsym.h:187
DateFormatSymbols(UErrorCode &status)
Construct a DateFormatSymbols object by loading format data from resources for the default locale,...
void setAmPmStrings(const UnicodeString *ampms, int32_t count)
Sets ampm strings.
DtWidthType
Selector for date formatting width.
Definition dtfmtsym.h:294
@ DT_WIDTH_COUNT
One more than the highest normal DtWidthType value.
Definition dtfmtsym.h:308
@ SHORT
Short width is currently only supported for weekday names.
Definition dtfmtsym.h:302
DateFormatSymbols & operator=(const DateFormatSymbols &)
Assignment operator.
const UnicodeString * getMonths(int32_t &count) const
Gets month strings.
void setShortWeekdays(const UnicodeString *abbrevWeekdays, int32_t count)
Sets abbreviated weekday strings.
const UnicodeString * getMonths(int32_t &count, DtContextType context, DtWidthType width) const
Gets month strings by width and context.
const UnicodeString * getQuarters(int32_t &count, DtContextType context, DtWidthType width) const
Gets quarter strings by width and context.
const UnicodeString * getNarrowEras(int32_t &count) const
Gets narrow era strings.
DateFormatSymbols(const Locale &locale, const char *type, UErrorCode &status)
Construct a DateFormatSymbols object by loading format data from resources for the given locale,...
void setZoneStrings(const UnicodeString *const *strings, int32_t rowCount, int32_t columnCount)
Sets timezone strings.
void setNarrowEras(const UnicodeString *narrowEras, int32_t count)
Sets narrow era strings.
bool operator==(const DateFormatSymbols &other) const
Return true if another object is semantically equal to this one.
const UnicodeString * getLeapMonthPatterns(int32_t &count) const
Somewhat temporary function for getting complete set of leap month patterns for all contexts & widths...
DateFormatSymbols(const DateFormatSymbols &)
Copy constructor.
virtual UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
void setEraNames(const UnicodeString *eraNames, int32_t count)
Sets era name strings.
void setMonths(const UnicodeString *months, int32_t count, DtContextType context, DtWidthType width)
Sets month strings by width and context.
void setTimeSeparatorString(const UnicodeString &newTimeSeparator)
Sets the time separator string.
void setZodiacNames(const UnicodeString *zodiacNames, int32_t count, DtContextType context, DtWidthType width)
Sets calendar zodiac name strings by width and context.
virtual ~DateFormatSymbols()
Destructor.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
static const char16_t DEFAULT_TIME_SEPARATOR
This default time separator is used for formatting when the locale doesn't specify any time separator...
Definition dtfmtsym.h:431
void setMonths(const UnicodeString *months, int32_t count)
Sets month strings.
void setWeekdays(const UnicodeString *weekdays, int32_t count, DtContextType context, DtWidthType width)
Sets weekday strings by width and context.
DtContextType
Selector for date formatting context.
Definition dtfmtsym.h:278
@ DT_CONTEXT_COUNT
One more than the highest normal DtContextType value.
Definition dtfmtsym.h:286
UnicodeString & getLocalPatternChars(UnicodeString &result) const
Gets localized date-time pattern characters.
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.
ECapitalizationContextUsageType
Constants for capitalization context usage types.
Definition dtfmtsym.h:607
static const char16_t * getPatternUChars()
Get the non-localized date-time pattern characters.
const UnicodeString * getEras(int32_t &count) const
Gets abbreviated era strings.
const UnicodeString * getWeekdays(int32_t &count) const
Gets wide weekday strings.
DateFormatSymbols(const Locale &locale, UErrorCode &status)
Construct a DateFormatSymbols object by loading format data from resources for the given locale,...
EMonthPatternType
Somewhat temporary constants for leap month pattern types, adequate for supporting just leap month pa...
Definition dtfmtsym.h:515
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:195
UObject is the common ICU "boilerplate" class.
Definition uobject.h:223
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:296
C++ API: Locale ID object.
U_EXPORT 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:247
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:430
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:316