ICU 56.1: smpdtfmt.h Source File

ICU 56.1 56.1

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

- File List
- Globals

smpdtfmt.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 1997-2015, International Business Machines Corporation and
3 * others. All Rights Reserved.
4 *******************************************************************************
5 *
6 * File SMPDTFMT.H
7 *
8 * Modification History:
9 *
10 * Date Name Description
11 * 02/19/97 aliu Converted from java.
12 * 07/09/97 helena Make ParsePosition into a class.
13 * 07/21/98 stephen Added GMT_PLUS, GMT_MINUS
14 * Changed setTwoDigitStartDate to set2DigitYearStart
15 * Changed getTwoDigitStartDate to get2DigitYearStart
16 * Removed subParseLong
17 * Removed getZoneIndex (added in DateFormatSymbols)
18 * 06/14/99 stephen Removed fgTimeZoneDataSuffix
19 * 10/14/99 aliu Updated class doc to describe 2-digit year parsing
20 * {j28 4182066}.
21 *******************************************************************************
22 */
23
24 #ifndef SMPDTFMT_H
25 #define SMPDTFMT_H
26
27 #include "unicode/utypes.h"
28
34 #if !UCONFIG_NO_FORMATTING
35
36 #include "unicode/datefmt.h"
37 #include "unicode/udisplaycontext.h"
38 #include "unicode/tzfmt.h" /* for UTimeZoneFormatTimeType */
39 #include "unicode/brkiter.h"
40
41 U_NAMESPACE_BEGIN
42
43 class DateFormatSymbols;
44 class DateFormat;
45 class MessageFormat;
46 class FieldPositionHandler;
47 class TimeZoneFormat;
48 class SharedNumberFormat;
49 class SimpleDateFormatMutableNFs;
50
717 class U_I18N_API SimpleDateFormat: public DateFormat {
718 public:
728 SimpleDateFormat(UErrorCode& status);
729
741 SimpleDateFormat(const UnicodeString& pattern,
742 UErrorCode& status);
743
765 SimpleDateFormat(const UnicodeString& pattern,
766 const UnicodeString& override,
767 UErrorCode& status);
768
781 SimpleDateFormat(const UnicodeString& pattern,
782 const Locale& locale,
783 UErrorCode& status);
784
806 SimpleDateFormat(const UnicodeString& pattern,
807 const UnicodeString& override,
808 const Locale& locale,
809 UErrorCode& status);
810
820 SimpleDateFormat(const UnicodeString& pattern,
821 DateFormatSymbols* formatDataToAdopt,
822 UErrorCode& status);
823
833 SimpleDateFormat(const UnicodeString& pattern,
834 const DateFormatSymbols& formatData,
835 UErrorCode& status);
836
841 SimpleDateFormat(const SimpleDateFormat&);
842
847 SimpleDateFormat& operator=(const SimpleDateFormat&);
848
853 virtual ~SimpleDateFormat();
854
861 virtual Format* clone(void) const;
862
870 virtual UBool operator==(const Format& other) const;
871
872
873 using DateFormat::format;
874
891 virtual UnicodeString& format( Calendar& cal,
892 UnicodeString& appendTo,
893 FieldPosition& pos) const;
894
913 virtual UnicodeString& format( Calendar& cal,
914 UnicodeString& appendTo,
915 FieldPositionIterator* posIter,
916 UErrorCode& status) const;
917
918 using DateFormat::parse;
919
946 virtual void parse( const UnicodeString& text,
947 Calendar& cal,
948 ParsePosition& pos) const;
949
950
967 virtual void set2DigitYearStart(UDate d, UErrorCode& status);
968
984 UDate get2DigitYearStart(UErrorCode& status) const;
985
992 virtual UnicodeString& toPattern(UnicodeString& result) const;
993
1010 virtual UnicodeString& toLocalizedPattern(UnicodeString& result,
1011 UErrorCode& status) const;
1012
1021 virtual void applyPattern(const UnicodeString& pattern);
1022
1033 virtual void applyLocalizedPattern(const UnicodeString& pattern,
1034 UErrorCode& status);
1035
1044 virtual const DateFormatSymbols* getDateFormatSymbols(void) const;
1045
1052 virtual void adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols);
1053
1059 virtual void setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols);
1060
1072 static UClassID U_EXPORT2 getStaticClassID(void);
1073
1085 virtual UClassID getDynamicClassID(void) const;
1086
1096 virtual void adoptCalendar(Calendar* calendarToAdopt);
1097
1098 /* Cannot use #ifndef U_HIDE_INTERNAL_API for the following methods since they are virtual */
1106 virtual void adoptTimeZoneFormat(TimeZoneFormat* timeZoneFormatToAdopt);
1107
1113 virtual void setTimeZoneFormat(const TimeZoneFormat& newTimeZoneFormat);
1114
1120 virtual const TimeZoneFormat* getTimeZoneFormat(void) const;
1121
1132 virtual void setContext(UDisplayContext value, UErrorCode& status);
1133
1141 void adoptNumberFormat(NumberFormat *formatToAdopt);
1142
1158 void adoptNumberFormat(const UnicodeString& fields, NumberFormat *formatToAdopt, UErrorCode &status);
1159
1165 const NumberFormat * getNumberFormatForField(UChar field) const;
1166
1167 #ifndef U_HIDE_INTERNAL_API
1168
1178 UBool isFieldUnitIgnored(UCalendarDateFields field) const;
1179
1180
1192 static UBool isFieldUnitIgnored(const UnicodeString& pattern,
1193 UCalendarDateFields field);
1194
1203 const Locale& getSmpFmtLocale(void) const;
1204 #endif /* U_HIDE_INTERNAL_API */
1205
1206 private:
1207 friend class DateFormat;
1208
1209 void initializeDefaultCentury(void);
1210
1211 void initializeBooleanAttributes(void);
1212
1213 SimpleDateFormat(); // default constructor not implemented
1214
1223 SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
1224
1233 SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
1234
1238 UnicodeString& _format(Calendar& cal, UnicodeString& appendTo, FieldPositionHandler& handler, UErrorCode& status) const;
1239
1256 void subFormat(UnicodeString &appendTo,
1257 UChar ch,
1258 int32_t count,
1259 UDisplayContext capitalizationContext,
1260 int32_t fieldNum,
1261 FieldPositionHandler& handler,
1262 Calendar& cal,
1263 SimpleDateFormatMutableNFs &mutableNFs,
1264 UErrorCode& status) const; // in case of illegal argument
1265
1279 void zeroPaddingNumber(NumberFormat *currentNumberFormat,
1280 UnicodeString &appendTo,
1281 int32_t value,
1282 int32_t minDigits,
1283 int32_t maxDigits) const;
1284
1289 static UBool isNumeric(UChar formatChar, int32_t count);
1290
1294 static UBool isAtNumericField(const UnicodeString &pattern, int32_t patternOffset);
1295
1299 static UBool isAfterNonNumericField(const UnicodeString &pattern, int32_t patternOffset);
1300
1308 Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status);
1309
1319 void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
1320
1327 void initialize(const Locale& locale, UErrorCode& status);
1328
1342 int32_t matchString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1343 const UnicodeString* stringArray, int32_t stringArrayCount,
1344 const UnicodeString* monthPattern, Calendar& cal) const;
1345
1358 int32_t matchQuarterString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1359 const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const;
1360
1376 static UBool matchLiterals(const UnicodeString &pattern, int32_t &patternOffset,
1377 const UnicodeString &text, int32_t &textOffset,
1378 UBool whitespaceLenient, UBool partialMatchLenient, UBool oldLeniency);
1379
1400 int32_t subParse(const UnicodeString& text, int32_t& start, UChar ch, int32_t count,
1401 UBool obeyCount, UBool allowNegative, UBool ambiguousYear[], int32_t& saveHebrewMonth, Calendar& cal,
1402 int32_t patLoc, MessageFormat * numericLeapMonthFormatter, UTimeZoneFormatTimeType *tzTimeType, SimpleDateFormatMutableNFs &mutableNFs) const;
1403
1404 void parseInt(const UnicodeString& text,
1405 Formattable& number,
1406 ParsePosition& pos,
1407 UBool allowNegative,
1408 NumberFormat *fmt) const;
1409
1410 void parseInt(const UnicodeString& text,
1411 Formattable& number,
1412 int32_t maxDigits,
1413 ParsePosition& pos,
1414 UBool allowNegative,
1415 NumberFormat *fmt) const;
1416
1417 int32_t checkIntSuffix(const UnicodeString& text, int32_t start,
1418 int32_t patLoc, UBool isNegative) const;
1419
1432 static void translatePattern(const UnicodeString& originalPattern,
1433 UnicodeString& translatedPattern,
1434 const UnicodeString& from,
1435 const UnicodeString& to,
1436 UErrorCode& status);
1437
1445 void parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status);
1446
1456 int32_t compareSimpleAffix(const UnicodeString& affix,
1457 const UnicodeString& input,
1458 int32_t pos) const;
1459
1464 int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos) const;
1465
1470 int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const;
1471
1475 void initNumberFormatters(const Locale &locale,UErrorCode &status);
1476
1480 void processOverrideString(const Locale &locale, const UnicodeString &str, int8_t type, UErrorCode &status);
1481
1485 static const UCalendarDateFields fgPatternIndexToCalendarField[];
1486
1490 static const UDateFormatField fgPatternIndexToDateFormatField[];
1491
1495 TimeZoneFormat *tzFormat() const;
1496
1497 const NumberFormat* getNumberFormatByIndex(UDateFormatField index) const;
1498
1505 static const int32_t fgCalendarFieldToLevel[];
1506
1510 static int32_t getLevelFromChar(UChar ch);
1511
1515 static UBool isSyntaxChar(UChar ch);
1516
1520 UnicodeString fPattern;
1521
1525 UnicodeString fDateOverride;
1526
1530 UnicodeString fTimeOverride;
1531
1532
1536 Locale fLocale;
1537
1542 DateFormatSymbols* fSymbols; // Owned
1543
1547 TimeZoneFormat* fTimeZoneFormat;
1548
1557 UDate fDefaultCenturyStart;
1558
1562 /*transient*/ int32_t fDefaultCenturyStartYear;
1563
1564 struct NSOverride : public UMemory {
1565 const SharedNumberFormat *snf;
1566 int32_t hash;
1567 NSOverride *next;
1568 void free();
1569 NSOverride() : snf(NULL), hash(0), next(NULL) {
1570 }
1571 ~NSOverride();
1572 };
1573
1578 const SharedNumberFormat **fSharedNumberFormatters;
1579
1580 UBool fHaveDefaultCentury;
1581
1582 BreakIterator* fCapitalizationBrkIter;
1583 };
1584
1585 inline UDate
1586 SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const
1587 {
1588 return fDefaultCenturyStart;
1589 }
1590
1591 U_NAMESPACE_END
1592
1593 #endif /* #if !UCONFIG_NO_FORMATTING */
1594
1595 #endif // _SMPDTFMT
1596 //eof
brkiter.h
C++ API: Break Iterator.
tzfmt.h
C++ API: TimeZoneFormat.
icu::Format
Base class for all formats.
Definition: format.h:94
icu::TimeZoneFormat
TimeZoneFormat supports time zone display name formatting and parsing.
Definition: tzfmt.h:270
UCalendarDateFields
UCalendarDateFields
Possible fields in a UCalendar.
Definition: ucal.h:183
UTimeZoneFormatTimeType
UTimeZoneFormatTimeType
Constants for time types used by TimeZoneFormat APIs for receiving time type (standard time...
Definition: tzfmt.h:202
icu::NumberFormat
Abstract base class for all number formats.
Definition: numfmt.h:172
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man'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:79
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:200
UDisplayContext
UDisplayContext
Display context settings.
Definition: udisplaycontext.h:56
UDate
double UDate
Date and Time data type.
Definition: utypes.h:201
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's RTTI.
Definition: uobject.h:91
icu::DateFormat::adoptNumberFormat
virtual void adoptNumberFormat(NumberFormat *formatToAdopt)
Allows you to set the number formatter.
icu::TimeZone
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:129
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:358
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
icu::FieldPositionIterator
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:53
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:100
NULL
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
Definition: utypes.h:186
icu::DateFormat::EStyle
EStyle
Constants for various style patterns.
Definition: datefmt.h:157
icu::MessageFormat
Definition: msgfmt.h:323
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:312
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
UDateFormatField
UDateFormatField
FieldPosition and UFieldPosition selectors for format fields defined by DateFormat and UDateFormat...
Definition: udat.h:488
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
icu::SimpleDateFormat
SimpleDateFormat is a concrete class for formatting and parsing dates in a language-independent manne...
Definition: smpdtfmt.h:717
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:106
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:47
icu::DateFormat
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition: datefmt.h:147
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:293
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:66
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:110
icu::Format::clone
virtual Format * clone() const =0
Clone this object polymorphically.
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185