ICU 55.1 55.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-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
1134 #ifndef U_HIDE_DRAFT_API
1135
1142 void adoptNumberFormat(NumberFormat *formatToAdopt);
1143
1159 void adoptNumberFormat(const UnicodeString& fields, NumberFormat *formatToAdopt, UErrorCode &status);
1160
1166 const NumberFormat * getNumberFormatForField(UChar field) const;
1167 #endif /* U_HIDE_DRAFT_API */
1168
1169 #ifndef U_HIDE_INTERNAL_API
1170
1180 UBool isFieldUnitIgnored(UCalendarDateFields field) const;
1181
1182
1194 static UBool isFieldUnitIgnored(const UnicodeString& pattern,
1195 UCalendarDateFields field);
1196
1205 const Locale& getSmpFmtLocale(void) const;
1206 #endif /* U_HIDE_INTERNAL_API */
1207
1208 private:
1209 friend class DateFormat;
1210
1211 void initializeDefaultCentury(void);
1212
1213 void initializeBooleanAttributes(void);
1214
1215 SimpleDateFormat(); // default constructor not implemented
1216
1225 SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
1226
1235 SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
1236
1240 UnicodeString& _format(Calendar& cal, UnicodeString& appendTo, FieldPositionHandler& handler, UErrorCode& status) const;
1241
1258 void subFormat(UnicodeString &appendTo,
1259 UChar ch,
1260 int32_t count,
1261 UDisplayContext capitalizationContext,
1262 int32_t fieldNum,
1263 FieldPositionHandler& handler,
1264 Calendar& cal,
1265 SimpleDateFormatMutableNFs &mutableNFs,
1266 UErrorCode& status) const; // in case of illegal argument
1267
1281 void zeroPaddingNumber(NumberFormat *currentNumberFormat,
1282 UnicodeString &appendTo,
1283 int32_t value,
1284 int32_t minDigits,
1285 int32_t maxDigits) const;
1286
1291 static UBool isNumeric(UChar formatChar, int32_t count);
1292
1296 static UBool isAtNumericField(const UnicodeString &pattern, int32_t patternOffset);
1297
1301 static UBool isAfterNonNumericField(const UnicodeString &pattern, int32_t patternOffset);
1302
1310 Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status);
1311
1321 void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
1322
1329 void initialize(const Locale& locale, UErrorCode& status);
1330
1344 int32_t matchString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1345 const UnicodeString* stringArray, int32_t stringArrayCount,
1346 const UnicodeString* monthPattern, Calendar& cal) const;
1347
1360 int32_t matchQuarterString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1361 const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const;
1362
1378 static UBool matchLiterals(const UnicodeString &pattern, int32_t &patternOffset,
1379 const UnicodeString &text, int32_t &textOffset,
1380 UBool whitespaceLenient, UBool partialMatchLenient, UBool oldLeniency);
1381
1402 int32_t subParse(const UnicodeString& text, int32_t& start, UChar ch, int32_t count,
1403 UBool obeyCount, UBool allowNegative, UBool ambiguousYear[], int32_t& saveHebrewMonth, Calendar& cal,
1404 int32_t patLoc, MessageFormat * numericLeapMonthFormatter, UTimeZoneFormatTimeType *tzTimeType, SimpleDateFormatMutableNFs &mutableNFs) const;
1405
1406 void parseInt(const UnicodeString& text,
1407 Formattable& number,
1408 ParsePosition& pos,
1409 UBool allowNegative,
1410 NumberFormat *fmt) const;
1411
1412 void parseInt(const UnicodeString& text,
1413 Formattable& number,
1414 int32_t maxDigits,
1415 ParsePosition& pos,
1416 UBool allowNegative,
1417 NumberFormat *fmt) const;
1418
1419 int32_t checkIntSuffix(const UnicodeString& text, int32_t start,
1420 int32_t patLoc, UBool isNegative) const;
1421
1434 static void translatePattern(const UnicodeString& originalPattern,
1435 UnicodeString& translatedPattern,
1436 const UnicodeString& from,
1437 const UnicodeString& to,
1438 UErrorCode& status);
1439
1447 void parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status);
1448
1458 int32_t compareSimpleAffix(const UnicodeString& affix,
1459 const UnicodeString& input,
1460 int32_t pos) const;
1461
1466 int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos) const;
1467
1472 int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const;
1473
1477 void initNumberFormatters(const Locale &locale,UErrorCode &status);
1478
1482 void processOverrideString(const Locale &locale, const UnicodeString &str, int8_t type, UErrorCode &status);
1483
1487 static const UCalendarDateFields fgPatternIndexToCalendarField[];
1488
1492 static const UDateFormatField fgPatternIndexToDateFormatField[];
1493
1497 TimeZoneFormat *tzFormat() const;
1498
1499 const NumberFormat* getNumberFormatByIndex(UDateFormatField index) const;
1500
1507 static const int32_t fgCalendarFieldToLevel[];
1508
1512 static int32_t getLevelFromChar(UChar ch);
1513
1517 static UBool isSyntaxChar(UChar ch);
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 struct NSOverride : public UMemory {
1567 const SharedNumberFormat *snf;
1568 int32_t hash;
1569 NSOverride *next;
1570 void free();
1571 NSOverride() : snf(NULL), hash(0), next(NULL) {
1572 }
1573 ~NSOverride();
1574 };
1575
1580 const SharedNumberFormat **fSharedNumberFormatters;
1581
1582 UBool fHaveDefaultCentury;
1583
1584 BreakIterator* fCapitalizationBrkIter;
1585 };
1586
1587 inline UDate
1588 SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const
1589 {
1590 return fDefaultCenturyStart;
1591 }
1592
1593 U_NAMESPACE_END
1594
1595 #endif /* #if !UCONFIG_NO_FORMATTING */
1596
1597 #endif // _SMPDTFMT
1598 //eof