1 // © 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 /* 4 ******************************************************************************** 5 * Copyright (C) 1997-2016, International Business Machines 6 * Corporation and others. All Rights Reserved. 7 ******************************************************************************** 8 * 9 * File DTFMTSYM.H 10 * 11 * Modification History: 12 * 13 * Date Name Description 14 * 02/19/97 aliu Converted from java. 15 * 07/21/98 stephen Added getZoneIndex() 16 * Changed to match C++ conventions 17 ******************************************************************************** 18 */ 19 20 #ifndef DTFMTSYM_H 21 #define DTFMTSYM_H 22 23 #include "unicode/utypes.h" 24 25 #if U_SHOW_CPLUSPLUS_API 26 27 #if !UCONFIG_NO_FORMATTING 28 29 #include "unicode/calendar.h" 30 #include "unicode/strenum.h" 31 #include "unicode/uobject.h" 32 #include "unicode/locid.h" 33 #include "unicode/udat.h" 34 #include "unicode/ures.h" 35 36 /** 37 * \file 38 * \brief C++ API: Symbols for formatting dates. 39 */ 40 41 U_NAMESPACE_BEGIN 42 43 /* forward declaration */ 44 class SimpleDateFormat; 45 class Hashtable; 46 47 /** 48 * DateFormatSymbols is a public class for encapsulating localizable date-time 49 * formatting data -- including timezone data. DateFormatSymbols is used by 50 * DateFormat and SimpleDateFormat. 51 * <P> 52 * Rather than first creating a DateFormatSymbols to get a date-time formatter 53 * by using a SimpleDateFormat constructor, clients are encouraged to create a 54 * date-time formatter using the getTimeInstance(), getDateInstance(), or 55 * getDateTimeInstance() method in DateFormat. Each of these methods can return a 56 * date/time formatter initialized with a default format pattern along with the 57 * date-time formatting data for a given or default locale. After a formatter is 58 * created, clients may modify the format pattern using the setPattern function 59 * as so desired. For more information on using these formatter factory 60 * functions, see DateFormat. 61 * <P> 62 * If clients decide to create a date-time formatter with a particular format 63 * pattern and locale, they can do so with new SimpleDateFormat(aPattern, 64 * new DateFormatSymbols(aLocale)). This will load the appropriate date-time 65 * formatting data from the locale. 66 * <P> 67 * DateFormatSymbols objects are clonable. When clients obtain a 68 * DateFormatSymbols object, they can feel free to modify the date-time 69 * formatting data as necessary. For instance, clients can 70 * replace the localized date-time format pattern characters with the ones that 71 * they feel easy to remember. Or they can change the representative cities 72 * originally picked by default to using their favorite ones. 73 * <P> 74 * DateFormatSymbols are not expected to be subclassed. Data for a calendar is 75 * loaded out of resource bundles. The 'type' parameter indicates the type of 76 * calendar, for example, "gregorian" or "japanese". If the type is not gregorian 77 * (or NULL, or an empty string) then the type is appended to the resource name, 78 * for example, 'Eras_japanese' instead of 'Eras'. If the resource 'Eras_japanese' did 79 * not exist (even in root), then this class will fall back to just 'Eras', that is, 80 * Gregorian data. Therefore, the calendar implementor MUST ensure that the root 81 * locale at least contains any resources that are to be particularized for the 82 * calendar type. 83 */ 84 class U_I18N_API DateFormatSymbols U_FINAL : public UObject { 85 public: 86 /** 87 * Construct a DateFormatSymbols object by loading format data from 88 * resources for the default locale, in the default calendar (Gregorian). 89 * <P> 90 * NOTE: This constructor will never fail; if it cannot get resource 91 * data for the default locale, it will return a last-resort object 92 * based on hard-coded strings. 93 * 94 * @param status Status code. Failure 95 * results if the resources for the default cannot be 96 * found or cannot be loaded 97 * @stable ICU 2.0 98 */ 99 DateFormatSymbols(UErrorCode& status); 100 101 /** 102 * Construct a DateFormatSymbols object by loading format data from 103 * resources for the given locale, in the default calendar (Gregorian). 104 * 105 * @param locale Locale to load format data from. 106 * @param status Status code. Failure 107 * results if the resources for the locale cannot be 108 * found or cannot be loaded 109 * @stable ICU 2.0 110 */ 111 DateFormatSymbols(const Locale& locale, 112 UErrorCode& status); 113 114 #ifndef U_HIDE_INTERNAL_API 115 /** 116 * Construct a DateFormatSymbols object by loading format data from 117 * resources for the default locale, in the default calendar (Gregorian). 118 * <P> 119 * NOTE: This constructor will never fail; if it cannot get resource 120 * data for the default locale, it will return a last-resort object 121 * based on hard-coded strings. 122 * 123 * @param type Type of calendar (as returned by Calendar::getType). 124 * Will be used to access the correct set of strings. 125 * (NULL or empty string defaults to "gregorian".) 126 * @param status Status code. Failure 127 * results if the resources for the default cannot be 128 * found or cannot be loaded 129 * @internal 130 */ 131 DateFormatSymbols(const char *type, UErrorCode& status); 132 133 /** 134 * Construct a DateFormatSymbols object by loading format data from 135 * resources for the given locale, in the default calendar (Gregorian). 136 * 137 * @param locale Locale to load format data from. 138 * @param type Type of calendar (as returned by Calendar::getType). 139 * Will be used to access the correct set of strings. 140 * (NULL or empty string defaults to "gregorian".) 141 * @param status Status code. Failure 142 * results if the resources for the locale cannot be 143 * found or cannot be loaded 144 * @internal 145 */ 146 DateFormatSymbols(const Locale& locale, 147 const char *type, 148 UErrorCode& status); 149 #endif /* U_HIDE_INTERNAL_API */ 150 151 /** 152 * Copy constructor. 153 * @stable ICU 2.0 154 */ 155 DateFormatSymbols(const DateFormatSymbols&); 156 157 /** 158 * Assignment operator. 159 * @stable ICU 2.0 160 */ 161 DateFormatSymbols& operator=(const DateFormatSymbols&); 162 163 /** 164 * Destructor. This is nonvirtual because this class is not designed to be 165 * subclassed. 166 * @stable ICU 2.0 167 */ 168 virtual ~DateFormatSymbols(); 169 170 /** 171 * Return true if another object is semantically equal to this one. 172 * 173 * @param other the DateFormatSymbols object to be compared with. 174 * @return true if other is semantically equal to this. 175 * @stable ICU 2.0 176 */ 177 UBool operator==(const DateFormatSymbols& other) const; 178 179 /** 180 * Return true if another object is semantically unequal to this one. 181 * 182 * @param other the DateFormatSymbols object to be compared with. 183 * @return true if other is semantically unequal to this. 184 * @stable ICU 2.0 185 */ 186 UBool operator!=(const DateFormatSymbols& other) const { return !operator==(other); } 187 188 /** 189 * Gets abbreviated era strings. For example: "AD" and "BC". 190 * 191 * @param count Filled in with length of the array. 192 * @return the era strings. 193 * @stable ICU 2.0 194 */ 195 const UnicodeString* getEras(int32_t& count) const; 196 197 /** 198 * Sets abbreviated era strings. For example: "AD" and "BC". 199 * @param eras Array of era strings (DateFormatSymbols retains ownership.) 200 * @param count Filled in with length of the array. 201 * @stable ICU 2.0 202 */ 203 void setEras(const UnicodeString* eras, int32_t count); 204 205 /** 206 * Gets era name strings. For example: "Anno Domini" and "Before Christ". 207 * 208 * @param count Filled in with length of the array. 209 * @return the era name strings. 210 * @stable ICU 3.4 211 */ 212 const UnicodeString* getEraNames(int32_t& count) const; 213 214 /** 215 * Sets era name strings. For example: "Anno Domini" and "Before Christ". 216 * @param eraNames Array of era name strings (DateFormatSymbols retains ownership.) 217 * @param count Filled in with length of the array. 218 * @stable ICU 3.6 219 */ 220 void setEraNames(const UnicodeString* eraNames, int32_t count); 221 222 /** 223 * Gets narrow era strings. For example: "A" and "B". 224 * 225 * @param count Filled in with length of the array. 226 * @return the narrow era strings. 227 * @stable ICU 4.2 228 */ 229 const UnicodeString* getNarrowEras(int32_t& count) const; 230 231 /** 232 * Sets narrow era strings. For example: "A" and "B". 233 * @param narrowEras Array of narrow era strings (DateFormatSymbols retains ownership.) 234 * @param count Filled in with length of the array. 235 * @stable ICU 4.2 236 */ 237 void setNarrowEras(const UnicodeString* narrowEras, int32_t count); 238 239 /** 240 * Gets month strings. For example: "January", "February", etc. 241 * @param count Filled in with length of the array. 242 * @return the month strings. (DateFormatSymbols retains ownership.) 243 * @stable ICU 2.0 244 */ 245 const UnicodeString* getMonths(int32_t& count) const; 246 247 /** 248 * Sets month strings. For example: "January", "February", etc. 249 * 250 * @param months the new month strings. (not adopted; caller retains ownership) 251 * @param count Filled in with length of the array. 252 * @stable ICU 2.0 253 */ 254 void setMonths(const UnicodeString* months, int32_t count); 255 256 /** 257 * Gets short month strings. For example: "Jan", "Feb", etc. 258 * 259 * @param count Filled in with length of the array. 260 * @return the short month strings. (DateFormatSymbols retains ownership.) 261 * @stable ICU 2.0 262 */ 263 const UnicodeString* getShortMonths(int32_t& count) const; 264 265 /** 266 * Sets short month strings. For example: "Jan", "Feb", etc. 267 * @param count Filled in with length of the array. 268 * @param shortMonths the new short month strings. (not adopted; caller retains ownership) 269 * @stable ICU 2.0 270 */ 271 void setShortMonths(const UnicodeString* shortMonths, int32_t count); 272 273 /** 274 * Selector for date formatting context 275 * @stable ICU 3.6 276 */ 277 enum DtContextType { 278 FORMAT, 279 STANDALONE, 280 #ifndef U_HIDE_DEPRECATED_API 281 /** 282 * One more than the highest normal DtContextType value. 283 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. 284 */ 285 DT_CONTEXT_COUNT 286 #endif // U_HIDE_DEPRECATED_API 287 }; 288 289 /** 290 * Selector for date formatting width 291 * @stable ICU 3.6 292 */ 293 enum DtWidthType { 294 ABBREVIATED, 295 WIDE, 296 NARROW, 297 /** 298 * Short width is currently only supported for weekday names. 299 * @stable ICU 51 300 */ 301 SHORT, 302 #ifndef U_HIDE_DEPRECATED_API 303 /** 304 * One more than the highest normal DtWidthType value. 305 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. 306 */ 307 DT_WIDTH_COUNT = 4 308 #endif // U_HIDE_DEPRECATED_API 309 }; 310 311 /** 312 * Gets month strings by width and context. For example: "January", "February", etc. 313 * @param count Filled in with length of the array. 314 * @param context The formatting context, either FORMAT or STANDALONE 315 * @param width The width of returned strings, either WIDE, ABBREVIATED, or NARROW. 316 * @return the month strings. (DateFormatSymbols retains ownership.) 317 * @stable ICU 3.4 318 */ 319 const UnicodeString* getMonths(int32_t& count, DtContextType context, DtWidthType width) const; 320 321 /** 322 * Sets month strings by width and context. For example: "January", "February", etc. 323 * 324 * @param months The new month strings. (not adopted; caller retains ownership) 325 * @param count Filled in with length of the array. 326 * @param context The formatting context, either FORMAT or STANDALONE 327 * @param width The width of returned strings, either WIDE, ABBREVIATED, or NARROW. 328 * @stable ICU 3.6 329 */ 330 void setMonths(const UnicodeString* months, int32_t count, DtContextType context, DtWidthType width); 331 332 /** 333 * Gets wide weekday strings. For example: "Sunday", "Monday", etc. 334 * @param count Filled in with length of the array. 335 * @return the weekday strings. (DateFormatSymbols retains ownership.) 336 * @stable ICU 2.0 337 */ 338 const UnicodeString* getWeekdays(int32_t& count) const; 339 340 341 /** 342 * Sets wide weekday strings. For example: "Sunday", "Monday", etc. 343 * @param weekdays the new weekday strings. (not adopted; caller retains ownership) 344 * @param count Filled in with length of the array. 345 * @stable ICU 2.0 346 */ 347 void setWeekdays(const UnicodeString* weekdays, int32_t count); 348 349 /** 350 * Gets abbreviated weekday strings. For example: "Sun", "Mon", etc. (Note: The method name is 351 * misleading; it does not get the CLDR-style "short" weekday strings, e.g. "Su", "Mo", etc.) 352 * @param count Filled in with length of the array. 353 * @return the abbreviated weekday strings. (DateFormatSymbols retains ownership.) 354 * @stable ICU 2.0 355 */ 356 const UnicodeString* getShortWeekdays(int32_t& count) const; 357 358 /** 359 * Sets abbreviated weekday strings. For example: "Sun", "Mon", etc. (Note: The method name is 360 * misleading; it does not set the CLDR-style "short" weekday strings, e.g. "Su", "Mo", etc.) 361 * @param abbrevWeekdays the new abbreviated weekday strings. (not adopted; caller retains ownership) 362 * @param count Filled in with length of the array. 363 * @stable ICU 2.0 364 */ 365 void setShortWeekdays(const UnicodeString* abbrevWeekdays, int32_t count); 366 367 /** 368 * Gets weekday strings by width and context. For example: "Sunday", "Monday", etc. 369 * @param count Filled in with length of the array. 370 * @param context The formatting context, either FORMAT or STANDALONE 371 * @param width The width of returned strings, either WIDE, ABBREVIATED, SHORT, or NARROW 372 * @return the month strings. (DateFormatSymbols retains ownership.) 373 * @stable ICU 3.4 374 */ 375 const UnicodeString* getWeekdays(int32_t& count, DtContextType context, DtWidthType width) const; 376 377 /** 378 * Sets weekday strings by width and context. For example: "Sunday", "Monday", etc. 379 * @param weekdays The new weekday strings. (not adopted; caller retains ownership) 380 * @param count Filled in with length of the array. 381 * @param context The formatting context, either FORMAT or STANDALONE 382 * @param width The width of returned strings, either WIDE, ABBREVIATED, SHORT, or NARROW 383 * @stable ICU 3.6 384 */ 385 void setWeekdays(const UnicodeString* weekdays, int32_t count, DtContextType context, DtWidthType width); 386 387 /** 388 * Gets quarter strings by width and context. For example: "1st Quarter", "2nd Quarter", etc. 389 * @param count Filled in with length of the array. 390 * @param context The formatting context, either FORMAT or STANDALONE 391 * @param width The width of returned strings, either WIDE or ABBREVIATED. There 392 * are no NARROW quarters. 393 * @return the quarter strings. (DateFormatSymbols retains ownership.) 394 * @stable ICU 3.6 395 */ 396 const UnicodeString* getQuarters(int32_t& count, DtContextType context, DtWidthType width) const; 397 398 /** 399 * Sets quarter strings by width and context. For example: "1st Quarter", "2nd Quarter", etc. 400 * 401 * @param quarters The new quarter strings. (not adopted; caller retains ownership) 402 * @param count Filled in with length of the array. 403 * @param context The formatting context, either FORMAT or STANDALONE 404 * @param width The width of returned strings, either WIDE or ABBREVIATED. There 405 * are no NARROW quarters. 406 * @stable ICU 3.6 407 */ 408 void setQuarters(const UnicodeString* quarters, int32_t count, DtContextType context, DtWidthType width); 409 410 /** 411 * Gets AM/PM strings. For example: "AM" and "PM". 412 * @param count Filled in with length of the array. 413 * @return the weekday strings. (DateFormatSymbols retains ownership.) 414 * @stable ICU 2.0 415 */ 416 const UnicodeString* getAmPmStrings(int32_t& count) const; 417 418 /** 419 * Sets ampm strings. For example: "AM" and "PM". 420 * @param ampms the new ampm strings. (not adopted; caller retains ownership) 421 * @param count Filled in with length of the array. 422 * @stable ICU 2.0 423 */ 424 void setAmPmStrings(const UnicodeString* ampms, int32_t count); 425 426 #ifndef U_HIDE_INTERNAL_API 427 /** 428 * This default time separator is used for formatting when the locale 429 * doesn't specify any time separator, and always recognized when parsing. 430 * @internal 431 */ 432 static const char16_t DEFAULT_TIME_SEPARATOR = 0x003a; // ':' 433 434 /** 435 * This alternate time separator is always recognized when parsing. 436 * @internal 437 */ 438 static const char16_t ALTERNATE_TIME_SEPARATOR = 0x002e; // '.' 439 440 /** 441 * Gets the time separator string. For example: ":". 442 * @param result Output param which will receive the time separator string. 443 * @return A reference to 'result'. 444 * @internal 445 */ 446 UnicodeString& getTimeSeparatorString(UnicodeString& result) const; 447 448 /** 449 * Sets the time separator string. For example: ":". 450 * @param newTimeSeparator the new time separator string. 451 * @internal 452 */ 453 void setTimeSeparatorString(const UnicodeString& newTimeSeparator); 454 #endif /* U_HIDE_INTERNAL_API */ 455 456 /** 457 * Gets cyclic year name strings if the calendar has them, by width and context. 458 * For example: "jia-zi", "yi-chou", etc. 459 * @param count Filled in with length of the array. 460 * @param context The usage context: FORMAT, STANDALONE. 461 * @param width The requested name width: WIDE, ABBREVIATED, NARROW. 462 * @return The year name strings (DateFormatSymbols retains ownership), 463 * or null if they are not available for this calendar. 464 * @stable ICU 54 465 */ 466 const UnicodeString* getYearNames(int32_t& count, 467 DtContextType context, DtWidthType width) const; 468 469 /** 470 * Sets cyclic year name strings by width and context. For example: "jia-zi", "yi-chou", etc. 471 * 472 * @param yearNames The new cyclic year name strings (not adopted; caller retains ownership). 473 * @param count The length of the array. 474 * @param context The usage context: FORMAT, STANDALONE (currently only FORMAT is supported). 475 * @param width The name width: WIDE, ABBREVIATED, NARROW (currently only ABBREVIATED is supported). 476 * @stable ICU 54 477 */ 478 void setYearNames(const UnicodeString* yearNames, int32_t count, 479 DtContextType context, DtWidthType width); 480 481 /** 482 * Gets calendar zodiac name strings if the calendar has them, by width and context. 483 * For example: "Rat", "Ox", "Tiger", etc. 484 * @param count Filled in with length of the array. 485 * @param context The usage context: FORMAT, STANDALONE. 486 * @param width The requested name width: WIDE, ABBREVIATED, NARROW. 487 * @return The zodiac name strings (DateFormatSymbols retains ownership), 488 * or null if they are not available for this calendar. 489 * @stable ICU 54 490 */ 491 const UnicodeString* getZodiacNames(int32_t& count, 492 DtContextType context, DtWidthType width) const; 493 494 /** 495 * Sets calendar zodiac name strings by width and context. For example: "Rat", "Ox", "Tiger", etc. 496 * 497 * @param zodiacNames The new zodiac name strings (not adopted; caller retains ownership). 498 * @param count The length of the array. 499 * @param context The usage context: FORMAT, STANDALONE (currently only FORMAT is supported). 500 * @param width The name width: WIDE, ABBREVIATED, NARROW (currently only ABBREVIATED is supported). 501 * @stable ICU 54 502 */ 503 void setZodiacNames(const UnicodeString* zodiacNames, int32_t count, 504 DtContextType context, DtWidthType width); 505 506 #ifndef U_HIDE_INTERNAL_API 507 /** 508 * Somewhat temporary constants for leap month pattern types, adequate for supporting 509 * just leap month patterns as needed for Chinese lunar calendar. 510 * Eventually we will add full support for different month pattern types (needed for 511 * other calendars such as Hindu) at which point this approach will be replaced by a 512 * more complete approach. 513 * @internal 514 */ 515 enum EMonthPatternType 516 { 517 kLeapMonthPatternFormatWide, 518 kLeapMonthPatternFormatAbbrev, 519 kLeapMonthPatternFormatNarrow, 520 kLeapMonthPatternStandaloneWide, 521 kLeapMonthPatternStandaloneAbbrev, 522 kLeapMonthPatternStandaloneNarrow, 523 kLeapMonthPatternNumeric, 524 kMonthPatternsCount 525 }; 526 527 /** 528 * Somewhat temporary function for getting complete set of leap month patterns for all 529 * contexts & widths, indexed by EMonthPatternType values. Returns NULL if calendar 530 * does not have leap month patterns. Note, there is currently no setter for this. 531 * Eventually we will add full support for different month pattern types (needed for 532 * other calendars such as Hindu) at which point this approach will be replaced by a 533 * more complete approach. 534 * @param count Filled in with length of the array (may be 0). 535 * @return The leap month patterns (DateFormatSymbols retains ownership). 536 * May be NULL if there are no leap month patterns for this calendar. 537 * @internal 538 */ 539 const UnicodeString* getLeapMonthPatterns(int32_t& count) const; 540 541 #endif /* U_HIDE_INTERNAL_API */ 542 543 #ifndef U_HIDE_DEPRECATED_API 544 /** 545 * Gets timezone strings. These strings are stored in a 2-dimensional array. 546 * @param rowCount Output param to receive number of rows. 547 * @param columnCount Output param to receive number of columns. 548 * @return The timezone strings as a 2-d array. (DateFormatSymbols retains ownership.) 549 * @deprecated ICU 3.6 550 */ 551 const UnicodeString** getZoneStrings(int32_t& rowCount, int32_t& columnCount) const; 552 #endif /* U_HIDE_DEPRECATED_API */ 553 554 /** 555 * Sets timezone strings. These strings are stored in a 2-dimensional array. 556 * <p><b>Note:</b> SimpleDateFormat no longer use the zone strings stored in 557 * a DateFormatSymbols. Therefore, the time zone strings set by this mthod 558 * have no effects in an instance of SimpleDateFormat for formatting time 559 * zones. 560 * @param strings The timezone strings as a 2-d array to be copied. (not adopted; caller retains ownership) 561 * @param rowCount The number of rows (count of first index). 562 * @param columnCount The number of columns (count of second index). 563 * @stable ICU 2.0 564 */ 565 void setZoneStrings(const UnicodeString* const* strings, int32_t rowCount, int32_t columnCount); 566 567 /** 568 * Get the non-localized date-time pattern characters. 569 * @return the non-localized date-time pattern characters 570 * @stable ICU 2.0 571 */ 572 static const char16_t * U_EXPORT2 getPatternUChars(void); 573 574 /** 575 * Gets localized date-time pattern characters. For example: 'u', 't', etc. 576 * <p> 577 * Note: ICU no longer provides localized date-time pattern characters for a locale 578 * starting ICU 3.8. This method returns the non-localized date-time pattern 579 * characters unless user defined localized data is set by setLocalPatternChars. 580 * @param result Output param which will receive the localized date-time pattern characters. 581 * @return A reference to 'result'. 582 * @stable ICU 2.0 583 */ 584 UnicodeString& getLocalPatternChars(UnicodeString& result) const; 585 586 /** 587 * Sets localized date-time pattern characters. For example: 'u', 't', etc. 588 * @param newLocalPatternChars the new localized date-time 589 * pattern characters. 590 * @stable ICU 2.0 591 */ 592 void setLocalPatternChars(const UnicodeString& newLocalPatternChars); 593 594 /** 595 * Returns the locale for this object. Two flavors are available: 596 * valid and actual locale. 597 * @stable ICU 2.8 598 */ 599 Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const; 600 601 /* The following type and kCapContextUsageTypeCount cannot be #ifndef U_HIDE_INTERNAL_API, 602 they are needed for .h file declarations. */ 603 /** 604 * Constants for capitalization context usage types. 605 * @internal 606 */ 607 enum ECapitalizationContextUsageType 608 { 609 #ifndef U_HIDE_INTERNAL_API 610 kCapContextUsageOther = 0, 611 kCapContextUsageMonthFormat, /* except narrow */ 612 kCapContextUsageMonthStandalone, /* except narrow */ 613 kCapContextUsageMonthNarrow, 614 kCapContextUsageDayFormat, /* except narrow */ 615 kCapContextUsageDayStandalone, /* except narrow */ 616 kCapContextUsageDayNarrow, 617 kCapContextUsageEraWide, 618 kCapContextUsageEraAbbrev, 619 kCapContextUsageEraNarrow, 620 kCapContextUsageZoneLong, 621 kCapContextUsageZoneShort, 622 kCapContextUsageMetazoneLong, 623 kCapContextUsageMetazoneShort, 624 #endif /* U_HIDE_INTERNAL_API */ 625 kCapContextUsageTypeCount = 14 626 }; 627 628 /** 629 * ICU "poor man's RTTI", returns a UClassID for the actual class. 630 * 631 * @stable ICU 2.2 632 */ 633 virtual UClassID getDynamicClassID() const; 634 635 /** 636 * ICU "poor man's RTTI", returns a UClassID for this class. 637 * 638 * @stable ICU 2.2 639 */ 640 static UClassID U_EXPORT2 getStaticClassID(); 641 642 private: 643 644 friend class SimpleDateFormat; 645 friend class DateFormatSymbolsSingleSetter; // see udat.cpp 646 647 /** 648 * Abbreviated era strings. For example: "AD" and "BC". 649 */ 650 UnicodeString* fEras; 651 int32_t fErasCount; 652 653 /** 654 * Era name strings. For example: "Anno Domini" and "Before Christ". 655 */ 656 UnicodeString* fEraNames; 657 int32_t fEraNamesCount; 658 659 /** 660 * Narrow era strings. For example: "A" and "B". 661 */ 662 UnicodeString* fNarrowEras; 663 int32_t fNarrowErasCount; 664 665 /** 666 * Month strings. For example: "January", "February", etc. 667 */ 668 UnicodeString* fMonths; 669 int32_t fMonthsCount; 670 671 /** 672 * Short month strings. For example: "Jan", "Feb", etc. 673 */ 674 UnicodeString* fShortMonths; 675 int32_t fShortMonthsCount; 676 677 /** 678 * Narrow month strings. For example: "J", "F", etc. 679 */ 680 UnicodeString* fNarrowMonths; 681 int32_t fNarrowMonthsCount; 682 683 /** 684 * Standalone Month strings. For example: "January", "February", etc. 685 */ 686 UnicodeString* fStandaloneMonths; 687 int32_t fStandaloneMonthsCount; 688 689 /** 690 * Standalone Short month strings. For example: "Jan", "Feb", etc. 691 */ 692 UnicodeString* fStandaloneShortMonths; 693 int32_t fStandaloneShortMonthsCount; 694 695 /** 696 * Standalone Narrow month strings. For example: "J", "F", etc. 697 */ 698 UnicodeString* fStandaloneNarrowMonths; 699 int32_t fStandaloneNarrowMonthsCount; 700 701 /** 702 * CLDR-style format wide weekday strings. For example: "Sunday", "Monday", etc. 703 */ 704 UnicodeString* fWeekdays; 705 int32_t fWeekdaysCount; 706 707 /** 708 * CLDR-style format abbreviated (not short) weekday strings. For example: "Sun", "Mon", etc. 709 */ 710 UnicodeString* fShortWeekdays; 711 int32_t fShortWeekdaysCount; 712 713 /** 714 * CLDR-style format short weekday strings. For example: "Su", "Mo", etc. 715 */ 716 UnicodeString* fShorterWeekdays; 717 int32_t fShorterWeekdaysCount; 718 719 /** 720 * CLDR-style format narrow weekday strings. For example: "S", "M", etc. 721 */ 722 UnicodeString* fNarrowWeekdays; 723 int32_t fNarrowWeekdaysCount; 724 725 /** 726 * CLDR-style standalone wide weekday strings. For example: "Sunday", "Monday", etc. 727 */ 728 UnicodeString* fStandaloneWeekdays; 729 int32_t fStandaloneWeekdaysCount; 730 731 /** 732 * CLDR-style standalone abbreviated (not short) weekday strings. For example: "Sun", "Mon", etc. 733 */ 734 UnicodeString* fStandaloneShortWeekdays; 735 int32_t fStandaloneShortWeekdaysCount; 736 737 /** 738 * CLDR-style standalone short weekday strings. For example: "Su", "Mo", etc. 739 */ 740 UnicodeString* fStandaloneShorterWeekdays; 741 int32_t fStandaloneShorterWeekdaysCount; 742 743 /** 744 * Standalone Narrow weekday strings. For example: "Sun", "Mon", etc. 745 */ 746 UnicodeString* fStandaloneNarrowWeekdays; 747 int32_t fStandaloneNarrowWeekdaysCount; 748 749 /** 750 * Ampm strings. For example: "AM" and "PM". 751 */ 752 UnicodeString* fAmPms; 753 int32_t fAmPmsCount; 754 755 /** 756 * Narrow Ampm strings. For example: "a" and "p". 757 */ 758 UnicodeString* fNarrowAmPms; 759 int32_t fNarrowAmPmsCount; 760 761 /** 762 * Time separator string. For example: ":". 763 */ 764 UnicodeString fTimeSeparator; 765 766 /** 767 * Quarter strings. For example: "1st quarter", "2nd quarter", etc. 768 */ 769 UnicodeString *fQuarters; 770 int32_t fQuartersCount; 771 772 /** 773 * Short quarters. For example: "Q1", "Q2", etc. 774 */ 775 UnicodeString *fShortQuarters; 776 int32_t fShortQuartersCount; 777 778 /** 779 * Standalone quarter strings. For example: "1st quarter", "2nd quarter", etc. 780 */ 781 UnicodeString *fStandaloneQuarters; 782 int32_t fStandaloneQuartersCount; 783 784 /** 785 * Standalone short quarter strings. For example: "Q1", "Q2", etc. 786 */ 787 UnicodeString *fStandaloneShortQuarters; 788 int32_t fStandaloneShortQuartersCount; 789 790 /** 791 * All leap month patterns, for example "{0}bis". 792 */ 793 UnicodeString *fLeapMonthPatterns; 794 int32_t fLeapMonthPatternsCount; 795 796 /** 797 * Cyclic year names, for example: "jia-zi", "yi-chou", ... "gui-hai"; 798 * currently we only have data for format/abbreviated. 799 * For the others, just get from format/abbreviated, ignore set. 800 */ 801 UnicodeString *fShortYearNames; 802 int32_t fShortYearNamesCount; 803 804 /** 805 * Cyclic zodiac names, for example "Rat", "Ox", "Tiger", etc.; 806 * currently we only have data for format/abbreviated. 807 * For the others, just get from format/abbreviated, ignore set. 808 */ 809 UnicodeString *fShortZodiacNames; 810 int32_t fShortZodiacNamesCount; 811 812 /** 813 * Localized names of time zones in this locale. This is a 814 * two-dimensional array of strings of size n by m, 815 * where m is at least 5 and up to 7. Each of the n rows is an 816 * entry containing the localized names for a single TimeZone. 817 * 818 * Each such row contains (with i ranging from 0..n-1): 819 * 820 * zoneStrings[i][0] - time zone ID 821 * example: America/Los_Angeles 822 * zoneStrings[i][1] - long name of zone in standard time 823 * example: Pacific Standard Time 824 * zoneStrings[i][2] - short name of zone in standard time 825 * example: PST 826 * zoneStrings[i][3] - long name of zone in daylight savings time 827 * example: Pacific Daylight Time 828 * zoneStrings[i][4] - short name of zone in daylight savings time 829 * example: PDT 830 * zoneStrings[i][5] - location name of zone 831 * example: United States (Los Angeles) 832 * zoneStrings[i][6] - long generic name of zone 833 * example: Pacific Time 834 * zoneStrings[i][7] - short generic of zone 835 * example: PT 836 * 837 * The zone ID is not localized; it corresponds to the ID 838 * value associated with a system time zone object. All other entries 839 * are localized names. If a zone does not implement daylight savings 840 * time, the daylight savings time names are ignored. 841 * 842 * Note:CLDR 1.5 introduced metazone and its historical mappings. 843 * This simple two-dimensional array is no longer sufficient to represent 844 * localized names and its historic changes. Since ICU 3.8.1, localized 845 * zone names extracted from ICU locale data is stored in a ZoneStringFormat 846 * instance. But we still need to support the old way of customizing 847 * localized zone names, so we keep this field for the purpose. 848 */ 849 UnicodeString **fZoneStrings; // Zone string array set by setZoneStrings 850 UnicodeString **fLocaleZoneStrings; // Zone string array created by the locale 851 int32_t fZoneStringsRowCount; 852 int32_t fZoneStringsColCount; 853 854 Locale fZSFLocale; // Locale used for getting ZoneStringFormat 855 856 /** 857 * Localized date-time pattern characters. For example: use 'u' as 'y'. 858 */ 859 UnicodeString fLocalPatternChars; 860 861 /** 862 * Capitalization transforms. For each usage type, the first array element indicates 863 * whether to titlecase for uiListOrMenu context, the second indicates whether to 864 * titlecase for stand-alone context. 865 */ 866 UBool fCapitalization[kCapContextUsageTypeCount][2]; 867 868 /** 869 * Abbreviated (== short) day period strings. 870 */ 871 UnicodeString *fAbbreviatedDayPeriods; 872 int32_t fAbbreviatedDayPeriodsCount; 873 874 /** 875 * Wide day period strings. 876 */ 877 UnicodeString *fWideDayPeriods; 878 int32_t fWideDayPeriodsCount; 879 880 /** 881 * Narrow day period strings. 882 */ 883 UnicodeString *fNarrowDayPeriods; 884 int32_t fNarrowDayPeriodsCount; 885 886 /** 887 * Stand-alone abbreviated (== short) day period strings. 888 */ 889 UnicodeString *fStandaloneAbbreviatedDayPeriods; 890 int32_t fStandaloneAbbreviatedDayPeriodsCount; 891 892 /** 893 * Stand-alone wide day period strings. 894 */ 895 UnicodeString *fStandaloneWideDayPeriods; 896 int32_t fStandaloneWideDayPeriodsCount; 897 898 /** 899 * Stand-alone narrow day period strings. 900 */ 901 UnicodeString *fStandaloneNarrowDayPeriods; 902 int32_t fStandaloneNarrowDayPeriodsCount; 903 904 private: 905 /** valid/actual locale information 906 * these are always ICU locales, so the length should not be a problem 907 */ 908 char validLocale[ULOC_FULLNAME_CAPACITY]; 909 char actualLocale[ULOC_FULLNAME_CAPACITY]; 910 911 DateFormatSymbols(); // default constructor not implemented 912 913 /** 914 * Called by the constructors to actually load data from the resources 915 * 916 * @param locale The locale to get symbols for. 917 * @param type Calendar Type (as from Calendar::getType()) 918 * @param status Input/output parameter, set to success or 919 * failure code upon return. 920 * @param useLastResortData determine if use last resort data 921 */ 922 void initializeData(const Locale& locale, const char *type, UErrorCode& status, UBool useLastResortData = FALSE); 923 924 /** 925 * Copy or alias an array in another object, as appropriate. 926 * 927 * @param dstArray the copy destination array. 928 * @param dstCount fill in with the lenth of 'dstArray'. 929 * @param srcArray the source array to be copied. 930 * @param srcCount the length of items to be copied from the 'srcArray'. 931 */ 932 static void assignArray(UnicodeString*& dstArray, 933 int32_t& dstCount, 934 const UnicodeString* srcArray, 935 int32_t srcCount); 936 937 /** 938 * Return true if the given arrays' contents are equal, or if the arrays are 939 * identical (pointers are equal). 940 * 941 * @param array1 one array to be compared with. 942 * @param array2 another array to be compared with. 943 * @param count the length of items to be copied. 944 * @return true if the given arrays' contents are equal, or if the arrays are 945 * identical (pointers are equal). 946 */ 947 static UBool arrayCompare(const UnicodeString* array1, 948 const UnicodeString* array2, 949 int32_t count); 950 951 /** 952 * Create a copy, in fZoneStrings, of the given zone strings array. The 953 * member variables fZoneStringsRowCount and fZoneStringsColCount should be 954 * set already by the caller. 955 */ 956 void createZoneStrings(const UnicodeString *const * otherStrings); 957 958 /** 959 * Delete all the storage owned by this object. 960 */ 961 void dispose(void); 962 963 /** 964 * Copy all of the other's data to this. 965 * @param other the object to be copied. 966 */ 967 void copyData(const DateFormatSymbols& other); 968 969 /** 970 * Create zone strings array by locale if not yet available 971 */ 972 void initZoneStringsArray(void); 973 974 /** 975 * Delete just the zone strings. 976 */ 977 void disposeZoneStrings(void); 978 979 /** 980 * Returns the date format field index of the pattern character c, 981 * or UDAT_FIELD_COUNT if c is not a pattern character. 982 */ 983 static UDateFormatField U_EXPORT2 getPatternCharIndex(char16_t c); 984 985 /** 986 * Returns TRUE if f (with its pattern character repeated count times) is a numeric field. 987 */ 988 static UBool U_EXPORT2 isNumericField(UDateFormatField f, int32_t count); 989 990 /** 991 * Returns TRUE if c (repeated count times) is the pattern character for a numeric field. 992 */ 993 static UBool U_EXPORT2 isNumericPatternChar(char16_t c, int32_t count); 994 public: 995 #ifndef U_HIDE_INTERNAL_API 996 /** 997 * Gets a DateFormatSymbols by locale. 998 * Unlike the constructors which always use gregorian calendar, this 999 * method uses the calendar in the locale. If the locale contains no 1000 * explicit calendar, this method uses the default calendar for that 1001 * locale. 1002 * @param locale the locale. 1003 * @param status error returned here. 1004 * @return the new DateFormatSymbols which the caller owns. 1005 * @internal For ICU use only. 1006 */ 1007 static DateFormatSymbols * U_EXPORT2 createForLocale( 1008 const Locale &locale, UErrorCode &status); 1009 #endif /* U_HIDE_INTERNAL_API */ 1010 }; 1011 1012 U_NAMESPACE_END 1013 1014 #endif /* #if !UCONFIG_NO_FORMATTING */ 1015 1016 #endif /* U_SHOW_CPLUSPLUS_API */ 1017 1018 #endif // _DTFMTSYM 1019 //eof 1020