ICU 62.1 62.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
36#if !UCONFIG_NO_FORMATTING
37
38#include "unicode/datefmt.h"
40#include "unicode/tzfmt.h" /* for UTimeZoneFormatTimeType */
41#include "unicode/brkiter.h"
42
44
45class DateFormatSymbols;
46class DateFormat;
47class MessageFormat;
48class FieldPositionHandler;
49class TimeZoneFormat;
50class SharedNumberFormat;
51class SimpleDateFormatMutableNFs;
52
53namespace number {
54class LocalizedNumberFormatter;
55}
56
724public:
735
749
772 const UnicodeString& override,
774
788 const Locale& locale,
790
813 const UnicodeString& override,
814 const Locale& locale,
816
829
842
848
854
860
867 virtual Format* clone(void) const;
868
876 virtual UBool operator==(const Format& other) const;
877
878
879 using DateFormat::format;
880
898 UnicodeString& appendTo,
899 FieldPosition& pos) const;
900
920 UnicodeString& appendTo,
922 UErrorCode& status) const;
923
924 using DateFormat::parse;
925
952 virtual void parse( const UnicodeString& text,
953 Calendar& cal,
954 ParsePosition& pos) const;
955
956
974
990 UDate get2DigitYearStart(UErrorCode& status) const;
991
999
1023 UErrorCode& status) const;
1024
1033 virtual void applyPattern(const UnicodeString& pattern);
1034
1045 virtual void applyLocalizedPattern(const UnicodeString& pattern,
1047
1056 virtual const DateFormatSymbols* getDateFormatSymbols(void) const;
1057
1065
1072
1085
1097 virtual UClassID getDynamicClassID(void) const;
1098
1109
1110 /* Cannot use #ifndef U_HIDE_INTERNAL_API for the following methods since they are virtual */
1119
1126
1132 virtual const TimeZoneFormat* getTimeZoneFormat(void) const;
1133
1145
1154
1171
1177 const NumberFormat * getNumberFormatForField(char16_t field) const;
1178
1179#ifndef U_HIDE_INTERNAL_API
1191
1192
1205 UCalendarDateFields field);
1206
1215 const Locale& getSmpFmtLocale(void) const;
1216#endif /* U_HIDE_INTERNAL_API */
1217
1218private:
1219 friend class DateFormat;
1220
1221 void initializeDefaultCentury(void);
1222
1223 void initializeBooleanAttributes(void);
1224
1225 SimpleDateFormat(); // default constructor not implemented
1226
1236
1245 SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
1246
1251
1268 void subFormat(UnicodeString &appendTo,
1269 char16_t ch,
1270 int32_t count,
1272 int32_t fieldNum,
1274 Calendar& cal,
1275 UErrorCode& status) const; // in case of illegal argument
1276
1290 void zeroPaddingNumber(const NumberFormat *currentNumberFormat,
1291 UnicodeString &appendTo,
1292 int32_t value,
1293 int32_t minDigits,
1294 int32_t maxDigits) const;
1295
1300 static UBool isNumeric(char16_t formatChar, int32_t count);
1301
1305 static UBool isAtNumericField(const UnicodeString &pattern, int32_t patternOffset);
1306
1310 static UBool isAfterNonNumericField(const UnicodeString &pattern, int32_t patternOffset);
1311
1319 Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status);
1320
1330 void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
1331
1338 void initialize(const Locale& locale, UErrorCode& status);
1339
1353 int32_t matchString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1355 const UnicodeString* monthPattern, Calendar& cal) const;
1356
1369 int32_t matchQuarterString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1370 const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const;
1371
1375 int32_t matchDayPeriodStrings(const UnicodeString& text, int32_t start,
1377 int32_t &dayPeriod) const;
1378
1394 static UBool matchLiterals(const UnicodeString &pattern, int32_t &patternOffset,
1395 const UnicodeString &text, int32_t &textOffset,
1397
1418 int32_t subParse(const UnicodeString& text, int32_t& start, char16_t ch, int32_t count,
1421 int32_t *dayPeriod=NULL) const;
1422
1423 void parseInt(const UnicodeString& text,
1424 Formattable& number,
1425 ParsePosition& pos,
1427 const NumberFormat *fmt) const;
1428
1429 void parseInt(const UnicodeString& text,
1430 Formattable& number,
1431 int32_t maxDigits,
1432 ParsePosition& pos,
1434 const NumberFormat *fmt) const;
1435
1436 int32_t checkIntSuffix(const UnicodeString& text, int32_t start,
1437 int32_t patLoc, UBool isNegative) const;
1438
1447 int32_t countDigits(const UnicodeString& text, int32_t start, int32_t end) const;
1448
1461 static void translatePattern(const UnicodeString& originalPattern,
1463 const UnicodeString& from,
1464 const UnicodeString& to,
1466
1474 void parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status);
1475
1485 int32_t compareSimpleAffix(const UnicodeString& affix,
1486 const UnicodeString& input,
1487 int32_t pos) const;
1488
1493 int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos) const;
1494
1499 int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const;
1500
1504 void initFastNumberFormatters(UErrorCode& status);
1505
1509 void freeFastNumberFormatters();
1510
1514 void initNumberFormatters(const Locale &locale,UErrorCode &status);
1515
1519 void processOverrideString(const Locale &locale, const UnicodeString &str, int8_t type, UErrorCode &status);
1520
1524 static const UCalendarDateFields fgPatternIndexToCalendarField[];
1525
1529 static const UDateFormatField fgPatternIndexToDateFormatField[];
1530
1534 TimeZoneFormat *tzFormat(UErrorCode &status) const;
1535
1536 const NumberFormat* getNumberFormatByIndex(UDateFormatField index) const;
1537
1544 static const int32_t fgCalendarFieldToLevel[];
1545
1549 static int32_t getLevelFromChar(char16_t ch);
1550
1554 static UBool isSyntaxChar(char16_t ch);
1555
1559 UnicodeString fPattern;
1560
1564 UnicodeString fDateOverride;
1565
1569 UnicodeString fTimeOverride;
1570
1571
1575 Locale fLocale;
1576
1581 DateFormatSymbols* fSymbols; // Owned
1582
1586 TimeZoneFormat* fTimeZoneFormat;
1587
1596 UDate fDefaultCenturyStart;
1597
1598 UBool fHasMinute;
1599 UBool fHasSecond;
1600
1604 void parsePattern();
1605
1609 /*transient*/ int32_t fDefaultCenturyStartYear;
1610
1611 struct NSOverride : public UMemory {
1612 const SharedNumberFormat *snf;
1613 int32_t hash;
1614 NSOverride *next;
1615 void free();
1616 NSOverride() : snf(NULL), hash(0), next(NULL) {
1617 }
1618 ~NSOverride();
1619 };
1620
1625 const SharedNumberFormat **fSharedNumberFormatters;
1626
1627 enum NumberFormatterKey {
1628 SMPDTFMT_NF_1x10,
1629 SMPDTFMT_NF_2x10,
1630 SMPDTFMT_NF_3x10,
1631 SMPDTFMT_NF_4x10,
1632 SMPDTFMT_NF_2x2,
1633 SMPDTFMT_NF_COUNT
1634 };
1635
1639 const number::LocalizedNumberFormatter* fFastNumberFormatters[SMPDTFMT_NF_COUNT] = {};
1640
1641 UBool fHaveDefaultCentury;
1642
1643 BreakIterator* fCapitalizationBrkIter;
1644};
1645
1646inline UDate
1647SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const
1648{
1649 return fDefaultCenturyStart;
1650}
1651
1653
1654#endif /* #if !UCONFIG_NO_FORMATTING */
1655
1656#endif // _SMPDTFMT
1657//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:202
DateFormatSymbols is a public class for encapsulating localizable date-time formatting data – includi...
Definition dtfmtsym.h:82
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition datefmt.h:150
EStyle
Constants for various style patterns.
Definition datefmt.h:161
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition fpositer.h:55
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition fieldpos.h:108
Base class for all formats.
Definition format.h:96
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition fmtable.h:62
"Smart pointer" base class; do not use directly: use LocalPointer etc.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:188
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:49
SimpleDateFormat is a concrete class for formatting and parsing dates in a language-independent manne...
Definition smpdtfmt.h:723
virtual Format * clone(void) const
Clone this Format object polymorphically.
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.
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:272
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition timezone.h:131
UMemory is the common ICU base class.
Definition uobject.h:112
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:287
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:204
UCalendarDateFields
Possible fields in a UCalendar.
Definition ucal.h:185
UDateFormatField
FieldPosition and UFieldPosition selectors for format fields defined by DateFormat and UDateFormat.
Definition udat.h:490
C API: Display context types (enum values)
UDisplayContext
Display context settings.
int8_t UBool
The ICU boolean type.
Definition umachine.h:236
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:93
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
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:396
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:360
double UDate
Date and Time data type.
Definition utypes.h:203
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:138
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:137