"Fossies" - the Fresh Open Source Software Archive

Member "smpdtfmt_8h_source.html" (3 Oct 2019, 77024 Bytes) of package /linux/misc/icu4c-65_1-docs.zip:


Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the project site itself.

ICU 65.1  65.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 
31 #if U_SHOW_CPLUSPLUS_API
32 
38 #if !UCONFIG_NO_FORMATTING
39 
40 #include "unicode/datefmt.h"
42 #include "unicode/tzfmt.h" /* for UTimeZoneFormatTimeType */
43 #include "unicode/brkiter.h"
44 
45 U_NAMESPACE_BEGIN
46 
47 class DateFormatSymbols;
48 class DateFormat;
49 class MessageFormat;
50 class FieldPositionHandler;
51 class TimeZoneFormat;
52 class SharedNumberFormat;
53 class SimpleDateFormatMutableNFs;
54 class DateIntervalFormat;
55 
56 namespace number {
57 class LocalizedNumberFormatter;
58 }
59 
727 public:
737  SimpleDateFormat(UErrorCode& status);
738 
750  SimpleDateFormat(const UnicodeString& pattern,
751  UErrorCode& status);
752 
774  SimpleDateFormat(const UnicodeString& pattern,
775  const UnicodeString& override,
776  UErrorCode& status);
777 
790  SimpleDateFormat(const UnicodeString& pattern,
791  const Locale& locale,
792  UErrorCode& status);
793 
815  SimpleDateFormat(const UnicodeString& pattern,
816  const UnicodeString& override,
817  const Locale& locale,
818  UErrorCode& status);
819 
829  SimpleDateFormat(const UnicodeString& pattern,
830  DateFormatSymbols* formatDataToAdopt,
831  UErrorCode& status);
832 
842  SimpleDateFormat(const UnicodeString& pattern,
843  const DateFormatSymbols& formatData,
844  UErrorCode& status);
845 
851 
856  SimpleDateFormat& operator=(const SimpleDateFormat&);
857 
862  virtual ~SimpleDateFormat();
863 
870  virtual SimpleDateFormat* clone() const;
871 
879  virtual UBool operator==(const Format& other) const;
880 
881 
882  using DateFormat::format;
883 
900  virtual UnicodeString& format( Calendar& cal,
901  UnicodeString& appendTo,
902  FieldPosition& pos) const;
903 
922  virtual UnicodeString& format( Calendar& cal,
923  UnicodeString& appendTo,
924  FieldPositionIterator* posIter,
925  UErrorCode& status) const;
926 
927  using DateFormat::parse;
928 
955  virtual void parse( const UnicodeString& text,
956  Calendar& cal,
957  ParsePosition& pos) const;
958 
959 
976  virtual void set2DigitYearStart(UDate d, UErrorCode& status);
977 
993  UDate get2DigitYearStart(UErrorCode& status) const;
994 
1001  virtual UnicodeString& toPattern(UnicodeString& result) const;
1002 
1025  virtual UnicodeString& toLocalizedPattern(UnicodeString& result,
1026  UErrorCode& status) const;
1027 
1036  virtual void applyPattern(const UnicodeString& pattern);
1037 
1048  virtual void applyLocalizedPattern(const UnicodeString& pattern,
1049  UErrorCode& status);
1050 
1059  virtual const DateFormatSymbols* getDateFormatSymbols(void) const;
1060 
1067  virtual void adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols);
1068 
1074  virtual void setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols);
1075 
1087  static UClassID U_EXPORT2 getStaticClassID(void);
1088 
1100  virtual UClassID getDynamicClassID(void) const;
1101 
1111  virtual void adoptCalendar(Calendar* calendarToAdopt);
1112 
1113  /* Cannot use #ifndef U_HIDE_INTERNAL_API for the following methods since they are virtual */
1121  virtual void adoptTimeZoneFormat(TimeZoneFormat* timeZoneFormatToAdopt);
1122 
1128  virtual void setTimeZoneFormat(const TimeZoneFormat& newTimeZoneFormat);
1129 
1135  virtual const TimeZoneFormat* getTimeZoneFormat(void) const;
1136 
1147  virtual void setContext(UDisplayContext value, UErrorCode& status);
1148 
1156  void adoptNumberFormat(NumberFormat *formatToAdopt);
1157 
1173  void adoptNumberFormat(const UnicodeString& fields, NumberFormat *formatToAdopt, UErrorCode &status);
1174 
1180  const NumberFormat * getNumberFormatForField(char16_t field) const;
1181 
1182 #ifndef U_HIDE_INTERNAL_API
1183 
1193  UBool isFieldUnitIgnored(UCalendarDateFields field) const;
1194 
1195 
1207  static UBool isFieldUnitIgnored(const UnicodeString& pattern,
1208  UCalendarDateFields field);
1209 
1218  const Locale& getSmpFmtLocale(void) const;
1219 #endif /* U_HIDE_INTERNAL_API */
1220 
1221 private:
1222  friend class DateFormat;
1223  friend class DateIntervalFormat;
1224 
1225  void initializeDefaultCentury(void);
1226 
1227  void initializeBooleanAttributes(void);
1228 
1229  SimpleDateFormat(); // default constructor not implemented
1230 
1239  SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
1240 
1249  SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
1250 
1254  UnicodeString& _format(Calendar& cal, UnicodeString& appendTo, FieldPositionHandler& handler, UErrorCode& status) const;
1255 
1272  void subFormat(UnicodeString &appendTo,
1273  char16_t ch,
1274  int32_t count,
1275  UDisplayContext capitalizationContext,
1276  int32_t fieldNum,
1277  FieldPositionHandler& handler,
1278  Calendar& cal,
1279  UErrorCode& status) const; // in case of illegal argument
1280 
1294  void zeroPaddingNumber(const NumberFormat *currentNumberFormat,
1295  UnicodeString &appendTo,
1296  int32_t value,
1297  int32_t minDigits,
1298  int32_t maxDigits) const;
1299 
1304  static UBool isNumeric(char16_t formatChar, int32_t count);
1305 
1309  static UBool isAtNumericField(const UnicodeString &pattern, int32_t patternOffset);
1310 
1314  static UBool isAfterNonNumericField(const UnicodeString &pattern, int32_t patternOffset);
1315 
1323  Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status);
1324 
1334  void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
1335 
1342  void initialize(const Locale& locale, UErrorCode& status);
1343 
1357  int32_t matchString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1358  const UnicodeString* stringArray, int32_t stringArrayCount,
1359  const UnicodeString* monthPattern, Calendar& cal) const;
1360 
1373  int32_t matchQuarterString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
1374  const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const;
1375 
1379  int32_t matchDayPeriodStrings(const UnicodeString& text, int32_t start,
1380  const UnicodeString* stringArray, int32_t stringArrayCount,
1381  int32_t &dayPeriod) const;
1382 
1398  static UBool matchLiterals(const UnicodeString &pattern, int32_t &patternOffset,
1399  const UnicodeString &text, int32_t &textOffset,
1400  UBool whitespaceLenient, UBool partialMatchLenient, UBool oldLeniency);
1401 
1422  int32_t subParse(const UnicodeString& text, int32_t& start, char16_t ch, int32_t count,
1423  UBool obeyCount, UBool allowNegative, UBool ambiguousYear[], int32_t& saveHebrewMonth, Calendar& cal,
1424  int32_t patLoc, MessageFormat * numericLeapMonthFormatter, UTimeZoneFormatTimeType *tzTimeType,
1425  int32_t *dayPeriod=NULL) const;
1426 
1427  void parseInt(const UnicodeString& text,
1428  Formattable& number,
1429  ParsePosition& pos,
1430  UBool allowNegative,
1431  const NumberFormat *fmt) const;
1432 
1433  void parseInt(const UnicodeString& text,
1434  Formattable& number,
1435  int32_t maxDigits,
1436  ParsePosition& pos,
1437  UBool allowNegative,
1438  const NumberFormat *fmt) const;
1439 
1440  int32_t checkIntSuffix(const UnicodeString& text, int32_t start,
1441  int32_t patLoc, UBool isNegative) const;
1442 
1451  int32_t countDigits(const UnicodeString& text, int32_t start, int32_t end) const;
1452 
1465  static void translatePattern(const UnicodeString& originalPattern,
1466  UnicodeString& translatedPattern,
1467  const UnicodeString& from,
1468  const UnicodeString& to,
1469  UErrorCode& status);
1470 
1478  void parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status);
1479 
1489  int32_t compareSimpleAffix(const UnicodeString& affix,
1490  const UnicodeString& input,
1491  int32_t pos) const;
1492 
1497  int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos) const;
1498 
1503  int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const;
1504 
1508  void initFastNumberFormatters(UErrorCode& status);
1509 
1513  void freeFastNumberFormatters();
1514 
1518  void initNumberFormatters(const Locale &locale,UErrorCode &status);
1519 
1523  void processOverrideString(const Locale &locale, const UnicodeString &str, int8_t type, UErrorCode &status);
1524 
1528  static const UCalendarDateFields fgPatternIndexToCalendarField[];
1529 
1533  static const UDateFormatField fgPatternIndexToDateFormatField[];
1534 
1538  TimeZoneFormat *tzFormat(UErrorCode &status) const;
1539 
1540  const NumberFormat* getNumberFormatByIndex(UDateFormatField index) const;
1541 
1548  static const int32_t fgCalendarFieldToLevel[];
1549 
1553  static int32_t getLevelFromChar(char16_t ch);
1554 
1558  static UBool isSyntaxChar(char16_t ch);
1559 
1563  UnicodeString fPattern;
1564 
1568  UnicodeString fDateOverride;
1569 
1573  UnicodeString fTimeOverride;
1574 
1575 
1579  Locale fLocale;
1580 
1585  DateFormatSymbols* fSymbols; // Owned
1586 
1590  TimeZoneFormat* fTimeZoneFormat;
1591 
1600  UDate fDefaultCenturyStart;
1601 
1602  UBool fHasMinute;
1603  UBool fHasSecond;
1604  UBool fHasHanYearChar; // pattern contains the Han year character \u5E74
1605 
1609  void parsePattern();
1610 
1614  /*transient*/ int32_t fDefaultCenturyStartYear;
1615 
1616  struct NSOverride : public UMemory {
1617  const SharedNumberFormat *snf;
1618  int32_t hash;
1619  NSOverride *next;
1620  void free();
1621  NSOverride() : snf(NULL), hash(0), next(NULL) {
1622  }
1623  ~NSOverride();
1624  };
1625 
1630  const SharedNumberFormat **fSharedNumberFormatters;
1631 
1632  enum NumberFormatterKey {
1633  SMPDTFMT_NF_1x10,
1634  SMPDTFMT_NF_2x10,
1635  SMPDTFMT_NF_3x10,
1636  SMPDTFMT_NF_4x10,
1637  SMPDTFMT_NF_2x2,
1638  SMPDTFMT_NF_COUNT
1639  };
1640 
1644  const number::LocalizedNumberFormatter* fFastNumberFormatters[SMPDTFMT_NF_COUNT] = {};
1645 
1646  UBool fHaveDefaultCentury;
1647 
1648  const BreakIterator* fCapitalizationBrkIter;
1649 };
1650 
1651 inline UDate
1652 SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const
1653 {
1654  return fDefaultCenturyStart;
1655 }
1656 
1657 U_NAMESPACE_END
1658 
1659 #endif /* #if !UCONFIG_NO_FORMATTING */
1660 
1661 #endif /* U_SHOW_CPLUSPLUS_API */
1662 
1663 #endif // _SMPDTFMT
1664 //eof
C++ API: Break Iterator.
C++ API: TimeZoneFormat.
Base class for all formats.
Definition: format.h:98
TimeZoneFormat supports time zone display name formatting and parsing.
Definition: tzfmt.h:274
UCalendarDateFields
Possible fields in a UCalendar.
Definition: ucal.h:199
UTimeZoneFormatTimeType
Constants for time types used by TimeZoneFormat APIs for receiving time type (standard time...
Definition: tzfmt.h:206
DateIntervalFormat is a class for formatting and parsing date intervals in a language-independent man...
Definition: dtitvfmt.h:300
DateFormatSymbols is a public class for encapsulating localizable date-time formatting data – includ...
Definition: dtfmtsym.h:84
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition: calendar.h:187
UDisplayContext
Display context settings.
double UDate
Date and Time data type.
Definition: utypes.h:203
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:133
C API: Display context types (enum values)
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:58
The BreakIterator class implements methods for finding the location of boundaries in text...
Definition: brkiter.h:106
#define NULL
Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.
Definition: utypes.h:188
EStyle
Constants for various style patterns.
Definition: datefmt.h:166
A NumberFormatter that has a locale associated with it; this means .format() methods are available...
UDateFormatField
FieldPosition and UFieldPosition selectors for format fields defined by DateFormat and UDateFormat...
Definition: udat.h:511
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
SimpleDateFormat is a concrete class for formatting and parsing dates in a language-independent manne...
Definition: smpdtfmt.h:726
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:110
C++ API: Abstract class for converting dates.
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:52
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition: datefmt.h:156
Basic definitions for ICU, for both C and C++ APIs.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:294
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:64
UMemory is the common ICU base class.
Definition: uobject.h:115
int8_t UBool
The ICU boolean type.
Definition: umachine.h:261
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195