ICU 63.1 63.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 !UCONFIG_NO_FORMATTING
26
27 #include "unicode/calendar.h"
28 #include "unicode/strenum.h"
29 #include "unicode/uobject.h"
30 #include "unicode/locid.h"
31 #include "unicode/udat.h"
32 #include "unicode/ures.h"
33
39 U_NAMESPACE_BEGIN
40
41 /* forward declaration */
42 class SimpleDateFormat;
43 class Hashtable;
44
82 class U_I18N_API DateFormatSymbols U_FINAL : public UObject {
83 public:
97 DateFormatSymbols(UErrorCode& status);
98
109 DateFormatSymbols(const Locale& locale,
110 UErrorCode& status);
111
112 #ifndef U_HIDE_INTERNAL_API
113
129 DateFormatSymbols(const char *type, UErrorCode& status);
130
144 DateFormatSymbols(const Locale& locale,
145 const char *type,
146 UErrorCode& status);
147 #endif /* U_HIDE_INTERNAL_API */
148
153 DateFormatSymbols(const DateFormatSymbols&);
154
159 DateFormatSymbols& operator=(const DateFormatSymbols&);
160
166 virtual ~DateFormatSymbols();
167
175 UBool operator==(const DateFormatSymbols& other) const;
176
184 UBool operator!=(const DateFormatSymbols& other) const { return !operator==(other); }
185
193 const UnicodeString* getEras(int32_t& count) const;
194
201 void setEras(const UnicodeString* eras, int32_t count);
202
210 const UnicodeString* getEraNames(int32_t& count) const;
211
218 void setEraNames(const UnicodeString* eraNames, int32_t count);
219
227 const UnicodeString* getNarrowEras(int32_t& count) const;
228
235 void setNarrowEras(const UnicodeString* narrowEras, int32_t count);
236
243 const UnicodeString* getMonths(int32_t& count) const;
244
252 void setMonths(const UnicodeString* months, int32_t count);
253
261 const UnicodeString* getShortMonths(int32_t& count) const;
262
269 void setShortMonths(const UnicodeString* shortMonths, int32_t count);
270
275 enum DtContextType {
276 FORMAT,
277 STANDALONE,
278 #ifndef U_HIDE_DEPRECATED_API
279
283 DT_CONTEXT_COUNT
284 #endif // U_HIDE_DEPRECATED_API
285 };
286
291 enum DtWidthType {
292 ABBREVIATED,
293 WIDE,
294 NARROW,
299 SHORT,
300 #ifndef U_HIDE_DEPRECATED_API
301
305 DT_WIDTH_COUNT = 4
306 #endif // U_HIDE_DEPRECATED_API
307 };
308
317 const UnicodeString* getMonths(int32_t& count, DtContextType context, DtWidthType width) const;
318
328 void setMonths(const UnicodeString* months, int32_t count, DtContextType context, DtWidthType width);
329
336 const UnicodeString* getWeekdays(int32_t& count) const;
337
338
345 void setWeekdays(const UnicodeString* weekdays, int32_t count);
346
354 const UnicodeString* getShortWeekdays(int32_t& count) const;
355
363 void setShortWeekdays(const UnicodeString* abbrevWeekdays, int32_t count);
364
373 const UnicodeString* getWeekdays(int32_t& count, DtContextType context, DtWidthType width) const;
374
383 void setWeekdays(const UnicodeString* weekdays, int32_t count, DtContextType context, DtWidthType width);
384
394 const UnicodeString* getQuarters(int32_t& count, DtContextType context, DtWidthType width) const;
395
406 void setQuarters(const UnicodeString* quarters, int32_t count, DtContextType context, DtWidthType width);
407
414 const UnicodeString* getAmPmStrings(int32_t& count) const;
415
422 void setAmPmStrings(const UnicodeString* ampms, int32_t count);
423
424 #ifndef U_HIDE_INTERNAL_API
425
430 static const char16_t DEFAULT_TIME_SEPARATOR = 0x003a; // ':'
431
436 static const char16_t ALTERNATE_TIME_SEPARATOR = 0x002e; // '.'
437
444 UnicodeString& getTimeSeparatorString(UnicodeString& result) const;
445
451 void setTimeSeparatorString(const UnicodeString& newTimeSeparator);
452 #endif /* U_HIDE_INTERNAL_API */
453
464 const UnicodeString* getYearNames(int32_t& count,
465 DtContextType context, DtWidthType width) const;
466
476 void setYearNames(const UnicodeString* yearNames, int32_t count,
477 DtContextType context, DtWidthType width);
478
489 const UnicodeString* getZodiacNames(int32_t& count,
490 DtContextType context, DtWidthType width) const;
491
501 void setZodiacNames(const UnicodeString* zodiacNames, int32_t count,
502 DtContextType context, DtWidthType width);
503
504 #ifndef U_HIDE_INTERNAL_API
505
513 enum EMonthPatternType
514 {
515 kLeapMonthPatternFormatWide,
516 kLeapMonthPatternFormatAbbrev,
517 kLeapMonthPatternFormatNarrow,
518 kLeapMonthPatternStandaloneWide,
519 kLeapMonthPatternStandaloneAbbrev,
520 kLeapMonthPatternStandaloneNarrow,
521 kLeapMonthPatternNumeric,
522 kMonthPatternsCount
523 };
524
537 const UnicodeString* getLeapMonthPatterns(int32_t& count) const;
538
539 #endif /* U_HIDE_INTERNAL_API */
540
541 #ifndef U_HIDE_DEPRECATED_API
542
549 const UnicodeString** getZoneStrings(int32_t& rowCount, int32_t& columnCount) const;
550 #endif /* U_HIDE_DEPRECATED_API */
551
563 void setZoneStrings(const UnicodeString* const* strings, int32_t rowCount, int32_t columnCount);
564
570 static const char16_t * U_EXPORT2 getPatternUChars(void);
571
582 UnicodeString& getLocalPatternChars(UnicodeString& result) const;
583
590 void setLocalPatternChars(const UnicodeString& newLocalPatternChars);
591
597 Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
598
599 /* The following type and kCapContextUsageTypeCount cannot be #ifndef U_HIDE_INTERNAL_API,
600 they are needed for .h file declarations. */
605 enum ECapitalizationContextUsageType
606 {
607 #ifndef U_HIDE_INTERNAL_API
608 kCapContextUsageOther = 0,
609 kCapContextUsageMonthFormat, /* except narrow */
610 kCapContextUsageMonthStandalone, /* except narrow */
611 kCapContextUsageMonthNarrow,
612 kCapContextUsageDayFormat, /* except narrow */
613 kCapContextUsageDayStandalone, /* except narrow */
614 kCapContextUsageDayNarrow,
615 kCapContextUsageEraWide,
616 kCapContextUsageEraAbbrev,
617 kCapContextUsageEraNarrow,
618 kCapContextUsageZoneLong,
619 kCapContextUsageZoneShort,
620 kCapContextUsageMetazoneLong,
621 kCapContextUsageMetazoneShort,
622 #endif /* U_HIDE_INTERNAL_API */
623 kCapContextUsageTypeCount = 14
624 };
625
631 virtual UClassID getDynamicClassID() const;
632
638 static UClassID U_EXPORT2 getStaticClassID();
639
640 private:
641
642 friend class SimpleDateFormat;
643 friend class DateFormatSymbolsSingleSetter; // see udat.cpp
644
648 UnicodeString* fEras;
649 int32_t fErasCount;
650
654 UnicodeString* fEraNames;
655 int32_t fEraNamesCount;
656
660 UnicodeString* fNarrowEras;
661 int32_t fNarrowErasCount;
662
666 UnicodeString* fMonths;
667 int32_t fMonthsCount;
668
672 UnicodeString* fShortMonths;
673 int32_t fShortMonthsCount;
674
678 UnicodeString* fNarrowMonths;
679 int32_t fNarrowMonthsCount;
680
684 UnicodeString* fStandaloneMonths;
685 int32_t fStandaloneMonthsCount;
686
690 UnicodeString* fStandaloneShortMonths;
691 int32_t fStandaloneShortMonthsCount;
692
696 UnicodeString* fStandaloneNarrowMonths;
697 int32_t fStandaloneNarrowMonthsCount;
698
702 UnicodeString* fWeekdays;
703 int32_t fWeekdaysCount;
704
708 UnicodeString* fShortWeekdays;
709 int32_t fShortWeekdaysCount;
710
714 UnicodeString* fShorterWeekdays;
715 int32_t fShorterWeekdaysCount;
716
720 UnicodeString* fNarrowWeekdays;
721 int32_t fNarrowWeekdaysCount;
722
726 UnicodeString* fStandaloneWeekdays;
727 int32_t fStandaloneWeekdaysCount;
728
732 UnicodeString* fStandaloneShortWeekdays;
733 int32_t fStandaloneShortWeekdaysCount;
734
738 UnicodeString* fStandaloneShorterWeekdays;
739 int32_t fStandaloneShorterWeekdaysCount;
740
744 UnicodeString* fStandaloneNarrowWeekdays;
745 int32_t fStandaloneNarrowWeekdaysCount;
746
750 UnicodeString* fAmPms;
751 int32_t fAmPmsCount;
752
756 UnicodeString* fNarrowAmPms;
757 int32_t fNarrowAmPmsCount;
758
762 UnicodeString fTimeSeparator;
763
767 UnicodeString *fQuarters;
768 int32_t fQuartersCount;
769
773 UnicodeString *fShortQuarters;
774 int32_t fShortQuartersCount;
775
779 UnicodeString *fStandaloneQuarters;
780 int32_t fStandaloneQuartersCount;
781
785 UnicodeString *fStandaloneShortQuarters;
786 int32_t fStandaloneShortQuartersCount;
787
791 UnicodeString *fLeapMonthPatterns;
792 int32_t fLeapMonthPatternsCount;
793
799 UnicodeString *fShortYearNames;
800 int32_t fShortYearNamesCount;
801
807 UnicodeString *fShortZodiacNames;
808 int32_t fShortZodiacNamesCount;
809
847 UnicodeString **fZoneStrings; // Zone string array set by setZoneStrings
848 UnicodeString **fLocaleZoneStrings; // Zone string array created by the locale
849 int32_t fZoneStringsRowCount;
850 int32_t fZoneStringsColCount;
851
852 Locale fZSFLocale; // Locale used for getting ZoneStringFormat
853
857 UnicodeString fLocalPatternChars;
858
864 UBool fCapitalization[kCapContextUsageTypeCount][2];
865
869 UnicodeString *fAbbreviatedDayPeriods;
870 int32_t fAbbreviatedDayPeriodsCount;
871
875 UnicodeString *fWideDayPeriods;
876 int32_t fWideDayPeriodsCount;
877
881 UnicodeString *fNarrowDayPeriods;
882 int32_t fNarrowDayPeriodsCount;
883
887 UnicodeString *fStandaloneAbbreviatedDayPeriods;
888 int32_t fStandaloneAbbreviatedDayPeriodsCount;
889
893 UnicodeString *fStandaloneWideDayPeriods;
894 int32_t fStandaloneWideDayPeriodsCount;
895
899 UnicodeString *fStandaloneNarrowDayPeriods;
900 int32_t fStandaloneNarrowDayPeriodsCount;
901
902 private:
906 char validLocale[ULOC_FULLNAME_CAPACITY];
907 char actualLocale[ULOC_FULLNAME_CAPACITY];
908
909 DateFormatSymbols(); // default constructor not implemented
910
920 void initializeData(const Locale& locale, const char *type, UErrorCode& status, UBool useLastResortData = FALSE);
921
930 static void assignArray(UnicodeString*& dstArray,
931 int32_t& dstCount,
932 const UnicodeString* srcArray,
933 int32_t srcCount);
934
945 static UBool arrayCompare(const UnicodeString* array1,
946 const UnicodeString* array2,
947 int32_t count);
948
954 void createZoneStrings(const UnicodeString *const * otherStrings);
955
959 void dispose(void);
960
965 void copyData(const DateFormatSymbols& other);
966
970 void initZoneStringsArray(void);
971
975 void disposeZoneStrings(void);
976
981 static UDateFormatField U_EXPORT2 getPatternCharIndex(char16_t c);
982
986 static UBool U_EXPORT2 isNumericField(UDateFormatField f, int32_t count);
987
991 static UBool U_EXPORT2 isNumericPatternChar(char16_t c, int32_t count);
992 public:
993 #ifndef U_HIDE_INTERNAL_API
994
1005 static DateFormatSymbols * U_EXPORT2 createForLocale(
1006 const Locale &locale, UErrorCode &status);
1007 #endif /* U_HIDE_INTERNAL_API */
1008 };
1009
1010 U_NAMESPACE_END
1011
1012 #endif /* #if !UCONFIG_NO_FORMATTING */
1013
1014 #endif // _DTFMTSYM
1015 //eof
icu::DateFormatSymbols::operator!=
UBool operator!=(const DateFormatSymbols &other) const
Return true if another object is semantically unequal to this one.
Definition: dtfmtsym.h:184
icu::DateFormatSymbols
DateFormatSymbols is a public class for encapsulating localizable date-time formatting data – includ...
Definition: dtfmtsym.h:82
icu::DateFormatSymbols::SHORT
Short width is currently only supported for weekday names.
Definition: dtfmtsym.h:299
icu::DateFormatSymbols::EMonthPatternType
EMonthPatternType
Somewhat temporary constants for leap month pattern types, adequate for supporting just leap month pa...
Definition: dtfmtsym.h:513
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:90
ULOC_FULLNAME_CAPACITY
#define ULOC_FULLNAME_CAPACITY
Useful constant for the maximum size of the whole locale ID (including the terminating NULL and all k...
Definition: uloc.h:264
icu::DateFormatSymbols::DtContextType
DtContextType
Selector for date formatting context.
Definition: dtfmtsym.h:275
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
calendar.h
C++ API: Calendar object.
udat.h
C API: DateFormat.
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
uobject.h
C++ API: Common ICU base class UObject.
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
UDateFormatField
UDateFormatField
FieldPosition and UFieldPosition selectors for format fields defined by DateFormat and UDateFormat...
Definition: udat.h:490
icu::DateFormatSymbols::DtWidthType
DtWidthType
Selector for date formatting width.
Definition: dtfmtsym.h:291
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:401
icu::SimpleDateFormat
SimpleDateFormat is a concrete class for formatting and parsing dates in a language-independent manne...
Definition: smpdtfmt.h:723
ULocDataLocaleType
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested...
Definition: uloc.h:338
strenum.h
C++ API: String Enumeration.
locid.h
C++ API: Locale ID object.
U_FINAL
#define U_FINAL
Defined to the C++11 "final" keyword if available.
Definition: umachine.h:140
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
FALSE
#define FALSE
The FALSE value of a UBool.
Definition: umachine.h:233
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:289
icu::DateFormatSymbols::ECapitalizationContextUsageType
ECapitalizationContextUsageType
Constants for capitalization context usage types.
Definition: dtfmtsym.h:605
icu::UObject
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:220
ures.h
C API: Resource Bundle.
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:192