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