+// © 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.
#include "unicode/tzfmt.h" /* for UTimeZoneFormatTimeType */
#include "unicode/brkiter.h"
+#if U_SHOW_CPLUSPLUS_API
U_NAMESPACE_BEGIN
class DateFormatSymbols;
class TimeZoneFormat;
class SharedNumberFormat;
class SimpleDateFormatMutableNFs;
+class DateIntervalFormat;
+
+namespace number {
+class LocalizedNumberFormatter;
+}
/**
*
* = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss a zzz", success );
* GregorianCalendar cal(success);
* UDate currentTime_1 = cal.getTime(success);
- * FieldPosition fp(0);
+ * FieldPosition fp(FieldPosition::DONT_CARE);
* UnicodeString dateString;
* formatter->format( currentTime_1, dateString, fp );
* cout << "result: " << dateString << endl;
* (Presumably, letters that would be more mnemonic in that locale's
* language.) This function would produce a pattern using those
* letters.
+ * <p>
+ * <b>Note:</b> This implementation depends on DateFormatSymbols::getLocalPatternChars()
+ * to get localized format pattern characters. ICU does not include
+ * localized pattern character data, therefore, unless user sets localized
+ * pattern characters manually, this method returns the same result as
+ * toPattern().
*
* @param result Receives the localized pattern.
* @param status Output param set to success/failure code on
* Overrides base class method and
* This method clears per field NumberFormat instances
* previously set by {@see adoptNumberFormat(const UnicodeString&, NumberFormat*, UErrorCode)}
- * @param adoptNF the NumbeferFormat used
+ * @param formatToAdopt the NumbeferFormat used
* @stable ICU 54
*/
void adoptNumberFormat(NumberFormat *formatToAdopt);
* Per field NumberFormat can also be cleared in {@see DateFormat::setNumberFormat(const NumberFormat& newNumberFormat)}
*
* @param fields the fields to override(like y)
- * @param adoptNF the NumbeferFormat used
+ * @param formatToAdopt the NumbeferFormat used
* @param status Receives a status code, which will be U_ZERO_ERROR
* if the operation succeeds.
* @stable ICU 54
* @param field The UDateFormatField to get
* @stable ICU 54
*/
- const NumberFormat * getNumberFormatForField(UChar field) const;
+ const NumberFormat * getNumberFormatForField(char16_t field) const;
#ifndef U_HIDE_INTERNAL_API
/**
* @internal ICU 4.0
*/
const Locale& getSmpFmtLocale(void) const;
+
+ /**
+ * Apple addition
+ * This is for ICU internal use only. Please do not use.
+ * Get the capitalization break iterator of this simple date formatter.
+ * Should be cloned before using it.
+ * It is used in udat.
+ *
+ * @return capitalization break iterator
+ * @internal
+ */
+ BreakIterator* getCapitalizationBrkIter(void) const;
#endif /* U_HIDE_INTERNAL_API */
private:
friend class DateFormat;
+ friend class DateIntervalFormat;
void initializeDefaultCentury(void);
* succeeds.
*/
void subFormat(UnicodeString &appendTo,
- UChar ch,
+ char16_t ch,
int32_t count,
UDisplayContext capitalizationContext,
int32_t fieldNum,
FieldPositionHandler& handler,
Calendar& cal,
- SimpleDateFormatMutableNFs &mutableNFs,
UErrorCode& status) const; // in case of illegal argument
/**
* @param minDigits Minimum number of digits the result should have
* @param maxDigits Maximum number of digits the result should have
*/
- void zeroPaddingNumber(NumberFormat *currentNumberFormat,
+ void zeroPaddingNumber(const NumberFormat *currentNumberFormat,
UnicodeString &appendTo,
int32_t value,
int32_t minDigits,
* Return true if the given format character, occuring count
* times, represents a numeric field.
*/
- static UBool isNumeric(UChar formatChar, int32_t count);
+ static UBool isNumeric(char16_t formatChar, int32_t count);
/**
* Returns TRUE if the patternOffset is at the start of a numeric field.
* @return the new start position if matching succeeded; a negative number
* indicating matching failure, otherwise.
*/
- int32_t subParse(const UnicodeString& text, int32_t& start, UChar ch, int32_t count,
+ 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, SimpleDateFormatMutableNFs &mutableNFs,
+ int32_t patLoc, MessageFormat * numericLeapMonthFormatter, UTimeZoneFormatTimeType *tzTimeType,
int32_t *dayPeriod=NULL) const;
void parseInt(const UnicodeString& text,
Formattable& number,
ParsePosition& pos,
UBool allowNegative,
- NumberFormat *fmt) const;
+ const NumberFormat *fmt) const;
void parseInt(const UnicodeString& text,
Formattable& number,
int32_t maxDigits,
ParsePosition& pos,
UBool allowNegative,
- NumberFormat *fmt) const;
+ const NumberFormat *fmt) const;
int32_t checkIntSuffix(const UnicodeString& text, int32_t start,
int32_t patLoc, UBool isNegative) const;
+ /**
+ * Counts number of digit code points in the specified text.
+ *
+ * @param text input text
+ * @param start start index, inclusive
+ * @param end end index, exclusive
+ * @return number of digits found in the text in the specified range.
+ */
+ int32_t countDigits(const UnicodeString& text, int32_t start, int32_t end) const;
+
/**
* Translate a pattern, mapping each character in the from string to the
* corresponding character in the to string. Return an error if the original
*/
int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const;
+ /**
+ * Initialize LocalizedNumberFormatter instances used for speedup.
+ */
+ void initFastNumberFormatters(UErrorCode& status);
+
+ /**
+ * Delete the LocalizedNumberFormatter instances used for speedup.
+ */
+ void freeFastNumberFormatters();
+
/**
* Initialize NumberFormat instances used for numbering system overrides.
*/
/**
* Lazy TimeZoneFormat instantiation, semantically const
*/
- TimeZoneFormat *tzFormat() const;
+ TimeZoneFormat *tzFormat(UErrorCode &status) const;
const NumberFormat* getNumberFormatByIndex(UDateFormatField index) const;
/**
* Map calendar field letter into calendar field level.
*/
- static int32_t getLevelFromChar(UChar ch);
+ static int32_t getLevelFromChar(char16_t ch);
/**
* Tell if a character can be used to define a field in a format string.
*/
- static UBool isSyntaxChar(UChar ch);
+ static UBool isSyntaxChar(char16_t ch);
/**
* The formatting pattern for this formatter.
UBool fHasMinute;
UBool fHasSecond;
+ UBool fHasHanYearChar; // pattern contains the Han year character \u5E74
/**
* Sets fHasMinutes and fHasSeconds.
*/
const SharedNumberFormat **fSharedNumberFormatters;
+ enum NumberFormatterKey {
+ SMPDTFMT_NF_1x10,
+ SMPDTFMT_NF_2x10,
+ SMPDTFMT_NF_3x10,
+ SMPDTFMT_NF_4x10,
+ SMPDTFMT_NF_2x2,
+ SMPDTFMT_NF_COUNT
+ };
+
+ /**
+ * Number formatters pre-allocated for fast performance on the most common integer lengths.
+ */
+ const number::LocalizedNumberFormatter* fFastNumberFormatters[SMPDTFMT_NF_COUNT] = {};
+
UBool fHaveDefaultCentury;
BreakIterator* fCapitalizationBrkIter;
return fDefaultCenturyStart;
}
+inline BreakIterator*
+SimpleDateFormat::getCapitalizationBrkIter() const
+{
+ return fCapitalizationBrkIter;
+}
+
U_NAMESPACE_END
+#endif // U_SHOW_CPLUSPLUS_API
#endif /* #if !UCONFIG_NO_FORMATTING */