ICU 66.1 66.1
smpdtfmt.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* Copyright (C) 1997-2016, International Business Machines Corporation and
5* others. All Rights Reserved.
6*******************************************************************************
7*
8* File SMPDTFMT.H
9*
10* Modification History:
11*
12* Date Name Description
13* 02/19/97 aliu Converted from java.
14* 07/09/97 helena Make ParsePosition into a class.
15* 07/21/98 stephen Added GMT_PLUS, GMT_MINUS
16* Changed setTwoDigitStartDate to set2DigitYearStart
17* Changed getTwoDigitStartDate to get2DigitYearStart
18* Removed subParseLong
19* Removed getZoneIndex (added in DateFormatSymbols)
20* 06/14/99 stephen Removed fgTimeZoneDataSuffix
21* 10/14/99 aliu Updated class doc to describe 2-digit year parsing
22* {j28 4182066}.
23*******************************************************************************
24*/
25
26#ifndef SMPDTFMT_H
27#define SMPDTFMT_H
28
29#include "unicode/utypes.h"
30
31#if U_SHOW_CPLUSPLUS_API
32
38#if !UCONFIG_NO_FORMATTING
39
40#include "unicode/datefmt.h"
42#include "unicode/tzfmt.h" /* for UTimeZoneFormatTimeType */
43#include "unicode/brkiter.h"
44
45U_NAMESPACE_BEGIN
46
47class DateFormatSymbols;
48class DateFormat;
49class MessageFormat;
50class FieldPositionHandler;
51class TimeZoneFormat;
52class SharedNumberFormat;
53class SimpleDateFormatMutableNFs;
54class DateIntervalFormat;
55
56namespace number {
57class LocalizedNumberFormatter;
58}
59
727public:
738
751 UErrorCode& status);
752
775 const UnicodeString& override,
776 UErrorCode& status);
777
791 const Locale& locale,
792 UErrorCode& status);
793
816 const UnicodeString& override,
817 const Locale& locale,
818 UErrorCode& status);
819
830 DateFormatSymbols* formatDataToAdopt,
831 UErrorCode& status);
832
843 const DateFormatSymbols& formatData,
844 UErrorCode& status);
845
851
857
863
870 virtual SimpleDateFormat* clone() const;
871
879 virtual UBool operator==(const Format& other) const;
880
881
882 using DateFormat::format;
883
901 UnicodeString& appendTo,
902 FieldPosition& pos) const;
903
923 UnicodeString& appendTo,
924 FieldPositionIterator* posIter,
925 UErrorCode& status) const;
926
927 using DateFormat::parse;
928
955 virtual void parse( const UnicodeString& text,
956 Calendar& cal,
957 ParsePosition& pos) const;
958
959
976 virtual void set2DigitYearStart(UDate d, UErrorCode& status);
977
993 UDate get2DigitYearStart(UErrorCode& status) const;
994
1001 virtual UnicodeString& toPattern(UnicodeString& result) const;
1002
1026 UErrorCode& status) const;
1027
1036 virtual void applyPattern(const UnicodeString& pattern);
1037
1048 virtual void applyLocalizedPattern(const UnicodeString& pattern,
1049 UErrorCode& status);
1050
1059 virtual const DateFormatSymbols* getDateFormatSymbols(void) const;
1060
1067 virtual void adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols);
1068
1074 virtual void setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols);
1075
1087 static UClassID U_EXPORT2 getStaticClassID(void);
1088
1100 virtual UClassID getDynamicClassID(void) const;
1101
1111 virtual void adoptCalendar(Calendar* calendarToAdopt);
1112
1113 /* Cannot use #ifndef U_HIDE_INTERNAL_API for the following methods since they are virtual */
1121 virtual void adoptTimeZoneFormat(TimeZoneFormat* timeZoneFormatToAdopt);
1122
1128 virtual void setTimeZoneFormat(const TimeZoneFormat& newTimeZoneFormat);
1129
1135 virtual const TimeZoneFormat* getTimeZoneFormat(void) const;
1136
1147 virtual void setContext(UDisplayContext value, UErrorCode& status);
1148
1156 void adoptNumberFormat(NumberFormat *formatToAdopt);
1157
1173 void adoptNumberFormat(const UnicodeString& fields, NumberFormat *formatToAdopt, UErrorCode &status);
1174
1180 const NumberFormat * getNumberFormatForField(char16_t field) const;
1181
1182#ifndef U_HIDE_INTERNAL_API
1194
1195
1208 UCalendarDateFields field);
1209
1218 const Locale& getSmpFmtLocale(void) const;
1219#endif /* U_HIDE_INTERNAL_API */
1220
1221private:
1222 friend class DateFormat;
1223 friend class DateIntervalFormat;
1224
1225 void initializeDefaultCentury(void);
1226
1227 void initializeBooleanAttributes(void);
1228
1229 SimpleDateFormat(); // default constructor not implemented
1230
1239 SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
1240
1249 SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
1250
1254 UnicodeString& _format(Calendar& cal, UnicodeString& appendTo, FieldPositionHandler& handler, UErrorCode& status) const;
1255
1272 void subFormat(UnicodeString &appendTo,
1273 char16_t ch,
1274 int32_t count,
1275 UDisplayContext capitalizationContext,
1276 int32_t fieldNum,
1277 FieldPositionHandler& handler,
1278 Calendar& cal,
1279 UErrorCode& status) const; // in case of illegal argument
1280
1294 void zeroPaddingNumber(const NumberFormat *currentNumberFormat,
1295 UnicodeString &appendTo,
1296 int32_t value,
1297 int32_t minDigits,
1298 int32_t maxDigits) const;
1299
1304 static UBool isNumeric(char16_t formatChar, int32_t count);
1305
1309 static UBool isAtNumericField(const UnicodeString &pattern, int32_t patternOffset);
1310
1314 static UBool isAfterNonNumericField(const UnicodeString &pattern, int32_t patternOffset);
1315
1323 Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status);
1324
1334 void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
1335
1342 void initialize(const Locale& locale, UErrorCode& status);
1343
1357 int32_t matchString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1358 const UnicodeString* stringArray, int32_t stringArrayCount,
1359 const UnicodeString* monthPattern, Calendar& cal) const;
1360
1373 int32_t matchQuarterString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1374 const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const;
1375
1379 int32_t matchDayPeriodStrings(const UnicodeString& text, int32_t start,
1380 const UnicodeString* stringArray, int32_t stringArrayCount,
1381 int32_t &dayPeriod) const;
1382
1398 static UBool matchLiterals(const UnicodeString &pattern, int32_t &patternOffset,
1399 const UnicodeString &text, int32_t &textOffset,
1400 UBool whitespaceLenient, UBool partialMatchLenient, UBool oldLeniency);
1401
1422 int32_t subParse(const UnicodeString& text, int32_t& start, char16_t ch, int32_t count,
1423 UBool obeyCount, UBool allowNegative, UBool ambiguousYear[], int32_t& saveHebrewMonth, Calendar& cal,
1424 int32_t patLoc, MessageFormat * numericLeapMonthFormatter, UTimeZoneFormatTimeType *tzTimeType,
1425 int32_t *dayPeriod=NULL) const;
1426
1427 void parseInt(const UnicodeString& text,
1428 Formattable& number,
1429 ParsePosition& pos,
1430 UBool allowNegative,
1431 const NumberFormat *fmt) const;
1432
1433 void parseInt(const UnicodeString& text,
1434 Formattable& number,
1435 int32_t maxDigits,
1436 ParsePosition& pos,
1437 UBool allowNegative,
1438 const NumberFormat *fmt) const;
1439
1440 int32_t checkIntSuffix(const UnicodeString& text, int32_t start,
1441 int32_t patLoc, UBool isNegative) const;
1442
1451 int32_t countDigits(const UnicodeString& text, int32_t start, int32_t end) const;
1452
1465 static void translatePattern(const UnicodeString& originalPattern,
1466 UnicodeString& translatedPattern,
1467 const UnicodeString& from,
1468 const UnicodeString& to,
1469 UErrorCode& status);
1470
1478 void parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status);
1479
1489 int32_t compareSimpleAffix(const UnicodeString& affix,
1490 const UnicodeString& input,
1491 int32_t pos) const;
1492
1497 int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos) const;
1498
1503 int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const;
1504
1508 void initFastNumberFormatters(UErrorCode& status);
1509
1513 void freeFastNumberFormatters();
1514
1518 void initNumberFormatters(const Locale &locale,UErrorCode &status);
1519
1523 void processOverrideString(const Locale &locale, const UnicodeString &str, int8_t type, UErrorCode &status);
1524
1528 static const UCalendarDateFields fgPatternIndexToCalendarField[];
1529
1533 static const UDateFormatField fgPatternIndexToDateFormatField[];
1534
1538 TimeZoneFormat *tzFormat(UErrorCode &status) const;
1539
1540 const NumberFormat* getNumberFormatByIndex(UDateFormatField index) const;
1541
1548 static const int32_t fgCalendarFieldToLevel[];
1549
1553 static int32_t getLevelFromChar(char16_t ch);
1554
1558 static UBool isSyntaxChar(char16_t ch);
1559
1563 UnicodeString fPattern;
1564
1568 UnicodeString fDateOverride;
1569
1573 UnicodeString fTimeOverride;
1574
1575
1579 Locale fLocale;
1580
1585 DateFormatSymbols* fSymbols; // Owned
1586
1590 TimeZoneFormat* fTimeZoneFormat;
1591
1600 UDate fDefaultCenturyStart;
1601
1602 UBool fHasMinute;
1603 UBool fHasSecond;
1604 UBool fHasHanYearChar; // pattern contains the Han year character \u5E74
1605
1609 void parsePattern();
1610
1614 /*transient*/ int32_t fDefaultCenturyStartYear;
1615
1616 struct NSOverride : public UMemory {
1617 const SharedNumberFormat *snf;
1618 int32_t hash;
1619 NSOverride *next;
1620 void free();
1621 NSOverride() : snf(NULL), hash(0), next(NULL) {
1622 }
1623 ~NSOverride();
1624 };
1625
1630 const SharedNumberFormat **fSharedNumberFormatters;
1631
1632 enum NumberFormatterKey {
1633 SMPDTFMT_NF_1x10,
1634 SMPDTFMT_NF_2x10,
1635 SMPDTFMT_NF_3x10,
1636 SMPDTFMT_NF_4x10,
1637 SMPDTFMT_NF_2x2,
1638 SMPDTFMT_NF_COUNT
1639 };
1640
1644 const number::LocalizedNumberFormatter* fFastNumberFormatters[SMPDTFMT_NF_COUNT] = {};
1645
1646 UBool fHaveDefaultCentury;
1647
1648 const BreakIterator* fCapitalizationBrkIter;
1649};
1650
1651inline UDate
1652SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const
1653{
1654 return fDefaultCenturyStart;
1655}
1656
1657U_NAMESPACE_END
1658
1659#endif /* #if !UCONFIG_NO_FORMATTING */
1660
1661#endif /* U_SHOW_CPLUSPLUS_API */
1662
1663#endif // _SMPDTFMT
1664//eof
C++ API: Break Iterator.
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition: calendar.h:187
DateFormatSymbols is a public class for encapsulating localizable date-time formatting data – includi...
Definition: dtfmtsym.h:84
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition: datefmt.h:156
EStyle
Constants for various style patterns.
Definition: datefmt.h:167
DateIntervalFormat is a class for formatting and parsing date intervals in a language-independent man...
Definition: dtitvfmt.h:300
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:58
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:110
Base class for all formats.
Definition: format.h:98
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:64
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:52
SimpleDateFormat is a concrete class for formatting and parsing dates in a language-independent manne...
Definition: smpdtfmt.h:726
virtual UnicodeString & toLocalizedPattern(UnicodeString &result, UErrorCode &status) const
Return a localized pattern string describing this date format.
virtual void parse(const UnicodeString &text, Calendar &cal, ParsePosition &pos) const
Parse a date/time string beginning at the given parse position.
SimpleDateFormat(const UnicodeString &pattern, const UnicodeString &override, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern, numbering system override, and the default loca...
virtual const DateFormatSymbols * getDateFormatSymbols(void) const
Gets the date/time formatting symbols (this is an object carrying the various strings and other symbo...
virtual UnicodeString & format(Calendar &cal, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const
Format a date or time, which is the standard millis since 24:00 GMT, Jan 1, 1970.
virtual void applyPattern(const UnicodeString &pattern)
Apply the given unlocalized pattern string to this date format.
SimpleDateFormat(const SimpleDateFormat &)
Copy constructor.
virtual void adoptDateFormatSymbols(DateFormatSymbols *newFormatSymbols)
Set the date/time formatting symbols.
SimpleDateFormat(const UnicodeString &pattern, DateFormatSymbols *formatDataToAdopt, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale-specific symbol data.
virtual void setDateFormatSymbols(const DateFormatSymbols &newFormatSymbols)
Set the date/time formatting data.
static UClassID getStaticClassID(void)
Return the class ID for this class.
SimpleDateFormat(const UnicodeString &pattern, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and the default locale.
virtual const TimeZoneFormat * getTimeZoneFormat(void) const
Gets the time zone format object associated with this date/time formatter.
virtual UnicodeString & format(Calendar &cal, UnicodeString &appendTo, FieldPosition &pos) const
Format a date or time, which is the standard millis since 24:00 GMT, Jan 1, 1970.
virtual void setContext(UDisplayContext value, UErrorCode &status)
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
UBool isFieldUnitIgnored(UCalendarDateFields field) const
This is for ICU internal use only.
virtual UBool operator==(const Format &other) const
Return true if the given Format objects are semantically equal.
SimpleDateFormat(const UnicodeString &pattern, const DateFormatSymbols &formatData, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale-specific symbol data.
virtual void setTimeZoneFormat(const TimeZoneFormat &newTimeZoneFormat)
Sets the TimeZoneFormat to be used by this date/time formatter.
const Locale & getSmpFmtLocale(void) const
This is for ICU internal use only.
SimpleDateFormat(UErrorCode &status)
Construct a SimpleDateFormat using the default pattern for the default locale.
const NumberFormat * getNumberFormatForField(char16_t field) const
Get the numbering system to be used for a particular field.
SimpleDateFormat & operator=(const SimpleDateFormat &)
Assignment operator.
virtual SimpleDateFormat * clone() const
Clone this Format object polymorphically.
void adoptNumberFormat(NumberFormat *formatToAdopt)
Overrides base class method and This method clears per field NumberFormat instances previously set by...
virtual void set2DigitYearStart(UDate d, UErrorCode &status)
Set the start UDate used to interpret two-digit year strings.
virtual ~SimpleDateFormat()
Destructor.
void adoptNumberFormat(const UnicodeString &fields, NumberFormat *formatToAdopt, UErrorCode &status)
Allow the user to set the NumberFormat for several fields It can be a single field like: "y"(year) or...
SimpleDateFormat(const UnicodeString &pattern, const UnicodeString &override, const Locale &locale, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern, numbering system override, and locale.
virtual void adoptCalendar(Calendar *calendarToAdopt)
Set the calendar to be used by this date format.
SimpleDateFormat(const UnicodeString &pattern, const Locale &locale, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale.
static UBool isFieldUnitIgnored(const UnicodeString &pattern, UCalendarDateFields field)
This is for ICU internal use only.
virtual void adoptTimeZoneFormat(TimeZoneFormat *timeZoneFormatToAdopt)
Sets the TimeZoneFormat to be used by this date/time formatter.
virtual UClassID getDynamicClassID(void) const
Returns a unique class ID POLYMORPHICALLY.
virtual UnicodeString & toPattern(UnicodeString &result) const
Return a pattern string describing this date format.
virtual void applyLocalizedPattern(const UnicodeString &pattern, UErrorCode &status)
Apply the given localized pattern string to this date format.
TimeZoneFormat supports time zone display name formatting and parsing.
Definition: tzfmt.h:274
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:133
UMemory is the common ICU base class.
Definition: uobject.h:115
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
C++ API: Abstract class for converting dates.
C++ API: TimeZoneFormat.
UTimeZoneFormatTimeType
Constants for time types used by TimeZoneFormat APIs for receiving time type (standard time,...
Definition: tzfmt.h:206
UCalendarDateFields
Possible fields in a UCalendar.
Definition: ucal.h:199
UDateFormatField
FieldPosition and UFieldPosition selectors for format fields defined by DateFormat and UDateFormat.
Definition: udat.h:511
C API: Display context types (enum values)
UDisplayContext
Display context settings.
int8_t UBool
The ICU boolean type.
Definition: umachine.h:261
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
#define NULL
Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.
Definition: utypes.h:188
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:301
double UDate
Date and Time data type.
Definition: utypes.h:203