ICU 54.1 54.1

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

- File List
- Globals

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
smpdtfmt.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 1997-2014, 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
715 class U_I18N_API SimpleDateFormat: public DateFormat {
716 public:
726 SimpleDateFormat(UErrorCode& status);
727
739 SimpleDateFormat(const UnicodeString& pattern,
740 UErrorCode& status);
741
763 SimpleDateFormat(const UnicodeString& pattern,
764 const UnicodeString& override,
765 UErrorCode& status);
766
779 SimpleDateFormat(const UnicodeString& pattern,
780 const Locale& locale,
781 UErrorCode& status);
782
804 SimpleDateFormat(const UnicodeString& pattern,
805 const UnicodeString& override,
806 const Locale& locale,
807 UErrorCode& status);
808
818 SimpleDateFormat(const UnicodeString& pattern,
819 DateFormatSymbols* formatDataToAdopt,
820 UErrorCode& status);
821
831 SimpleDateFormat(const UnicodeString& pattern,
832 const DateFormatSymbols& formatData,
833 UErrorCode& status);
834
839 SimpleDateFormat(const SimpleDateFormat&);
840
845 SimpleDateFormat& operator=(const SimpleDateFormat&);
846
851 virtual ~SimpleDateFormat();
852
859 virtual Format* clone(void) const;
860
868 virtual UBool operator==(const Format& other) const;
869
870
871 using DateFormat::format;
872
889 virtual UnicodeString& format( Calendar& cal,
890 UnicodeString& appendTo,
891 FieldPosition& pos) const;
892
911 virtual UnicodeString& format( Calendar& cal,
912 UnicodeString& appendTo,
913 FieldPositionIterator* posIter,
914 UErrorCode& status) const;
915
916 using DateFormat::parse;
917
944 virtual void parse( const UnicodeString& text,
945 Calendar& cal,
946 ParsePosition& pos) const;
947
948
965 virtual void set2DigitYearStart(UDate d, UErrorCode& status);
966
982 UDate get2DigitYearStart(UErrorCode& status) const;
983
990 virtual UnicodeString& toPattern(UnicodeString& result) const;
991
1008 virtual UnicodeString& toLocalizedPattern(UnicodeString& result,
1009 UErrorCode& status) const;
1010
1019 virtual void applyPattern(const UnicodeString& pattern);
1020
1031 virtual void applyLocalizedPattern(const UnicodeString& pattern,
1032 UErrorCode& status);
1033
1042 virtual const DateFormatSymbols* getDateFormatSymbols(void) const;
1043
1050 virtual void adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols);
1051
1057 virtual void setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols);
1058
1070 static UClassID U_EXPORT2 getStaticClassID(void);
1071
1083 virtual UClassID getDynamicClassID(void) const;
1084
1094 virtual void adoptCalendar(Calendar* calendarToAdopt);
1095
1096 /* Cannot use #ifndef U_HIDE_INTERNAL_API for the following methods since they are virtual */
1104 virtual void adoptTimeZoneFormat(TimeZoneFormat* timeZoneFormatToAdopt);
1105
1111 virtual void setTimeZoneFormat(const TimeZoneFormat& newTimeZoneFormat);
1112
1118 virtual const TimeZoneFormat* getTimeZoneFormat(void) const;
1119
1120 /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */
1131 virtual void setContext(UDisplayContext value, UErrorCode& status);
1132
1133 #ifndef U_HIDE_DRAFT_API
1134
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 #endif /* U_HIDE_DRAFT_API */
1167
1168 #ifndef U_HIDE_INTERNAL_API
1169
1179 UBool isFieldUnitIgnored(UCalendarDateFields field) const;
1180
1181
1193 static UBool isFieldUnitIgnored(const UnicodeString& pattern,
1194 UCalendarDateFields field);
1195
1204 const Locale& getSmpFmtLocale(void) const;
1205 #endif /* U_HIDE_INTERNAL_API */
1206
1207 private:
1208 friend class DateFormat;
1209
1210 void initializeDefaultCentury(void);
1211
1212 void initializeBooleanAttributes(void);
1213
1214 SimpleDateFormat(); // default constructor not implemented
1215
1224 SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
1225
1234 SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
1235
1239 UnicodeString& _format(Calendar& cal, UnicodeString& appendTo, FieldPositionHandler& handler, UErrorCode& status) const;
1240
1257 void subFormat(UnicodeString &appendTo,
1258 UChar ch,
1259 int32_t count,
1260 UDisplayContext capitalizationContext,
1261 int32_t fieldNum,
1262 FieldPositionHandler& handler,
1263 Calendar& cal,
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
1316 void initializeSymbols(const Locale& locale, Calendar* calendar, 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
1384 static UBool matchLiterals(const UnicodeString &pattern, int32_t &patternOffset,
1385 const UnicodeString &text, int32_t &textOffset,
1386 UBool whitespaceLenient, UBool partialMatchLenient, UBool oldLeniency);
1387
1408 int32_t subParse(const UnicodeString& text, int32_t& start, UChar ch, int32_t count,
1409 UBool obeyCount, UBool allowNegative, UBool ambiguousYear[], int32_t& saveHebrewMonth, Calendar& cal,
1410 int32_t patLoc, MessageFormat * numericLeapMonthFormatter, UTimeZoneFormatTimeType *tzTimeType) const;
1411
1412 void parseInt(const UnicodeString& text,
1413 Formattable& number,
1414 ParsePosition& pos,
1415 UBool allowNegative,
1416 NumberFormat *fmt) const;
1417
1418 void parseInt(const UnicodeString& text,
1419 Formattable& number,
1420 int32_t maxDigits,
1421 ParsePosition& pos,
1422 UBool allowNegative,
1423 NumberFormat *fmt) const;
1424
1425 int32_t checkIntSuffix(const UnicodeString& text, int32_t start,
1426 int32_t patLoc, UBool isNegative) const;
1427
1440 static void translatePattern(const UnicodeString& originalPattern,
1441 UnicodeString& translatedPattern,
1442 const UnicodeString& from,
1443 const UnicodeString& to,
1444 UErrorCode& status);
1445
1453 void parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status);
1454
1464 int32_t compareSimpleAffix(const UnicodeString& affix,
1465 const UnicodeString& input,
1466 int32_t pos) const;
1467
1472 int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos) const;
1473
1478 int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const;
1479
1483 void initNumberFormatters(const Locale &locale,UErrorCode &status);
1484
1488 NumberFormat * getNumberFormatByIndex(UDateFormatField index) const;
1489
1493 void processOverrideString(const Locale &locale, const UnicodeString &str, int8_t type, UErrorCode &status);
1494
1498 static const UCalendarDateFields fgPatternIndexToCalendarField[];
1499
1503 static const UDateFormatField fgPatternIndexToDateFormatField[];
1504
1508 TimeZoneFormat *tzFormat() const;
1509
1516 static const int32_t fgCalendarFieldToLevel[];
1517 static const int32_t fgPatternCharToLevel[];
1518
1522 UnicodeString fPattern;
1523
1527 UnicodeString fDateOverride;
1528
1532 UnicodeString fTimeOverride;
1533
1534
1538 Locale fLocale;
1539
1544 DateFormatSymbols* fSymbols; // Owned
1545
1549 TimeZoneFormat* fTimeZoneFormat;
1550
1559 UDate fDefaultCenturyStart;
1560
1564 /*transient*/ int32_t fDefaultCenturyStartYear;
1565
1566 typedef struct NSOverride {
1567 NumberFormat *nf;
1568 int32_t hash;
1569 NSOverride *next;
1570 } NSOverride;
1571
1572 NumberFormat **fNumberFormatters;
1573
1574 NSOverride *fOverrideList;
1575
1576 UBool fHaveDefaultCentury;
1577
1578 BreakIterator* fCapitalizationBrkIter;
1579 };
1580
1581 inline UDate
1582 SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const
1583 {
1584 return fDefaultCenturyStart;
1585 }
1586
1587 U_NAMESPACE_END
1588
1589 #endif /* #if !UCONFIG_NO_FORMATTING */
1590
1591 #endif // _SMPDTFMT
1592 //eof