smpdtfmt.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
* Copyright (C) 1997-2016, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*
* File SMPDTFMT.H
*
* Modification History:
*
* Date Name Description
* 02/19/97 aliu Converted from java.
* 07/09/97 helena Make ParsePosition into a class.
* 07/21/98 stephen Added GMT_PLUS, GMT_MINUS
* Changed setTwoDigitStartDate to set2DigitYearStart
* Changed getTwoDigitStartDate to get2DigitYearStart
* Removed subParseLong
* Removed getZoneIndex (added in DateFormatSymbols)
* 06/14/99 stephen Removed fgTimeZoneDataSuffix
* 10/14/99 aliu Updated class doc to describe 2-digit year parsing
* {j28 4182066}.
*******************************************************************************
*/
#ifndef SMPDTFMT_H
#define SMPDTFMT_H
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_FORMATTING
#include "unicode/datefmt.h"
#include "unicode/udisplaycontext.h"
#include "unicode/tzfmt.h" /* for UTimeZoneFormatTimeType */
#include "unicode/brkiter.h"
U_NAMESPACE_BEGIN
class DateFormatSymbols;
class DateFormat;
class MessageFormat;
class FieldPositionHandler;
class TimeZoneFormat;
class SharedNumberFormat;
class SimpleDateFormatMutableNFs;
class DateIntervalFormat;
namespace number {
class LocalizedNumberFormatter;
class SimpleNumberFormatter;
}
class U_I18N_API SimpleDateFormat: public DateFormat {
public:
SimpleDateFormat(UErrorCode& status);
SimpleDateFormat(const UnicodeString& pattern,
UErrorCode& status);
SimpleDateFormat(const UnicodeString& pattern,
const UnicodeString& override,
UErrorCode& status);
SimpleDateFormat(const UnicodeString& pattern,
const Locale& locale,
UErrorCode& status);
SimpleDateFormat(const UnicodeString& pattern,
const UnicodeString& override,
const Locale& locale,
UErrorCode& status);
SimpleDateFormat(const UnicodeString& pattern,
DateFormatSymbols* formatDataToAdopt,
UErrorCode& status);
SimpleDateFormat(const UnicodeString& pattern,
const DateFormatSymbols& formatData,
UErrorCode& status);
SimpleDateFormat(const SimpleDateFormat&);
SimpleDateFormat& operator=(const SimpleDateFormat&);
virtual ~SimpleDateFormat();
virtual SimpleDateFormat* clone() const override;
virtual bool operator==(const Format& other) const override;
using DateFormat::format;
virtual UnicodeString& format( Calendar& cal,
UnicodeString& appendTo,
FieldPosition& pos) const override;
virtual UnicodeString& format( Calendar& cal,
UnicodeString& appendTo,
FieldPositionIterator* posIter,
UErrorCode& status) const override;
using DateFormat::parse;
virtual void parse( const UnicodeString& text,
Calendar& cal,
ParsePosition& pos) const override;
virtual void set2DigitYearStart(UDate d, UErrorCode& status);
UDate get2DigitYearStart(UErrorCode& status) const;
virtual UnicodeString& toPattern(UnicodeString& result) const;
virtual UnicodeString& toLocalizedPattern(UnicodeString& result,
UErrorCode& status) const;
virtual void applyPattern(const UnicodeString& pattern);
virtual void applyLocalizedPattern(const UnicodeString& pattern,
UErrorCode& status);
virtual const DateFormatSymbols* getDateFormatSymbols() const;
virtual void adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols);
virtual void setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols);
static UClassID U_EXPORT2 getStaticClassID();
virtual UClassID getDynamicClassID() const override;
virtual void adoptCalendar(Calendar* calendarToAdopt) override;
/* Cannot use #ifndef U_HIDE_INTERNAL_API for the following methods since they are virtual */
virtual void adoptTimeZoneFormat(TimeZoneFormat* timeZoneFormatToAdopt);
virtual void setTimeZoneFormat(const TimeZoneFormat& newTimeZoneFormat);
virtual const TimeZoneFormat* getTimeZoneFormat() const;
virtual void setContext(UDisplayContext value, UErrorCode& status) override;
void adoptNumberFormat(NumberFormat *formatToAdopt) override;
void adoptNumberFormat(const UnicodeString& fields, NumberFormat *formatToAdopt, UErrorCode &status);
const NumberFormat * getNumberFormatForField(char16_t field) const;
#ifndef U_HIDE_INTERNAL_API
UBool isFieldUnitIgnored(UCalendarDateFields field) const;
static UBool isFieldUnitIgnored(const UnicodeString& pattern,
UCalendarDateFields field);
const Locale& getSmpFmtLocale() const;
#endif /* U_HIDE_INTERNAL_API */
private:
friend class DateFormat;
friend class DateIntervalFormat;
void initializeDefaultCentury();
void initializeBooleanAttributes();
SimpleDateFormat() = delete; // default constructor not implemented
SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
UnicodeString& _format(Calendar& cal, UnicodeString& appendTo, FieldPositionHandler& handler, UErrorCode& status) const;
void subFormat(UnicodeString &appendTo,
char16_t ch,
int32_t count,
UDisplayContext capitalizationContext,
int32_t fieldNum,
char16_t fieldToOutput,
FieldPositionHandler& handler,
Calendar& cal,
UErrorCode& status) const; // in case of illegal argument
void zeroPaddingNumber(const NumberFormat *currentNumberFormat,
UnicodeString &appendTo,
int32_t value,
int32_t minDigits,
int32_t maxDigits) const;
static UBool isNumeric(char16_t formatChar, int32_t count);
static UBool isAtNumericField(const UnicodeString &pattern, int32_t patternOffset);
static UBool isAfterNonNumericField(const UnicodeString &pattern, int32_t patternOffset);
Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status);
void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
void initialize(const Locale& locale, UErrorCode& status);
int32_t matchString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
const UnicodeString* stringArray, int32_t stringArrayCount,
const UnicodeString* monthPattern, Calendar& cal) const;
int32_t matchAlphaMonthStrings(const UnicodeString& text, int32_t start,
const UnicodeString* wideStringArray, const UnicodeString* shortStringArray,
int32_t stringArrayCount, Calendar& cal) const;
int32_t matchQuarterString(const UnicodeString& text, int32_t start, UCalendarDateFields field,
const UnicodeString* stringArray, int32_t stringArrayCount, Calendar& cal) const;
int32_t matchDayPeriodStrings(const UnicodeString& text, int32_t start,
const UnicodeString* stringArray, int32_t stringArrayCount,
int32_t &dayPeriod) const;
static UBool matchLiterals(const UnicodeString &pattern, int32_t &patternOffset,
const UnicodeString &text, int32_t &textOffset,
UBool whitespaceLenient, UBool partialMatchLenient, UBool oldLeniency);
int32_t subParse(const UnicodeString& text, int32_t& start, char16_t ch, int32_t count,
UBool obeyCount, UBool allowNegative, UBool ambiguousYear[], int32_t& saveHebrewMonth, Calendar& cal,
int32_t patLoc, MessageFormat * numericLeapMonthFormatter, UTimeZoneFormatTimeType *tzTimeType,
int32_t *dayPeriod=nullptr) const;
void parseInt(const UnicodeString& text,
Formattable& number,
ParsePosition& pos,
UBool allowNegative,
const NumberFormat *fmt) const;
void parseInt(const UnicodeString& text,
Formattable& number,
int32_t maxDigits,
ParsePosition& pos,
UBool allowNegative,
const NumberFormat *fmt) const;
int32_t checkIntSuffix(const UnicodeString& text, int32_t start,
int32_t patLoc, UBool isNegative) const;
int32_t countDigits(const UnicodeString& text, int32_t start, int32_t end) const;
static void translatePattern(const UnicodeString& originalPattern,
UnicodeString& translatedPattern,
const UnicodeString& from,
const UnicodeString& to,
UErrorCode& status);
void parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status);
int32_t compareSimpleAffix(const UnicodeString& affix,
const UnicodeString& input,
int32_t pos) const;
int32_t skipPatternWhiteSpace(const UnicodeString& text, int32_t pos) const;
int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const;
void initSimpleNumberFormatter(UErrorCode &status);
void initNumberFormatters(const Locale &locale,UErrorCode &status);
void processOverrideString(const Locale &locale, const UnicodeString &str, int8_t type, UErrorCode &status);
static const UCalendarDateFields fgPatternIndexToCalendarField[];
static const UDateFormatField fgPatternIndexToDateFormatField[];
TimeZoneFormat *tzFormat(UErrorCode &status) const;
const NumberFormat* getNumberFormatByIndex(UDateFormatField index) const;
static const int32_t fgCalendarFieldToLevel[];
static int32_t getLevelFromChar(char16_t ch);
static UBool isSyntaxChar(char16_t ch);
UnicodeString fPattern;
UnicodeString fDateOverride;
UnicodeString fTimeOverride;
Locale fLocale;
DateFormatSymbols* fSymbols = nullptr; // Owned
TimeZoneFormat* fTimeZoneFormat = nullptr;
UDate fDefaultCenturyStart;
UBool fHasMinute;
UBool fHasSecond;
UBool fHasHanYearChar; // pattern contains the Han year character \u5E74
void parsePattern();
/*transient*/ int32_t fDefaultCenturyStartYear;
struct NSOverride : public UMemory {
const SharedNumberFormat *snf;
int32_t hash;
NSOverride *next;
void free();
NSOverride() : snf(nullptr), hash(0), next(nullptr) {
}
~NSOverride();
};
const SharedNumberFormat **fSharedNumberFormatters = nullptr;
const number::SimpleNumberFormatter* fSimpleNumberFormatter = nullptr;
UBool fHaveDefaultCentury;
const BreakIterator* fCapitalizationBrkIter = nullptr;
};
inline UDate
SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const
{
return fDefaultCenturyStart;
}
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // _SMPDTFMT
//eof
brkiter.h
C++ API: Break Iterator.
icu::Calendar
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition: calendar.h:189
icu::DateFormatSymbols
DateFormatSymbols is a public class for encapsulating localizable date-time formatting data – includi...
Definition: dtfmtsym.h:84
icu::DateFormat
DateFormat is an abstract class for a family of classes that convert dates and times from their inter...
Definition: datefmt.h:156
icu::DateFormat::parse
virtual UDate parse(const UnicodeString &text, UErrorCode &status) const
Parse a date/time string.
icu::DateFormat::EStyle
EStyle
Constants for various style patterns.
Definition: datefmt.h:167
icu::DateFormat::format
UnicodeString & format(const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
Formats an object to produce a string.
icu::DateIntervalFormat
DateIntervalFormat is a class for formatting and parsing date intervals in a language-independent man...
Definition: dtitvfmt.h:300
icu::FieldPositionIterator
FieldPositionIterator returns the field ids and their start/limit positions generated by a call to Fo...
Definition: fpositer.h:58
icu::FieldPosition
FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted out...
Definition: fieldpos.h:110
icu::Format
Base class for all formats.
Definition: format.h:98
icu::Formattable
Formattable objects can be passed to the Format class or its subclasses for formatting.
Definition: fmtable.h:63
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::MessageFormat
Definition: msgfmt.h:345
icu::NumberFormat
Definition: numfmt.h:175
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:52
icu::SimpleDateFormat
SimpleDateFormat is a concrete class for formatting and parsing dates in a language-independent manne...
Definition: smpdtfmt.h:385
icu::SimpleDateFormat::format
virtual UnicodeString & format(Calendar &cal, UnicodeString &appendTo, FieldPosition &pos) const override
Format a date or time, which is the standard millis since 24:00 GMT, Jan 1, 1970.
icu::SimpleDateFormat::operator==
virtual bool operator==(const Format &other) const override
Return true if the given Format objects are semantically equal.
icu::SimpleDateFormat::parse
virtual void parse(const UnicodeString &text, Calendar &cal, ParsePosition &pos) const override
Parse a date/time string beginning at the given parse position.
icu::SimpleDateFormat::getTimeZoneFormat
virtual const TimeZoneFormat * getTimeZoneFormat() const
Gets the time zone format object associated with this date/time formatter.
icu::SimpleDateFormat::SimpleDateFormat
SimpleDateFormat(const UnicodeString &pattern, const UnicodeString &override, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern, numbering system override, and the default loca...
icu::SimpleDateFormat::applyPattern
virtual void applyPattern(const UnicodeString &pattern)
Apply the given unlocalized pattern string to this date format.
icu::SimpleDateFormat::SimpleDateFormat
SimpleDateFormat(const SimpleDateFormat &)
Copy constructor.
icu::SimpleDateFormat::adoptDateFormatSymbols
virtual void adoptDateFormatSymbols(DateFormatSymbols *newFormatSymbols)
Set the date/time formatting symbols.
icu::SimpleDateFormat::SimpleDateFormat
SimpleDateFormat(const UnicodeString &pattern, DateFormatSymbols *formatDataToAdopt, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale-specific symbol data.
icu::SimpleDateFormat::setDateFormatSymbols
virtual void setDateFormatSymbols(const DateFormatSymbols &newFormatSymbols)
Set the date/time formatting data.
icu::SimpleDateFormat::toPattern
virtual UnicodeString & toPattern(UnicodeString &result) const
Return a pattern string describing this date format.
icu::SimpleDateFormat::SimpleDateFormat
SimpleDateFormat(const UnicodeString &pattern, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and the default locale.
icu::SimpleDateFormat::getDynamicClassID
virtual UClassID getDynamicClassID() const override
Returns a unique class ID POLYMORPHICALLY.
icu::SimpleDateFormat::toLocalizedPattern
virtual UnicodeString & toLocalizedPattern(UnicodeString &result, UErrorCode &status) const
Return a localized pattern string describing this date format.
icu::SimpleDateFormat::getNumberFormatForField
const NumberFormat * getNumberFormatForField(char16_t field) const
Get the numbering system to be used for a particular field.
icu::SimpleDateFormat::setContext
virtual void setContext(UDisplayContext value, UErrorCode &status) override
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
icu::SimpleDateFormat::adoptNumberFormat
void adoptNumberFormat(NumberFormat *formatToAdopt) override
Overrides base class method and This method clears per field NumberFormat instances previously set by...
icu::SimpleDateFormat::isFieldUnitIgnored
UBool isFieldUnitIgnored(UCalendarDateFields field) const
This is for ICU internal use only.
icu::SimpleDateFormat::SimpleDateFormat
SimpleDateFormat(const UnicodeString &pattern, const DateFormatSymbols &formatData, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale-specific symbol data.
icu::SimpleDateFormat::setTimeZoneFormat
virtual void setTimeZoneFormat(const TimeZoneFormat &newTimeZoneFormat)
Sets the TimeZoneFormat to be used by this date/time formatter.
icu::SimpleDateFormat::operator=
SimpleDateFormat & operator=(const SimpleDateFormat &)
Assignment operator.
icu::SimpleDateFormat::adoptCalendar
virtual void adoptCalendar(Calendar *calendarToAdopt) override
Set the calendar to be used by this date format.
icu::SimpleDateFormat::SimpleDateFormat
SimpleDateFormat(UErrorCode &status)
Construct a SimpleDateFormat using the default pattern for the default locale.
icu::SimpleDateFormat::getStaticClassID
static UClassID getStaticClassID()
Return the class ID for this class.
icu::SimpleDateFormat::format
virtual UnicodeString & format(Calendar &cal, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const override
Format a date or time, which is the standard millis since 24:00 GMT, Jan 1, 1970.
icu::SimpleDateFormat::set2DigitYearStart
virtual void set2DigitYearStart(UDate d, UErrorCode &status)
Set the start UDate used to interpret two-digit year strings.
icu::SimpleDateFormat::~SimpleDateFormat
virtual ~SimpleDateFormat()
Destructor.
icu::SimpleDateFormat::adoptNumberFormat
void adoptNumberFormat(const UnicodeString &fields, NumberFormat *formatToAdopt, UErrorCode &status)
Allow the user to set the NumberFormat for several fields It can be a single field like: "y"(year) or...
icu::SimpleDateFormat::SimpleDateFormat
SimpleDateFormat(const UnicodeString &pattern, const UnicodeString &override, const Locale &locale, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern, numbering system override, and locale.
icu::SimpleDateFormat::SimpleDateFormat
SimpleDateFormat(const UnicodeString &pattern, const Locale &locale, UErrorCode &status)
Construct a SimpleDateFormat using the given pattern and locale.
icu::SimpleDateFormat::isFieldUnitIgnored
static UBool isFieldUnitIgnored(const UnicodeString &pattern, UCalendarDateFields field)
This is for ICU internal use only.
icu::SimpleDateFormat::adoptTimeZoneFormat
virtual void adoptTimeZoneFormat(TimeZoneFormat *timeZoneFormatToAdopt)
Sets the TimeZoneFormat to be used by this date/time formatter.
icu::SimpleDateFormat::getSmpFmtLocale
const Locale & getSmpFmtLocale() const
This is for ICU internal use only.
icu::SimpleDateFormat::applyLocalizedPattern
virtual void applyLocalizedPattern(const UnicodeString &pattern, UErrorCode &status)
Apply the given localized pattern string to this date format.
icu::SimpleDateFormat::getDateFormatSymbols
virtual const DateFormatSymbols * getDateFormatSymbols() const
Gets the date/time formatting symbols (this is an object carrying the various strings and other symbo...
icu::SimpleDateFormat::clone
virtual SimpleDateFormat * clone() const override
Clone this Format object polymorphically.
icu::TimeZoneFormat
TimeZoneFormat supports time zone display name formatting and parsing.
Definition: tzfmt.h:274
icu::TimeZone
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:133
icu::UMemory
UMemory is the common ICU base class.
Definition: uobject.h:115
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
datefmt.h
C++ API: Abstract class for converting dates.
tzfmt.h
C++ API: TimeZoneFormat.
UTimeZoneFormatTimeType
UTimeZoneFormatTimeType
Constants for time types used by TimeZoneFormat APIs for receiving time type (standard time,...
Definition: tzfmt.h:206
UCalendarDateFields
UCalendarDateFields
Possible fields in a UCalendar.
Definition: ucal.h:202
UDateFormatField
UDateFormatField
FieldPosition and UFieldPosition selectors for format fields defined by DateFormat and UDateFormat.
Definition: udat.h:515
udisplaycontext.h
C API: Display context types (enum values)
UDisplayContext
UDisplayContext
Display context settings.
Definition: udisplaycontext.h:64
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:430
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:316
UDate
double UDate
Date and Time data type.
Definition: utypes.h:218