ICU 58.2 58.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

smpdtfmt.h
Go to the documentation of this file.
1 // Copyright (C) 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"
39 #include "unicode/udisplaycontext.h"
40 #include "unicode/tzfmt.h" /* for UTimeZoneFormatTimeType */
41 #include "unicode/brkiter.h"
42
43 U_NAMESPACE_BEGIN
44
45 class DateFormatSymbols;
46 class DateFormat;
47 class MessageFormat;
48 class FieldPositionHandler;
49 class TimeZoneFormat;
50 class SharedNumberFormat;
51 class SimpleDateFormatMutableNFs;
52
719 class U_I18N_API SimpleDateFormat: public DateFormat {
720 public:
730 SimpleDateFormat(UErrorCode& status);
731
743 SimpleDateFormat(const UnicodeString& pattern,
744 UErrorCode& status);
745
767 SimpleDateFormat(const UnicodeString& pattern,
768 const UnicodeString& override,
769 UErrorCode& status);
770
783 SimpleDateFormat(const UnicodeString& pattern,
784 const Locale& locale,
785 UErrorCode& status);
786
808 SimpleDateFormat(const UnicodeString& pattern,
809 const UnicodeString& override,
810 const Locale& locale,
811 UErrorCode& status);
812
822 SimpleDateFormat(const UnicodeString& pattern,
823 DateFormatSymbols* formatDataToAdopt,
824 UErrorCode& status);
825
835 SimpleDateFormat(const UnicodeString& pattern,
836 const DateFormatSymbols& formatData,
837 UErrorCode& status);
838
843 SimpleDateFormat(const SimpleDateFormat&);
844
849 SimpleDateFormat& operator=(const SimpleDateFormat&);
850
855 virtual ~SimpleDateFormat();
856
863 virtual Format* clone(void) const;
864
872 virtual UBool operator==(const Format& other) const;
873
874
875 using DateFormat::format;
876
893 virtual UnicodeString& format( Calendar& cal,
894 UnicodeString& appendTo,
895 FieldPosition& pos) const;
896
915 virtual UnicodeString& format( Calendar& cal,
916 UnicodeString& appendTo,
917 FieldPositionIterator* posIter,
918 UErrorCode& status) const;
919
920 using DateFormat::parse;
921
948 virtual void parse( const UnicodeString& text,
949 Calendar& cal,
950 ParsePosition& pos) const;
951
952
969 virtual void set2DigitYearStart(UDate d, UErrorCode& status);
970
986 UDate get2DigitYearStart(UErrorCode& status) const;
987
994 virtual UnicodeString& toPattern(UnicodeString& result) const;
995
1018 virtual UnicodeString& toLocalizedPattern(UnicodeString& result,
1019 UErrorCode& status) const;
1020
1029 virtual void applyPattern(const UnicodeString& pattern);
1030
1041 virtual void applyLocalizedPattern(const UnicodeString& pattern,
1042 UErrorCode& status);
1043
1052 virtual const DateFormatSymbols* getDateFormatSymbols(void) const;
1053
1060 virtual void adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols);
1061
1067 virtual void setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols);
1068
1080 static UClassID U_EXPORT2 getStaticClassID(void);
1081
1093 virtual UClassID getDynamicClassID(void) const;
1094
1104 virtual void adoptCalendar(Calendar* calendarToAdopt);
1105
1106 /* Cannot use #ifndef U_HIDE_INTERNAL_API for the following methods since they are virtual */
1114 virtual void adoptTimeZoneFormat(TimeZoneFormat* timeZoneFormatToAdopt);
1115
1121 virtual void setTimeZoneFormat(const TimeZoneFormat& newTimeZoneFormat);
1122
1128 virtual const TimeZoneFormat* getTimeZoneFormat(void) const;
1129
1140 virtual void setContext(UDisplayContext value, UErrorCode& status);
1141
1149 void adoptNumberFormat(NumberFormat *formatToAdopt);
1150
1166 void adoptNumberFormat(const UnicodeString& fields, NumberFormat *formatToAdopt, UErrorCode &status);
1167
1173 const NumberFormat * getNumberFormatForField(UChar field) const;
1174
1175 #ifndef U_HIDE_INTERNAL_API
1176
1186 UBool isFieldUnitIgnored(UCalendarDateFields field) const;
1187
1188
1200 static UBool isFieldUnitIgnored(const UnicodeString& pattern,
1201 UCalendarDateFields field);
1202
1211 const Locale& getSmpFmtLocale(void) const;
1212 #endif /* U_HIDE_INTERNAL_API */
1213
1214 private:
1215 friend class DateFormat;
1216
1217 void initializeDefaultCentury(void);
1218
1219 void initializeBooleanAttributes(void);
1220
1221 SimpleDateFormat(); // default constructor not implemented
1222
1231 SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
1232
1241 SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
1242
1246 UnicodeString& _format(Calendar& cal, UnicodeString& appendTo, FieldPositionHandler& handler, UErrorCode& status) const;
1247
1264 void subFormat(UnicodeString &appendTo,
1265 UChar ch,
1266 int32_t count,
1267 UDisplayContext capitalizationContext,
1268 int32_t fieldNum,
1269 FieldPositionHandler& handler,
1270 Calendar& cal,
1271 SimpleDateFormatMutableNFs &mutableNFs,
1272 UErrorCode& status) const; // in case of illegal argument
1273
1287 void zeroPaddingNumber(NumberFormat *currentNumberFormat,
1288 UnicodeString &appendTo,
1289 int32_t value,
1290 int32_t minDigits,
1291 int32_t maxDigits) const;
1292
1297 static UBool isNumeric(UChar formatChar, int32_t count);
1298
1302 static UBool isAtNumericField(const UnicodeString &pattern, int32_t patternOffset);
1303
1307 static UBool isAfterNonNumericField(const UnicodeString &pattern, int32_t patternOffset);
1308
1316 Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status);
1317
1327 void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
1328
1335 void initialize(const Locale& locale, UErrorCode& status);
1336
1350 int32_t matchString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1351 const UnicodeString* stringArray, int32_t stringArrayCount,
1352 const UnicodeString* monthPattern, Calendar& cal) const;
1353
1366 int32_t matchQuarterString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1367 const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const;
1368
1372 int32_t matchDayPeriodStrings(const UnicodeString& text, int32_t start,
1373 const UnicodeString* stringArray, int32_t stringArrayCount,
1374 int32_t &dayPeriod) const;
1375
1391 static UBool matchLiterals(const UnicodeString &pattern, int32_t &patternOffset,
1392 const UnicodeString &text, int32_t &textOffset,
1393 UBool whitespaceLenient, UBool partialMatchLenient, UBool oldLeniency);
1394
1415 int32_t subParse(const UnicodeString& text, int32_t& start, UChar ch, int32_t count,
1416 UBool obeyCount, UBool allowNegative, UBool ambiguousYear[], int32_t& saveHebrewMonth, Calendar& cal,
1417 int32_t patLoc, MessageFormat * numericLeapMonthFormatter, UTimeZoneFormatTimeType *tzTimeType, SimpleDateFormatMutableNFs &mutableNFs,
1418 int32_t *dayPeriod=NULL) const;
1419
1420 void parseInt(const UnicodeString& text,
1421 Formattable& number,
1422 ParsePosition& pos,
1423 UBool allowNegative,
1424 NumberFormat *fmt) const;
1425
1426 void parseInt(const UnicodeString& text,
1427 Formattable& number,
1428 int32_t maxDigits,
1429 ParsePosition& pos,
1430 UBool allowNegative,
1431 NumberFormat *fmt) const;
1432
1433 int32_t checkIntSuffix(const UnicodeString& text, int32_t start,
1434 int32_t patLoc, UBool isNegative) const;
1435
1448 static void translatePattern(const UnicodeString& originalPattern,
1449 UnicodeString& translatedPattern,
1450 const UnicodeString& from,
1451 const UnicodeString& to,
1452 UErrorCode& status);
1453
1461 void parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status);
1462
1472 int32_t compareSimpleAffix(const UnicodeString& affix,
1473 const UnicodeString& input,
1474 int32_t pos) const;
1475
1480 int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos) const;
1481
1486 int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const;
1487
1491 void initNumberFormatters(const Locale &locale,UErrorCode &status);
1492
1496 void processOverrideString(const Locale &locale, const UnicodeString &str, int8_t type, UErrorCode &status);
1497
1501 static const UCalendarDateFields fgPatternIndexToCalendarField[];
1502
1506 static const UDateFormatField fgPatternIndexToDateFormatField[];
1507
1511 TimeZoneFormat *tzFormat() const;
1512
1513 const NumberFormat* getNumberFormatByIndex(UDateFormatField index) const;
1514
1521 static const int32_t fgCalendarFieldToLevel[];
1522
1526 static int32_t getLevelFromChar(UChar ch);
1527
1531 static UBool isSyntaxChar(UChar ch);
1532
1536 UnicodeString fPattern;
1537
1541 UnicodeString fDateOverride;
1542
1546 UnicodeString fTimeOverride;
1547
1548
1552 Locale fLocale;
1553
1558 DateFormatSymbols* fSymbols; // Owned
1559
1563 TimeZoneFormat* fTimeZoneFormat;
1564
1573 UDate fDefaultCenturyStart;
1574
1575 UBool fHasMinute;
1576 UBool fHasSecond;
1577
1581 void parsePattern();
1582
1586 /*transient*/ int32_t fDefaultCenturyStartYear;
1587
1588 struct NSOverride : public UMemory {
1589 const SharedNumberFormat *snf;
1590 int32_t hash;
1591 NSOverride *next;
1592 void free();
1593 NSOverride() : snf(NULL), hash(0), next(NULL) {
1594 }
1595 ~NSOverride();
1596 };
1597
1602 const SharedNumberFormat **fSharedNumberFormatters;
1603
1604 UBool fHaveDefaultCentury;
1605
1606 BreakIterator* fCapitalizationBrkIter;
1607 };
1608
1609 inline UDate
1610 SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const
1611 {
1612 return fDefaultCenturyStart;
1613 }
1614
1615 U_NAMESPACE_END
1616
1617 #endif /* #if !UCONFIG_NO_FORMATTING */
1618
1619 #endif // _SMPDTFMT
1620 //eof
brkiter.h
C++ API: Break Iterator.
tzfmt.h
C++ API: TimeZoneFormat.
icu::Format
Base class for all formats.
Definition: format.h:96
icu::TimeZoneFormat
TimeZoneFormat supports time zone display name formatting and parsing.
Definition: tzfmt.h:272
UCalendarDateFields
UCalendarDateFields
Possible fields in a UCalendar.
Definition: ucal.h:185
UTimeZoneFormatTimeType
UTimeZoneFormatTimeType
Constants for time types used by TimeZoneFormat APIs for receiving time type (standard time...
Definition: tzfmt.h:204
icu::NumberFormat
Abstract base class for all number formats.
Definition: numfmt.h:169
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
icu::DateFormatSymbols
DateFormatSymbols is a public class for encapsulating localizable date-time formatting data – includ...
Definition: dtfmtsym.h:81
icu::DateFormat::setContext
virtual void setContext(UDisplayContext value, UErrorCode &status)
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
icu::Calendar
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition: calendar.h:202
UDisplayContext
UDisplayContext
Display context settings.
Definition: udisplaycontext.h:66
UDate
double UDate
Date and Time data type.
Definition: utypes.h:203
icu::DateFormat::parse
virtual UDate parse(const UnicodeString &text, UErrorCode &status) const
Parse a date/time string.
icu::DateFormat::operator=
DateFormat & operator=(const DateFormat &)
Default assignment operator.
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:93
icu::DateFormat::adoptNumberFormat
virtual void adoptNumberFormat(NumberFormat *formatToAdopt)
Allows you to set the number formatter.
icu::Format::clone
virtual Format * clone() const =0
Clone this object polymorphically.
icu::TimeZone
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:131
udisplaycontext.h
C API: Display context types (enum values)
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:360
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
icu::FieldPositionIterator
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:55
icu::DateFormat::format
virtual UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
Format an object to produce a string.
icu::BreakIterator
The BreakIterator class implements methods for finding the location of boundaries in text...
Definition: brkiter.h:102
NULL
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
Definition: utypes.h:188
icu::DateFormat::EStyle
EStyle
Constants for various style patterns.
Definition: datefmt.h:159
icu::MessageFormat
Definition: msgfmt.h:325
UChar
uint16_t UChar
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
Definition: umachine.h:337
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
UDateFormatField
UDateFormatField
FieldPosition and UFieldPosition selectors for format fields defined by DateFormat and UDateFormat...
Definition: udat.h:490
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
icu::SimpleDateFormat
SimpleDateFormat is a concrete class for formatting and parsing dates in a language-independent manne...
Definition: smpdtfmt.h:719
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:108
datefmt.h
C++ API: Abstract class for converting dates.
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:49
icu::DateFormat
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition: datefmt.h:149
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::DateFormat::operator==
virtual UBool operator==(const Format &) const
Equality operator.
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:68
icu::DateFormat::adoptCalendar
virtual void adoptCalendar(Calendar *calendarToAdopt)
Set the calendar to be used by this date format.
icu::UMemory
UMemory is the common ICU base class.
Definition: uobject.h:112
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:259
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:187