| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1997-2014, International Business Machines Corporation and | 2 * Copyright (C) 1997-2015, International Business Machines Corporation and |
| 3 * others. All Rights Reserved. | 3 * others. All Rights Reserved. |
| 4 ******************************************************************************* | 4 ******************************************************************************* |
| 5 * | 5 * |
| 6 * File SMPDTFMT.H | 6 * File SMPDTFMT.H |
| 7 * | 7 * |
| 8 * Modification History: | 8 * Modification History: |
| 9 * | 9 * |
| 10 * Date Name Description | 10 * Date Name Description |
| 11 * 02/19/97 aliu Converted from java. | 11 * 02/19/97 aliu Converted from java. |
| 12 * 07/09/97 helena Make ParsePosition into a class. | 12 * 07/09/97 helena Make ParsePosition into a class. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 38 #include "unicode/tzfmt.h" /* for UTimeZoneFormatTimeType */ | 38 #include "unicode/tzfmt.h" /* for UTimeZoneFormatTimeType */ |
| 39 #include "unicode/brkiter.h" | 39 #include "unicode/brkiter.h" |
| 40 | 40 |
| 41 U_NAMESPACE_BEGIN | 41 U_NAMESPACE_BEGIN |
| 42 | 42 |
| 43 class DateFormatSymbols; | 43 class DateFormatSymbols; |
| 44 class DateFormat; | 44 class DateFormat; |
| 45 class MessageFormat; | 45 class MessageFormat; |
| 46 class FieldPositionHandler; | 46 class FieldPositionHandler; |
| 47 class TimeZoneFormat; | 47 class TimeZoneFormat; |
| 48 class SharedNumberFormat; |
| 49 class SimpleDateFormatMutableNFs; |
| 48 | 50 |
| 49 /** | 51 /** |
| 50 * | 52 * |
| 51 * SimpleDateFormat is a concrete class for formatting and parsing dates in a | 53 * SimpleDateFormat is a concrete class for formatting and parsing dates in a |
| 52 * language-independent manner. It allows for formatting (millis -> text), | 54 * language-independent manner. It allows for formatting (millis -> text), |
| 53 * parsing (text -> millis), and normalization. Formats/Parses a date or time, | 55 * parsing (text -> millis), and normalization. Formats/Parses a date or time, |
| 54 * which is the standard milliseconds since 24:00 GMT, Jan 1, 1970. | 56 * which is the standard milliseconds since 24:00 GMT, Jan 1, 1970. |
| 55 * <P> | 57 * <P> |
| 56 * Clients are encouraged to create a date-time formatter using DateFormat::getI
nstance(), | 58 * Clients are encouraged to create a date-time formatter using DateFormat::getI
nstance(), |
| 57 * getDateInstance(), getDateInstance(), or getDateTimeInstance() rather than | 59 * getDateInstance(), getDateInstance(), or getDateTimeInstance() rather than |
| (...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1110 */ | 1112 */ |
| 1111 virtual void setTimeZoneFormat(const TimeZoneFormat& newTimeZoneFormat); | 1113 virtual void setTimeZoneFormat(const TimeZoneFormat& newTimeZoneFormat); |
| 1112 | 1114 |
| 1113 /** | 1115 /** |
| 1114 * Gets the time zone format object associated with this date/time formatter
. | 1116 * Gets the time zone format object associated with this date/time formatter
. |
| 1115 * @return the time zone format associated with this date/time formatter. | 1117 * @return the time zone format associated with this date/time formatter. |
| 1116 * @internal ICU 49 technology preview | 1118 * @internal ICU 49 technology preview |
| 1117 */ | 1119 */ |
| 1118 virtual const TimeZoneFormat* getTimeZoneFormat(void) const; | 1120 virtual const TimeZoneFormat* getTimeZoneFormat(void) const; |
| 1119 | 1121 |
| 1120 /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since
it is virtual */ | |
| 1121 /** | 1122 /** |
| 1122 * Set a particular UDisplayContext value in the formatter, such as | 1123 * Set a particular UDisplayContext value in the formatter, such as |
| 1123 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. Note: For getContext, see | 1124 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. Note: For getContext, see |
| 1124 * DateFormat. | 1125 * DateFormat. |
| 1125 * @param value The UDisplayContext value to set. | 1126 * @param value The UDisplayContext value to set. |
| 1126 * @param status Input/output status. If at entry this indicates a failure | 1127 * @param status Input/output status. If at entry this indicates a failure |
| 1127 * status, the function will do nothing; otherwise this will b
e | 1128 * status, the function will do nothing; otherwise this will b
e |
| 1128 * updated with any new status from the function. | 1129 * updated with any new status from the function. |
| 1129 * @draft ICU 53 | 1130 * @stable ICU 53 |
| 1130 */ | 1131 */ |
| 1131 virtual void setContext(UDisplayContext value, UErrorCode& status); | 1132 virtual void setContext(UDisplayContext value, UErrorCode& status); |
| 1132 | 1133 |
| 1133 #ifndef U_HIDE_DRAFT_API | |
| 1134 /** | 1134 /** |
| 1135 * Overrides base class method and | 1135 * Overrides base class method and |
| 1136 * This method clears per field NumberFormat instances | 1136 * This method clears per field NumberFormat instances |
| 1137 * previously set by {@see adoptNumberFormat(const UnicodeString&, NumberFor
mat*, UErrorCode)} | 1137 * previously set by {@see adoptNumberFormat(const UnicodeString&, NumberFor
mat*, UErrorCode)} |
| 1138 * @param adoptNF the NumbeferFormat used | 1138 * @param adoptNF the NumbeferFormat used |
| 1139 * @draft ICU 54 | 1139 * @stable ICU 54 |
| 1140 */ | 1140 */ |
| 1141 void adoptNumberFormat(NumberFormat *formatToAdopt); | 1141 void adoptNumberFormat(NumberFormat *formatToAdopt); |
| 1142 | 1142 |
| 1143 /** | 1143 /** |
| 1144 * Allow the user to set the NumberFormat for several fields | 1144 * Allow the user to set the NumberFormat for several fields |
| 1145 * It can be a single field like: "y"(year) or "M"(month) | 1145 * It can be a single field like: "y"(year) or "M"(month) |
| 1146 * It can be several field combined together: "yM"(year and month) | 1146 * It can be several field combined together: "yM"(year and month) |
| 1147 * Note: | 1147 * Note: |
| 1148 * 1 symbol field is enough for multiple symbol field (so "y" will override
"yy", "yyy") | 1148 * 1 symbol field is enough for multiple symbol field (so "y" will override
"yy", "yyy") |
| 1149 * If the field is not numeric, then override has no effect (like "MMM" will
use abbreviation, not numerical field) | 1149 * If the field is not numeric, then override has no effect (like "MMM" will
use abbreviation, not numerical field) |
| 1150 * Per field NumberFormat can also be cleared in {@see DateFormat::setNumber
Format(const NumberFormat& newNumberFormat)} | 1150 * Per field NumberFormat can also be cleared in {@see DateFormat::setNumber
Format(const NumberFormat& newNumberFormat)} |
| 1151 * | 1151 * |
| 1152 * @param fields the fields to override(like y) | 1152 * @param fields the fields to override(like y) |
| 1153 * @param adoptNF the NumbeferFormat used | 1153 * @param adoptNF the NumbeferFormat used |
| 1154 * @param status Receives a status code, which will be U_ZERO_ERROR | 1154 * @param status Receives a status code, which will be U_ZERO_ERROR |
| 1155 * if the operation succeeds. | 1155 * if the operation succeeds. |
| 1156 * @draft ICU 54 | 1156 * @stable ICU 54 |
| 1157 */ | 1157 */ |
| 1158 void adoptNumberFormat(const UnicodeString& fields, NumberFormat *formatToAd
opt, UErrorCode &status); | 1158 void adoptNumberFormat(const UnicodeString& fields, NumberFormat *formatToAd
opt, UErrorCode &status); |
| 1159 | 1159 |
| 1160 /** | 1160 /** |
| 1161 * Get the numbering system to be used for a particular field. | 1161 * Get the numbering system to be used for a particular field. |
| 1162 * @param field The UDateFormatField to get | 1162 * @param field The UDateFormatField to get |
| 1163 * @draft ICU 54 | 1163 * @stable ICU 54 |
| 1164 */ | 1164 */ |
| 1165 const NumberFormat * getNumberFormatForField(UChar field) const; | 1165 const NumberFormat * getNumberFormatForField(UChar field) const; |
| 1166 #endif /* U_HIDE_DRAFT_API */ | |
| 1167 | 1166 |
| 1168 #ifndef U_HIDE_INTERNAL_API | 1167 #ifndef U_HIDE_INTERNAL_API |
| 1169 /** | 1168 /** |
| 1170 * This is for ICU internal use only. Please do not use. | 1169 * This is for ICU internal use only. Please do not use. |
| 1171 * Check whether the 'field' is smaller than all the fields covered in | 1170 * Check whether the 'field' is smaller than all the fields covered in |
| 1172 * pattern, return TRUE if it is. The sequence of calendar field, | 1171 * pattern, return TRUE if it is. The sequence of calendar field, |
| 1173 * from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,... | 1172 * from large to small is: ERA, YEAR, MONTH, DATE, AM_PM, HOUR, MINUTE,... |
| 1174 * @param field the calendar field need to check against | 1173 * @param field the calendar field need to check against |
| 1175 * @return TRUE if the 'field' is smaller than all the fields | 1174 * @return TRUE if the 'field' is smaller than all the fields |
| 1176 * covered in pattern. FALSE otherwise. | 1175 * covered in pattern. FALSE otherwise. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1254 * @param status Receives a status code, which will be U_ZERO_ERROR if th
e operation | 1253 * @param status Receives a status code, which will be U_ZERO_ERROR if th
e operation |
| 1255 * succeeds. | 1254 * succeeds. |
| 1256 */ | 1255 */ |
| 1257 void subFormat(UnicodeString &appendTo, | 1256 void subFormat(UnicodeString &appendTo, |
| 1258 UChar ch, | 1257 UChar ch, |
| 1259 int32_t count, | 1258 int32_t count, |
| 1260 UDisplayContext capitalizationContext, | 1259 UDisplayContext capitalizationContext, |
| 1261 int32_t fieldNum, | 1260 int32_t fieldNum, |
| 1262 FieldPositionHandler& handler, | 1261 FieldPositionHandler& handler, |
| 1263 Calendar& cal, | 1262 Calendar& cal, |
| 1263 SimpleDateFormatMutableNFs &mutableNFs, |
| 1264 UErrorCode& status) const; // in case of illegal argument | 1264 UErrorCode& status) const; // in case of illegal argument |
| 1265 | 1265 |
| 1266 /** | 1266 /** |
| 1267 * Used by subFormat() to format a numeric value. | 1267 * Used by subFormat() to format a numeric value. |
| 1268 * Appends to toAppendTo a string representation of "value" | 1268 * Appends to toAppendTo a string representation of "value" |
| 1269 * having a number of digits between "minDigits" and | 1269 * having a number of digits between "minDigits" and |
| 1270 * "maxDigits". Uses the DateFormat's NumberFormat. | 1270 * "maxDigits". Uses the DateFormat's NumberFormat. |
| 1271 * | 1271 * |
| 1272 * @param currentNumberFormat | 1272 * @param currentNumberFormat |
| 1273 * @param appendTo Output parameter to receive result. | 1273 * @param appendTo Output parameter to receive result. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1301 /** | 1301 /** |
| 1302 * initializes fCalendar from parameters. Returns fCalendar as a convenienc
e. | 1302 * initializes fCalendar from parameters. Returns fCalendar as a convenienc
e. |
| 1303 * @param adoptZone Zone to be adopted, or NULL for TimeZone::createDefault
(). | 1303 * @param adoptZone Zone to be adopted, or NULL for TimeZone::createDefault
(). |
| 1304 * @param locale Locale of the calendar | 1304 * @param locale Locale of the calendar |
| 1305 * @param status Error code | 1305 * @param status Error code |
| 1306 * @return the newly constructed fCalendar | 1306 * @return the newly constructed fCalendar |
| 1307 */ | 1307 */ |
| 1308 Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErr
orCode& status); | 1308 Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErr
orCode& status); |
| 1309 | 1309 |
| 1310 /** | 1310 /** |
| 1311 * initializes fSymbols from parameters. | |
| 1312 * @param locale Locale of the symbols | |
| 1313 * @param calendar Alias to Calendar that will be used. | |
| 1314 * @param status Error code | |
| 1315 */ | |
| 1316 void initializeSymbols(const Locale& locale, Calendar* calendar, UErrorCode&
status); | |
| 1317 | |
| 1318 /** | |
| 1319 * Called by several of the constructors to load pattern data and formatting
symbols | 1311 * Called by several of the constructors to load pattern data and formatting
symbols |
| 1320 * out of a resource bundle and initialize the locale based on it. | 1312 * out of a resource bundle and initialize the locale based on it. |
| 1321 * @param timeStyle The time style, as passed to DateFormat::createDateI
nstance(). | 1313 * @param timeStyle The time style, as passed to DateFormat::createDateI
nstance(). |
| 1322 * @param dateStyle The date style, as passed to DateFormat::createTimeI
nstance(). | 1314 * @param dateStyle The date style, as passed to DateFormat::createTimeI
nstance(). |
| 1323 * @param locale The locale to load the patterns from. | 1315 * @param locale The locale to load the patterns from. |
| 1324 * @param status Filled in with an error code if loading the data fro
m the | 1316 * @param status Filled in with an error code if loading the data fro
m the |
| 1325 * resources fails. | 1317 * resources fails. |
| 1326 */ | 1318 */ |
| 1327 void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UEr
rorCode& status); | 1319 void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UEr
rorCode& status); |
| 1328 | 1320 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1400 * into a date/time string. | 1392 * into a date/time string. |
| 1401 * @param patLoc | 1393 * @param patLoc |
| 1402 * @param numericLeapMonthFormatter If non-null, used to parse numeric leap
months. | 1394 * @param numericLeapMonthFormatter If non-null, used to parse numeric leap
months. |
| 1403 * @param tzTimeType the type of parsed time zone - standard, daylight or un
known (output). | 1395 * @param tzTimeType the type of parsed time zone - standard, daylight or un
known (output). |
| 1404 * This parameter can be NULL if caller does not need the information. | 1396 * This parameter can be NULL if caller does not need the information. |
| 1405 * @return the new start position if matching succeeded; a negative number | 1397 * @return the new start position if matching succeeded; a negative number |
| 1406 * indicating matching failure, otherwise. | 1398 * indicating matching failure, otherwise. |
| 1407 */ | 1399 */ |
| 1408 int32_t subParse(const UnicodeString& text, int32_t& start, UChar ch, int32_
t count, | 1400 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, | 1401 UBool obeyCount, UBool allowNegative, UBool ambiguousYear[]
, int32_t& saveHebrewMonth, Calendar& cal, |
| 1410 int32_t patLoc, MessageFormat * numericLeapMonthFormatter,
UTimeZoneFormatTimeType *tzTimeType) const; | 1402 int32_t patLoc, MessageFormat * numericLeapMonthFormatter,
UTimeZoneFormatTimeType *tzTimeType, SimpleDateFormatMutableNFs &mutableNFs) con
st; |
| 1411 | 1403 |
| 1412 void parseInt(const UnicodeString& text, | 1404 void parseInt(const UnicodeString& text, |
| 1413 Formattable& number, | 1405 Formattable& number, |
| 1414 ParsePosition& pos, | 1406 ParsePosition& pos, |
| 1415 UBool allowNegative, | 1407 UBool allowNegative, |
| 1416 NumberFormat *fmt) const; | 1408 NumberFormat *fmt) const; |
| 1417 | 1409 |
| 1418 void parseInt(const UnicodeString& text, | 1410 void parseInt(const UnicodeString& text, |
| 1419 Formattable& number, | 1411 Formattable& number, |
| 1420 int32_t maxDigits, | 1412 int32_t maxDigits, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1476 * in text. | 1468 * in text. |
| 1477 */ | 1469 */ |
| 1478 int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const; | 1470 int32_t skipUWhiteSpace(const UnicodeString& text, int32_t pos) const; |
| 1479 | 1471 |
| 1480 /** | 1472 /** |
| 1481 * Initialize NumberFormat instances used for numbering system overrides. | 1473 * Initialize NumberFormat instances used for numbering system overrides. |
| 1482 */ | 1474 */ |
| 1483 void initNumberFormatters(const Locale &locale,UErrorCode &status); | 1475 void initNumberFormatters(const Locale &locale,UErrorCode &status); |
| 1484 | 1476 |
| 1485 /** | 1477 /** |
| 1486 * Get the numbering system to be used for a particular field. | |
| 1487 */ | |
| 1488 NumberFormat * getNumberFormatByIndex(UDateFormatField index) const; | |
| 1489 | |
| 1490 /** | |
| 1491 * Parse the given override string and set up structures for number formats | 1478 * Parse the given override string and set up structures for number formats |
| 1492 */ | 1479 */ |
| 1493 void processOverrideString(const Locale &locale, const UnicodeString &str, i
nt8_t type, UErrorCode &status); | 1480 void processOverrideString(const Locale &locale, const UnicodeString &str, i
nt8_t type, UErrorCode &status); |
| 1494 | 1481 |
| 1495 /** | 1482 /** |
| 1496 * Used to map pattern characters to Calendar field identifiers. | 1483 * Used to map pattern characters to Calendar field identifiers. |
| 1497 */ | 1484 */ |
| 1498 static const UCalendarDateFields fgPatternIndexToCalendarField[]; | 1485 static const UCalendarDateFields fgPatternIndexToCalendarField[]; |
| 1499 | 1486 |
| 1500 /** | 1487 /** |
| 1501 * Map index into pattern character string to DateFormat field number | 1488 * Map index into pattern character string to DateFormat field number |
| 1502 */ | 1489 */ |
| 1503 static const UDateFormatField fgPatternIndexToDateFormatField[]; | 1490 static const UDateFormatField fgPatternIndexToDateFormatField[]; |
| 1504 | 1491 |
| 1505 /** | 1492 /** |
| 1506 * Lazy TimeZoneFormat instantiation, semantically const | 1493 * Lazy TimeZoneFormat instantiation, semantically const |
| 1507 */ | 1494 */ |
| 1508 TimeZoneFormat *tzFormat() const; | 1495 TimeZoneFormat *tzFormat() const; |
| 1509 | 1496 |
| 1497 const NumberFormat* getNumberFormatByIndex(UDateFormatField index) const; |
| 1498 |
| 1510 /** | 1499 /** |
| 1511 * Used to map Calendar field to field level. | 1500 * Used to map Calendar field to field level. |
| 1512 * The larger the level, the smaller the field unit. | 1501 * The larger the level, the smaller the field unit. |
| 1513 * For example, UCAL_ERA level is 0, UCAL_YEAR level is 10, | 1502 * For example, UCAL_ERA level is 0, UCAL_YEAR level is 10, |
| 1514 * UCAL_MONTH level is 20. | 1503 * UCAL_MONTH level is 20. |
| 1515 */ | 1504 */ |
| 1516 static const int32_t fgCalendarFieldToLevel[]; | 1505 static const int32_t fgCalendarFieldToLevel[]; |
| 1517 static const int32_t fgPatternCharToLevel[]; | 1506 |
| 1507 /** |
| 1508 * Map calendar field letter into calendar field level. |
| 1509 */ |
| 1510 static int32_t getLevelFromChar(UChar ch); |
| 1511 |
| 1512 /** |
| 1513 * Tell if a character can be used to define a field in a format string. |
| 1514 */ |
| 1515 static UBool isSyntaxChar(UChar ch); |
| 1518 | 1516 |
| 1519 /** | 1517 /** |
| 1520 * The formatting pattern for this formatter. | 1518 * The formatting pattern for this formatter. |
| 1521 */ | 1519 */ |
| 1522 UnicodeString fPattern; | 1520 UnicodeString fPattern; |
| 1523 | 1521 |
| 1524 /** | 1522 /** |
| 1525 * The numbering system override for dates. | 1523 * The numbering system override for dates. |
| 1526 */ | 1524 */ |
| 1527 UnicodeString fDateOverride; | 1525 UnicodeString fDateOverride; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1556 * defaultCenturyStartYear are only used if explicitly set by the user | 1554 * defaultCenturyStartYear are only used if explicitly set by the user |
| 1557 * through the API method parseAmbiguousDatesAsAfter(). | 1555 * through the API method parseAmbiguousDatesAsAfter(). |
| 1558 */ | 1556 */ |
| 1559 UDate fDefaultCenturyStart; | 1557 UDate fDefaultCenturyStart; |
| 1560 | 1558 |
| 1561 /** | 1559 /** |
| 1562 * See documentation for defaultCenturyStart. | 1560 * See documentation for defaultCenturyStart. |
| 1563 */ | 1561 */ |
| 1564 /*transient*/ int32_t fDefaultCenturyStartYear; | 1562 /*transient*/ int32_t fDefaultCenturyStartYear; |
| 1565 | 1563 |
| 1566 typedef struct NSOverride { | 1564 struct NSOverride : public UMemory { |
| 1567 NumberFormat *nf; | 1565 const SharedNumberFormat *snf; |
| 1568 int32_t hash; | 1566 int32_t hash; |
| 1569 NSOverride *next; | 1567 NSOverride *next; |
| 1570 } NSOverride; | 1568 void free(); |
| 1569 NSOverride() : snf(NULL), hash(0), next(NULL) { |
| 1570 } |
| 1571 ~NSOverride(); |
| 1572 }; |
| 1571 | 1573 |
| 1572 NumberFormat **fNumberFormatters; | 1574 /** |
| 1573 | 1575 * The number format in use for each date field. NULL means fall back |
| 1574 NSOverride *fOverrideList; | 1576 * to fNumberFormat in DateFormat. |
| 1577 */ |
| 1578 const SharedNumberFormat **fSharedNumberFormatters; |
| 1575 | 1579 |
| 1576 UBool fHaveDefaultCentury; | 1580 UBool fHaveDefaultCentury; |
| 1577 | 1581 |
| 1578 BreakIterator* fCapitalizationBrkIter; | 1582 BreakIterator* fCapitalizationBrkIter; |
| 1579 }; | 1583 }; |
| 1580 | 1584 |
| 1581 inline UDate | 1585 inline UDate |
| 1582 SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const | 1586 SimpleDateFormat::get2DigitYearStart(UErrorCode& /*status*/) const |
| 1583 { | 1587 { |
| 1584 return fDefaultCenturyStart; | 1588 return fDefaultCenturyStart; |
| 1585 } | 1589 } |
| 1586 | 1590 |
| 1587 U_NAMESPACE_END | 1591 U_NAMESPACE_END |
| 1588 | 1592 |
| 1589 #endif /* #if !UCONFIG_NO_FORMATTING */ | 1593 #endif /* #if !UCONFIG_NO_FORMATTING */ |
| 1590 | 1594 |
| 1591 #endif // _SMPDTFMT | 1595 #endif // _SMPDTFMT |
| 1592 //eof | 1596 //eof |
| OLD | NEW |