2 *******************************************************************************
3 * Copyright (C) 1997-2016, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
9 * Modification History:
11 * Date Name Description
12 * 02/19/97 aliu Converted from java.
13 * 07/21/98 stephen Added getZoneIndex
14 * Changed weekdays/short weekdays to be one-based
15 * 06/14/99 stephen Removed SimpleDateFormat::fgTimeZoneDataSuffix
16 * 11/16/99 weiv Added 'Y' and 'e' to fgPatternChars
17 * 03/27/00 weiv Keeping resource bundle around!
18 * 06/30/05 emmons Added eraNames, narrow month/day, standalone context
19 * 10/12/05 emmons Added setters for eraNames, month/day by width/context
20 *******************************************************************************
22 #include "unicode/utypes.h"
24 #if !UCONFIG_NO_FORMATTING
25 #include "unicode/ustring.h"
26 #include "unicode/localpointer.h"
27 #include "unicode/dtfmtsym.h"
28 #include "unicode/smpdtfmt.h"
29 #include "unicode/msgfmt.h"
30 #include "unicode/numsys.h"
31 #include "unicode/tznames.h"
41 #include "shareddateformatsymbols.h"
42 #include "unicode/calendar.h"
43 #include "unifiedcache.h"
45 // *****************************************************************************
46 // class DateFormatSymbols
47 // *****************************************************************************
50 * These are static arrays we use only in the case where we have no
54 #if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR
55 #define PATTERN_CHARS_LEN 38
57 #define PATTERN_CHARS_LEN 37
61 * Unlocalized date-time pattern characters. For example: 'y', 'd', etc. All
62 * locales use the same these unlocalized pattern characters.
64 static const UChar gPatternChars
[] = {
65 // if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR:
66 // GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXxrbB:
68 // GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXxrbB
70 0x47, 0x79, 0x4D, 0x64, 0x6B, 0x48, 0x6D, 0x73, 0x53, 0x45,
71 0x44, 0x46, 0x77, 0x57, 0x61, 0x68, 0x4B, 0x7A, 0x59, 0x65,
72 0x75, 0x67, 0x41, 0x5A, 0x76, 0x63, 0x4c, 0x51, 0x71, 0x56,
73 0x55, 0x4F, 0x58, 0x78, 0x72, 0x62, 0x42,
74 #if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR
80 //------------------------------------------------------
81 // Strings of last resort. These are only used if we have no resource
82 // files. They aren't designed for actual use, just for backup.
84 // These are the month names and abbreviations of last resort.
85 static const UChar gLastResortMonthNames
[13][3] =
87 {0x0030, 0x0031, 0x0000}, /* "01" */
88 {0x0030, 0x0032, 0x0000}, /* "02" */
89 {0x0030, 0x0033, 0x0000}, /* "03" */
90 {0x0030, 0x0034, 0x0000}, /* "04" */
91 {0x0030, 0x0035, 0x0000}, /* "05" */
92 {0x0030, 0x0036, 0x0000}, /* "06" */
93 {0x0030, 0x0037, 0x0000}, /* "07" */
94 {0x0030, 0x0038, 0x0000}, /* "08" */
95 {0x0030, 0x0039, 0x0000}, /* "09" */
96 {0x0031, 0x0030, 0x0000}, /* "10" */
97 {0x0031, 0x0031, 0x0000}, /* "11" */
98 {0x0031, 0x0032, 0x0000}, /* "12" */
99 {0x0031, 0x0033, 0x0000} /* "13" */
102 // These are the weekday names and abbreviations of last resort.
103 static const UChar gLastResortDayNames
[8][2] =
105 {0x0030, 0x0000}, /* "0" */
106 {0x0031, 0x0000}, /* "1" */
107 {0x0032, 0x0000}, /* "2" */
108 {0x0033, 0x0000}, /* "3" */
109 {0x0034, 0x0000}, /* "4" */
110 {0x0035, 0x0000}, /* "5" */
111 {0x0036, 0x0000}, /* "6" */
112 {0x0037, 0x0000} /* "7" */
115 // These are the quarter names and abbreviations of last resort.
116 static const UChar gLastResortQuarters
[4][2] =
118 {0x0031, 0x0000}, /* "1" */
119 {0x0032, 0x0000}, /* "2" */
120 {0x0033, 0x0000}, /* "3" */
121 {0x0034, 0x0000}, /* "4" */
124 // These are the am/pm and BC/AD markers of last resort.
125 static const UChar gLastResortAmPmMarkers
[2][3] =
127 {0x0041, 0x004D, 0x0000}, /* "AM" */
128 {0x0050, 0x004D, 0x0000} /* "PM" */
131 static const UChar gLastResortEras
[2][3] =
133 {0x0042, 0x0043, 0x0000}, /* "BC" */
134 {0x0041, 0x0044, 0x0000} /* "AD" */
137 /* Sizes for the last resort string arrays */
138 typedef enum LastResortSize
{
163 SharedDateFormatSymbols::~SharedDateFormatSymbols() {
166 template<> U_I18N_API
167 const SharedDateFormatSymbols
*
168 LocaleCacheKey
<SharedDateFormatSymbols
>::createObject(
169 const void * /*unusedContext*/, UErrorCode
&status
) const {
171 Calendar::getCalendarTypeFromLocale(fLoc
, type
, UPRV_LENGTHOF(type
), status
);
172 if (U_FAILURE(status
)) {
175 SharedDateFormatSymbols
*shared
176 = new SharedDateFormatSymbols(fLoc
, type
, status
);
177 if (shared
== NULL
) {
178 status
= U_MEMORY_ALLOCATION_ERROR
;
181 if (U_FAILURE(status
)) {
189 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateFormatSymbols
)
191 #define kSUPPLEMENTAL "supplementalData"
194 * These are the tags we expect to see in normal resource bundle files associated
195 * with a locale and calendar
197 static const char gErasTag
[]="eras";
198 static const char gCyclicNameSetsTag
[]="cyclicNameSets";
199 static const char gNameSetYearsTag
[]="years";
200 static const char gNameSetZodiacsTag
[]="zodiacs";
201 static const char gMonthNamesTag
[]="monthNames";
202 static const char gMonthPatternsTag
[]="monthPatterns";
203 static const char gDayNamesTag
[]="dayNames";
204 static const char gNamesWideTag
[]="wide";
205 static const char gNamesAbbrTag
[]="abbreviated";
206 static const char gNamesShortTag
[]="short";
207 static const char gNamesNarrowTag
[]="narrow";
208 static const char gNamesAllTag
[]="all";
209 static const char gNamesLeapTag
[]="leap";
210 static const char gNamesFormatTag
[]="format";
211 static const char gNamesStandaloneTag
[]="stand-alone";
212 static const char gNamesNumericTag
[]="numeric";
213 static const char gAmPmMarkersTag
[]="AmPmMarkers";
214 static const char gAmPmMarkersNarrowTag
[]="AmPmMarkersNarrow";
215 static const char gQuartersTag
[]="quarters";
216 static const char gNumberElementsTag
[]="NumberElements";
217 static const char gSymbolsTag
[]="symbols";
218 static const char gTimeSeparatorTag
[]="timeSeparator";
219 static const char gDayPeriodTag
[]="dayPeriod";
221 // static const char gZoneStringsTag[]="zoneStrings";
223 // static const char gLocalPatternCharsTag[]="localPatternChars";
225 static const char gContextTransformsTag
[]="contextTransforms";
227 static UMutex LOCK
= U_MUTEX_INITIALIZER
;
230 * Jitterbug 2974: MSVC has a bug whereby new X[0] behaves badly.
233 static inline UnicodeString
* newUnicodeStringArray(size_t count
) {
234 return new UnicodeString
[count
? count
: 1];
237 //------------------------------------------------------
239 DateFormatSymbols
* U_EXPORT2
240 DateFormatSymbols::createForLocale(
241 const Locale
& locale
, UErrorCode
&status
) {
242 const SharedDateFormatSymbols
*shared
= NULL
;
243 UnifiedCache::getByLocale(locale
, shared
, status
);
244 if (U_FAILURE(status
)) {
247 DateFormatSymbols
*result
= new DateFormatSymbols(shared
->get());
249 if (result
== NULL
) {
250 status
= U_MEMORY_ALLOCATION_ERROR
;
256 DateFormatSymbols::DateFormatSymbols(const Locale
& locale
,
260 initializeData(locale
, NULL
, status
);
263 DateFormatSymbols::DateFormatSymbols(UErrorCode
& status
)
266 initializeData(Locale::getDefault(), NULL
, status
, TRUE
);
270 DateFormatSymbols::DateFormatSymbols(const Locale
& locale
,
275 initializeData(locale
, type
, status
);
278 DateFormatSymbols::DateFormatSymbols(const char *type
, UErrorCode
& status
)
281 initializeData(Locale::getDefault(), type
, status
, TRUE
);
284 DateFormatSymbols::DateFormatSymbols(const DateFormatSymbols
& other
)
291 DateFormatSymbols::assignArray(UnicodeString
*& dstArray
,
293 const UnicodeString
* srcArray
,
296 // assignArray() is only called by copyData(), which in turn implements the
297 // copy constructor and the assignment operator.
298 // All strings in a DateFormatSymbols object are created in one of the following
299 // three ways that all allow to safely use UnicodeString::fastCopyFrom():
300 // - readonly-aliases from resource bundles
301 // - readonly-aliases or allocated strings from constants
302 // - safely cloned strings (with owned buffers) from setXYZ() functions
304 // Note that this is true for as long as DateFormatSymbols can be constructed
305 // only from a locale bundle or set via the cloning API,
306 // *and* for as long as all the strings are in *private* fields, preventing
307 // a subclass from creating these strings in an "unsafe" way (with respect to fastCopyFrom()).
309 dstArray
= newUnicodeStringArray(srcCount
);
310 if(dstArray
!= NULL
) {
312 for(i
=0; i
<srcCount
; ++i
) {
313 dstArray
[i
].fastCopyFrom(srcArray
[i
]);
319 * Create a copy, in fZoneStrings, of the given zone strings array. The
320 * member variables fZoneStringsRowCount and fZoneStringsColCount should
321 * be set already by the caller.
324 DateFormatSymbols::createZoneStrings(const UnicodeString
*const * otherStrings
)
327 UBool failed
= FALSE
;
329 fZoneStrings
= (UnicodeString
**)uprv_malloc(fZoneStringsRowCount
* sizeof(UnicodeString
*));
330 if (fZoneStrings
!= NULL
) {
331 for (row
=0; row
<fZoneStringsRowCount
; ++row
)
333 fZoneStrings
[row
] = newUnicodeStringArray(fZoneStringsColCount
);
334 if (fZoneStrings
[row
] == NULL
) {
338 for (col
=0; col
<fZoneStringsColCount
; ++col
) {
339 // fastCopyFrom() - see assignArray comments
340 fZoneStrings
[row
][col
].fastCopyFrom(otherStrings
[row
][col
]);
344 // If memory allocation failed, roll back and delete fZoneStrings
346 for (int i
= row
; i
>= 0; i
--) {
347 delete[] fZoneStrings
[i
];
349 uprv_free(fZoneStrings
);
355 * Copy all of the other's data to this.
358 DateFormatSymbols::copyData(const DateFormatSymbols
& other
) {
359 UErrorCode status
= U_ZERO_ERROR
;
360 U_LOCALE_BASED(locBased
, *this);
361 locBased
.setLocaleIDs(
362 other
.getLocale(ULOC_VALID_LOCALE
, status
),
363 other
.getLocale(ULOC_ACTUAL_LOCALE
, status
));
364 assignArray(fEras
, fErasCount
, other
.fEras
, other
.fErasCount
);
365 assignArray(fEraNames
, fEraNamesCount
, other
.fEraNames
, other
.fEraNamesCount
);
366 assignArray(fNarrowEras
, fNarrowErasCount
, other
.fNarrowEras
, other
.fNarrowErasCount
);
367 assignArray(fMonths
, fMonthsCount
, other
.fMonths
, other
.fMonthsCount
);
368 assignArray(fShortMonths
, fShortMonthsCount
, other
.fShortMonths
, other
.fShortMonthsCount
);
369 assignArray(fNarrowMonths
, fNarrowMonthsCount
, other
.fNarrowMonths
, other
.fNarrowMonthsCount
);
370 assignArray(fStandaloneMonths
, fStandaloneMonthsCount
, other
.fStandaloneMonths
, other
.fStandaloneMonthsCount
);
371 assignArray(fStandaloneShortMonths
, fStandaloneShortMonthsCount
, other
.fStandaloneShortMonths
, other
.fStandaloneShortMonthsCount
);
372 assignArray(fStandaloneNarrowMonths
, fStandaloneNarrowMonthsCount
, other
.fStandaloneNarrowMonths
, other
.fStandaloneNarrowMonthsCount
);
373 assignArray(fWeekdays
, fWeekdaysCount
, other
.fWeekdays
, other
.fWeekdaysCount
);
374 assignArray(fShortWeekdays
, fShortWeekdaysCount
, other
.fShortWeekdays
, other
.fShortWeekdaysCount
);
375 assignArray(fShorterWeekdays
, fShorterWeekdaysCount
, other
.fShorterWeekdays
, other
.fShorterWeekdaysCount
);
376 assignArray(fNarrowWeekdays
, fNarrowWeekdaysCount
, other
.fNarrowWeekdays
, other
.fNarrowWeekdaysCount
);
377 assignArray(fStandaloneWeekdays
, fStandaloneWeekdaysCount
, other
.fStandaloneWeekdays
, other
.fStandaloneWeekdaysCount
);
378 assignArray(fStandaloneShortWeekdays
, fStandaloneShortWeekdaysCount
, other
.fStandaloneShortWeekdays
, other
.fStandaloneShortWeekdaysCount
);
379 assignArray(fStandaloneShorterWeekdays
, fStandaloneShorterWeekdaysCount
, other
.fStandaloneShorterWeekdays
, other
.fStandaloneShorterWeekdaysCount
);
380 assignArray(fStandaloneNarrowWeekdays
, fStandaloneNarrowWeekdaysCount
, other
.fStandaloneNarrowWeekdays
, other
.fStandaloneNarrowWeekdaysCount
);
381 assignArray(fAmPms
, fAmPmsCount
, other
.fAmPms
, other
.fAmPmsCount
);
382 assignArray(fNarrowAmPms
, fNarrowAmPmsCount
, other
.fNarrowAmPms
, other
.fNarrowAmPmsCount
);
383 fTimeSeparator
.fastCopyFrom(other
.fTimeSeparator
); // fastCopyFrom() - see assignArray comments
384 assignArray(fQuarters
, fQuartersCount
, other
.fQuarters
, other
.fQuartersCount
);
385 assignArray(fShortQuarters
, fShortQuartersCount
, other
.fShortQuarters
, other
.fShortQuartersCount
);
386 assignArray(fStandaloneQuarters
, fStandaloneQuartersCount
, other
.fStandaloneQuarters
, other
.fStandaloneQuartersCount
);
387 assignArray(fStandaloneShortQuarters
, fStandaloneShortQuartersCount
, other
.fStandaloneShortQuarters
, other
.fStandaloneShortQuartersCount
);
388 assignArray(fWideDayPeriods
, fWideDayPeriodsCount
,
389 other
.fWideDayPeriods
, other
.fWideDayPeriodsCount
);
390 assignArray(fNarrowDayPeriods
, fNarrowDayPeriodsCount
,
391 other
.fNarrowDayPeriods
, other
.fNarrowDayPeriodsCount
);
392 assignArray(fAbbreviatedDayPeriods
, fAbbreviatedDayPeriodsCount
,
393 other
.fAbbreviatedDayPeriods
, other
.fAbbreviatedDayPeriodsCount
);
394 assignArray(fStandaloneWideDayPeriods
, fStandaloneWideDayPeriodsCount
,
395 other
.fStandaloneWideDayPeriods
, other
.fStandaloneWideDayPeriodsCount
);
396 assignArray(fStandaloneNarrowDayPeriods
, fStandaloneNarrowDayPeriodsCount
,
397 other
.fStandaloneNarrowDayPeriods
, other
.fStandaloneNarrowDayPeriodsCount
);
398 assignArray(fStandaloneAbbreviatedDayPeriods
, fStandaloneAbbreviatedDayPeriodsCount
,
399 other
.fStandaloneAbbreviatedDayPeriods
, other
.fStandaloneAbbreviatedDayPeriodsCount
);
400 if (other
.fLeapMonthPatterns
!= NULL
) {
401 assignArray(fLeapMonthPatterns
, fLeapMonthPatternsCount
, other
.fLeapMonthPatterns
, other
.fLeapMonthPatternsCount
);
403 fLeapMonthPatterns
= NULL
;
404 fLeapMonthPatternsCount
= 0;
406 if (other
.fShortYearNames
!= NULL
) {
407 assignArray(fShortYearNames
, fShortYearNamesCount
, other
.fShortYearNames
, other
.fShortYearNamesCount
);
409 fShortYearNames
= NULL
;
410 fShortYearNamesCount
= 0;
412 if (other
.fShortZodiacNames
!= NULL
) {
413 assignArray(fShortZodiacNames
, fShortZodiacNamesCount
, other
.fShortZodiacNames
, other
.fShortZodiacNamesCount
);
415 fShortZodiacNames
= NULL
;
416 fShortZodiacNamesCount
= 0;
419 if (other
.fZoneStrings
!= NULL
) {
420 fZoneStringsColCount
= other
.fZoneStringsColCount
;
421 fZoneStringsRowCount
= other
.fZoneStringsRowCount
;
422 createZoneStrings((const UnicodeString
**)other
.fZoneStrings
);
426 fZoneStringsColCount
= 0;
427 fZoneStringsRowCount
= 0;
429 fZSFLocale
= other
.fZSFLocale
;
430 // Other zone strings data is created on demand
431 fLocaleZoneStrings
= NULL
;
433 // fastCopyFrom() - see assignArray comments
434 fLocalPatternChars
.fastCopyFrom(other
.fLocalPatternChars
);
436 uprv_memcpy(fCapitalization
, other
.fCapitalization
, sizeof(fCapitalization
));
440 * Assignment operator.
442 DateFormatSymbols
& DateFormatSymbols::operator=(const DateFormatSymbols
& other
)
450 DateFormatSymbols::~DateFormatSymbols()
455 void DateFormatSymbols::dispose()
459 delete[] fNarrowEras
;
461 delete[] fShortMonths
;
462 delete[] fNarrowMonths
;
463 delete[] fStandaloneMonths
;
464 delete[] fStandaloneShortMonths
;
465 delete[] fStandaloneNarrowMonths
;
467 delete[] fShortWeekdays
;
468 delete[] fShorterWeekdays
;
469 delete[] fNarrowWeekdays
;
470 delete[] fStandaloneWeekdays
;
471 delete[] fStandaloneShortWeekdays
;
472 delete[] fStandaloneShorterWeekdays
;
473 delete[] fStandaloneNarrowWeekdays
;
475 delete[] fNarrowAmPms
;
477 delete[] fShortQuarters
;
478 delete[] fStandaloneQuarters
;
479 delete[] fStandaloneShortQuarters
;
480 delete[] fLeapMonthPatterns
;
481 delete[] fShortYearNames
;
482 delete[] fShortZodiacNames
;
483 delete[] fAbbreviatedDayPeriods
;
484 delete[] fWideDayPeriods
;
485 delete[] fNarrowDayPeriods
;
486 delete[] fStandaloneAbbreviatedDayPeriods
;
487 delete[] fStandaloneWideDayPeriods
;
488 delete[] fStandaloneNarrowDayPeriods
;
490 disposeZoneStrings();
493 void DateFormatSymbols::disposeZoneStrings()
496 for (int32_t row
= 0; row
< fZoneStringsRowCount
; ++row
) {
497 delete[] fZoneStrings
[row
];
499 uprv_free(fZoneStrings
);
501 if (fLocaleZoneStrings
) {
502 for (int32_t row
= 0; row
< fZoneStringsRowCount
; ++row
) {
503 delete[] fLocaleZoneStrings
[row
];
505 uprv_free(fLocaleZoneStrings
);
509 fLocaleZoneStrings
= NULL
;
510 fZoneStringsRowCount
= 0;
511 fZoneStringsColCount
= 0;
515 DateFormatSymbols::arrayCompare(const UnicodeString
* array1
,
516 const UnicodeString
* array2
,
519 if (array1
== array2
) return TRUE
;
523 if (array1
[count
] != array2
[count
]) return FALSE
;
529 DateFormatSymbols::operator==(const DateFormatSymbols
& other
) const
531 // First do cheap comparisons
532 if (this == &other
) {
535 if (fErasCount
== other
.fErasCount
&&
536 fEraNamesCount
== other
.fEraNamesCount
&&
537 fNarrowErasCount
== other
.fNarrowErasCount
&&
538 fMonthsCount
== other
.fMonthsCount
&&
539 fShortMonthsCount
== other
.fShortMonthsCount
&&
540 fNarrowMonthsCount
== other
.fNarrowMonthsCount
&&
541 fStandaloneMonthsCount
== other
.fStandaloneMonthsCount
&&
542 fStandaloneShortMonthsCount
== other
.fStandaloneShortMonthsCount
&&
543 fStandaloneNarrowMonthsCount
== other
.fStandaloneNarrowMonthsCount
&&
544 fWeekdaysCount
== other
.fWeekdaysCount
&&
545 fShortWeekdaysCount
== other
.fShortWeekdaysCount
&&
546 fShorterWeekdaysCount
== other
.fShorterWeekdaysCount
&&
547 fNarrowWeekdaysCount
== other
.fNarrowWeekdaysCount
&&
548 fStandaloneWeekdaysCount
== other
.fStandaloneWeekdaysCount
&&
549 fStandaloneShortWeekdaysCount
== other
.fStandaloneShortWeekdaysCount
&&
550 fStandaloneShorterWeekdaysCount
== other
.fStandaloneShorterWeekdaysCount
&&
551 fStandaloneNarrowWeekdaysCount
== other
.fStandaloneNarrowWeekdaysCount
&&
552 fAmPmsCount
== other
.fAmPmsCount
&&
553 fNarrowAmPmsCount
== other
.fNarrowAmPmsCount
&&
554 fQuartersCount
== other
.fQuartersCount
&&
555 fShortQuartersCount
== other
.fShortQuartersCount
&&
556 fStandaloneQuartersCount
== other
.fStandaloneQuartersCount
&&
557 fStandaloneShortQuartersCount
== other
.fStandaloneShortQuartersCount
&&
558 fLeapMonthPatternsCount
== other
.fLeapMonthPatternsCount
&&
559 fShortYearNamesCount
== other
.fShortYearNamesCount
&&
560 fShortZodiacNamesCount
== other
.fShortZodiacNamesCount
&&
561 fAbbreviatedDayPeriodsCount
== other
.fAbbreviatedDayPeriodsCount
&&
562 fWideDayPeriodsCount
== other
.fWideDayPeriodsCount
&&
563 fNarrowDayPeriodsCount
== other
.fNarrowDayPeriodsCount
&&
564 fStandaloneAbbreviatedDayPeriodsCount
== other
.fStandaloneAbbreviatedDayPeriodsCount
&&
565 fStandaloneWideDayPeriodsCount
== other
.fStandaloneWideDayPeriodsCount
&&
566 fStandaloneNarrowDayPeriodsCount
== other
.fStandaloneNarrowDayPeriodsCount
&&
567 (uprv_memcmp(fCapitalization
, other
.fCapitalization
, sizeof(fCapitalization
))==0))
569 // Now compare the arrays themselves
570 if (arrayCompare(fEras
, other
.fEras
, fErasCount
) &&
571 arrayCompare(fEraNames
, other
.fEraNames
, fEraNamesCount
) &&
572 arrayCompare(fNarrowEras
, other
.fNarrowEras
, fNarrowErasCount
) &&
573 arrayCompare(fMonths
, other
.fMonths
, fMonthsCount
) &&
574 arrayCompare(fShortMonths
, other
.fShortMonths
, fShortMonthsCount
) &&
575 arrayCompare(fNarrowMonths
, other
.fNarrowMonths
, fNarrowMonthsCount
) &&
576 arrayCompare(fStandaloneMonths
, other
.fStandaloneMonths
, fStandaloneMonthsCount
) &&
577 arrayCompare(fStandaloneShortMonths
, other
.fStandaloneShortMonths
, fStandaloneShortMonthsCount
) &&
578 arrayCompare(fStandaloneNarrowMonths
, other
.fStandaloneNarrowMonths
, fStandaloneNarrowMonthsCount
) &&
579 arrayCompare(fWeekdays
, other
.fWeekdays
, fWeekdaysCount
) &&
580 arrayCompare(fShortWeekdays
, other
.fShortWeekdays
, fShortWeekdaysCount
) &&
581 arrayCompare(fShorterWeekdays
, other
.fShorterWeekdays
, fShorterWeekdaysCount
) &&
582 arrayCompare(fNarrowWeekdays
, other
.fNarrowWeekdays
, fNarrowWeekdaysCount
) &&
583 arrayCompare(fStandaloneWeekdays
, other
.fStandaloneWeekdays
, fStandaloneWeekdaysCount
) &&
584 arrayCompare(fStandaloneShortWeekdays
, other
.fStandaloneShortWeekdays
, fStandaloneShortWeekdaysCount
) &&
585 arrayCompare(fStandaloneShorterWeekdays
, other
.fStandaloneShorterWeekdays
, fStandaloneShorterWeekdaysCount
) &&
586 arrayCompare(fStandaloneNarrowWeekdays
, other
.fStandaloneNarrowWeekdays
, fStandaloneNarrowWeekdaysCount
) &&
587 arrayCompare(fAmPms
, other
.fAmPms
, fAmPmsCount
) &&
588 arrayCompare(fNarrowAmPms
, other
.fNarrowAmPms
, fNarrowAmPmsCount
) &&
589 fTimeSeparator
== other
.fTimeSeparator
&&
590 arrayCompare(fQuarters
, other
.fQuarters
, fQuartersCount
) &&
591 arrayCompare(fShortQuarters
, other
.fShortQuarters
, fShortQuartersCount
) &&
592 arrayCompare(fStandaloneQuarters
, other
.fStandaloneQuarters
, fStandaloneQuartersCount
) &&
593 arrayCompare(fStandaloneShortQuarters
, other
.fStandaloneShortQuarters
, fStandaloneShortQuartersCount
) &&
594 arrayCompare(fLeapMonthPatterns
, other
.fLeapMonthPatterns
, fLeapMonthPatternsCount
) &&
595 arrayCompare(fShortYearNames
, other
.fShortYearNames
, fShortYearNamesCount
) &&
596 arrayCompare(fShortZodiacNames
, other
.fShortZodiacNames
, fShortZodiacNamesCount
) &&
597 arrayCompare(fAbbreviatedDayPeriods
, other
.fAbbreviatedDayPeriods
, fAbbreviatedDayPeriodsCount
) &&
598 arrayCompare(fWideDayPeriods
, other
.fWideDayPeriods
, fWideDayPeriodsCount
) &&
599 arrayCompare(fNarrowDayPeriods
, other
.fNarrowDayPeriods
, fNarrowDayPeriodsCount
) &&
600 arrayCompare(fStandaloneAbbreviatedDayPeriods
, other
.fStandaloneAbbreviatedDayPeriods
,
601 fStandaloneAbbreviatedDayPeriodsCount
) &&
602 arrayCompare(fStandaloneWideDayPeriods
, other
.fStandaloneWideDayPeriods
,
603 fStandaloneWideDayPeriodsCount
) &&
604 arrayCompare(fStandaloneNarrowDayPeriods
, other
.fStandaloneNarrowDayPeriods
,
605 fStandaloneWideDayPeriodsCount
))
607 // Compare the contents of fZoneStrings
608 if (fZoneStrings
== NULL
&& other
.fZoneStrings
== NULL
) {
609 if (fZSFLocale
== other
.fZSFLocale
) {
612 } else if (fZoneStrings
!= NULL
&& other
.fZoneStrings
!= NULL
) {
613 if (fZoneStringsRowCount
== other
.fZoneStringsRowCount
614 && fZoneStringsColCount
== other
.fZoneStringsColCount
) {
616 for (int32_t i
= 0; (i
< fZoneStringsRowCount
) && cmpres
; i
++) {
617 cmpres
= arrayCompare(fZoneStrings
[i
], other
.fZoneStrings
[i
], fZoneStringsColCount
);
628 //------------------------------------------------------
631 DateFormatSymbols::getEras(int32_t &count
) const
638 DateFormatSymbols::getEraNames(int32_t &count
) const
640 count
= fEraNamesCount
;
645 DateFormatSymbols::getNarrowEras(int32_t &count
) const
647 count
= fNarrowErasCount
;
652 DateFormatSymbols::getMonths(int32_t &count
) const
654 count
= fMonthsCount
;
659 DateFormatSymbols::getShortMonths(int32_t &count
) const
661 count
= fShortMonthsCount
;
666 DateFormatSymbols::getMonths(int32_t &count
, DtContextType context
, DtWidthType width
) const
668 UnicodeString
*returnValue
= NULL
;
674 count
= fMonthsCount
;
675 returnValue
= fMonths
;
678 case SHORT
: // no month data for this, defaults to ABBREVIATED
679 count
= fShortMonthsCount
;
680 returnValue
= fShortMonths
;
683 count
= fNarrowMonthsCount
;
684 returnValue
= fNarrowMonths
;
686 case DT_WIDTH_COUNT
:
693 count
= fStandaloneMonthsCount
;
694 returnValue
= fStandaloneMonths
;
697 case SHORT
: // no month data for this, defaults to ABBREVIATED
698 count
= fStandaloneShortMonthsCount
;
699 returnValue
= fStandaloneShortMonths
;
702 count
= fStandaloneNarrowMonthsCount
;
703 returnValue
= fStandaloneNarrowMonths
;
705 case DT_WIDTH_COUNT
:
709 case DT_CONTEXT_COUNT
:
716 DateFormatSymbols::getWeekdays(int32_t &count
) const
718 count
= fWeekdaysCount
;
723 DateFormatSymbols::getShortWeekdays(int32_t &count
) const
725 count
= fShortWeekdaysCount
;
726 return fShortWeekdays
;
730 DateFormatSymbols::getWeekdays(int32_t &count
, DtContextType context
, DtWidthType width
) const
732 UnicodeString
*returnValue
= NULL
;
737 count
= fWeekdaysCount
;
738 returnValue
= fWeekdays
;
741 count
= fShortWeekdaysCount
;
742 returnValue
= fShortWeekdays
;
745 count
= fShorterWeekdaysCount
;
746 returnValue
= fShorterWeekdays
;
749 count
= fNarrowWeekdaysCount
;
750 returnValue
= fNarrowWeekdays
;
752 case DT_WIDTH_COUNT
:
759 count
= fStandaloneWeekdaysCount
;
760 returnValue
= fStandaloneWeekdays
;
763 count
= fStandaloneShortWeekdaysCount
;
764 returnValue
= fStandaloneShortWeekdays
;
767 count
= fStandaloneShorterWeekdaysCount
;
768 returnValue
= fStandaloneShorterWeekdays
;
771 count
= fStandaloneNarrowWeekdaysCount
;
772 returnValue
= fStandaloneNarrowWeekdays
;
774 case DT_WIDTH_COUNT
:
778 case DT_CONTEXT_COUNT
:
785 DateFormatSymbols::getQuarters(int32_t &count
, DtContextType context
, DtWidthType width
) const
787 UnicodeString
*returnValue
= NULL
;
793 count
= fQuartersCount
;
794 returnValue
= fQuarters
;
797 case SHORT
: // no quarter data for this, defaults to ABBREVIATED
798 count
= fShortQuartersCount
;
799 returnValue
= fShortQuarters
;
805 case DT_WIDTH_COUNT
:
812 count
= fStandaloneQuartersCount
;
813 returnValue
= fStandaloneQuarters
;
816 case SHORT
: // no quarter data for this, defaults to ABBREVIATED
817 count
= fStandaloneShortQuartersCount
;
818 returnValue
= fStandaloneShortQuarters
;
824 case DT_WIDTH_COUNT
:
828 case DT_CONTEXT_COUNT
:
835 DateFormatSymbols::getTimeSeparatorString(UnicodeString
& result
) const
837 // fastCopyFrom() - see assignArray comments
838 return result
.fastCopyFrom(fTimeSeparator
);
842 DateFormatSymbols::getAmPmStrings(int32_t &count
) const
849 DateFormatSymbols::getLeapMonthPatterns(int32_t &count
) const
851 count
= fLeapMonthPatternsCount
;
852 return fLeapMonthPatterns
;
856 DateFormatSymbols::getYearNames(int32_t& count
,
857 DtContextType
/*ignored*/, DtWidthType
/*ignored*/) const
859 count
= fShortYearNamesCount
;
860 return fShortYearNames
;
864 DateFormatSymbols::setYearNames(const UnicodeString
* yearNames
, int32_t count
,
865 DtContextType context
, DtWidthType width
)
867 if (context
== FORMAT
&& width
== ABBREVIATED
) {
868 if (fShortYearNames
) {
869 delete[] fShortYearNames
;
871 fShortYearNames
= newUnicodeStringArray(count
);
872 uprv_arrayCopy(yearNames
, fShortYearNames
, count
);
873 fShortYearNamesCount
= count
;
878 DateFormatSymbols::getZodiacNames(int32_t& count
,
879 DtContextType
/*ignored*/, DtWidthType
/*ignored*/) const
881 count
= fShortZodiacNamesCount
;
882 return fShortZodiacNames
;
886 DateFormatSymbols::setZodiacNames(const UnicodeString
* zodiacNames
, int32_t count
,
887 DtContextType context
, DtWidthType width
)
889 if (context
== FORMAT
&& width
== ABBREVIATED
) {
890 if (fShortZodiacNames
) {
891 delete[] fShortZodiacNames
;
893 fShortZodiacNames
= newUnicodeStringArray(count
);
894 uprv_arrayCopy(zodiacNames
, fShortZodiacNames
, count
);
895 fShortZodiacNamesCount
= count
;
899 //------------------------------------------------------
902 DateFormatSymbols::setEras(const UnicodeString
* erasArray
, int32_t count
)
904 // delete the old list if we own it
908 // we always own the new list, which we create here (we duplicate rather
909 // than adopting the list passed in)
910 fEras
= newUnicodeStringArray(count
);
911 uprv_arrayCopy(erasArray
,fEras
, count
);
916 DateFormatSymbols::setEraNames(const UnicodeString
* eraNamesArray
, int32_t count
)
918 // delete the old list if we own it
922 // we always own the new list, which we create here (we duplicate rather
923 // than adopting the list passed in)
924 fEraNames
= newUnicodeStringArray(count
);
925 uprv_arrayCopy(eraNamesArray
,fEraNames
, count
);
926 fEraNamesCount
= count
;
930 DateFormatSymbols::setNarrowEras(const UnicodeString
* narrowErasArray
, int32_t count
)
932 // delete the old list if we own it
934 delete[] fNarrowEras
;
936 // we always own the new list, which we create here (we duplicate rather
937 // than adopting the list passed in)
938 fNarrowEras
= newUnicodeStringArray(count
);
939 uprv_arrayCopy(narrowErasArray
,fNarrowEras
, count
);
940 fNarrowErasCount
= count
;
944 DateFormatSymbols::setMonths(const UnicodeString
* monthsArray
, int32_t count
)
946 // delete the old list if we own it
950 // we always own the new list, which we create here (we duplicate rather
951 // than adopting the list passed in)
952 fMonths
= newUnicodeStringArray(count
);
953 uprv_arrayCopy( monthsArray
,fMonths
,count
);
954 fMonthsCount
= count
;
958 DateFormatSymbols::setShortMonths(const UnicodeString
* shortMonthsArray
, int32_t count
)
960 // delete the old list if we own it
962 delete[] fShortMonths
;
964 // we always own the new list, which we create here (we duplicate rather
965 // than adopting the list passed in)
966 fShortMonths
= newUnicodeStringArray(count
);
967 uprv_arrayCopy(shortMonthsArray
,fShortMonths
, count
);
968 fShortMonthsCount
= count
;
972 DateFormatSymbols::setMonths(const UnicodeString
* monthsArray
, int32_t count
, DtContextType context
, DtWidthType width
)
974 // delete the old list if we own it
975 // we always own the new list, which we create here (we duplicate rather
976 // than adopting the list passed in)
984 fMonths
= newUnicodeStringArray(count
);
985 uprv_arrayCopy( monthsArray
,fMonths
,count
);
986 fMonthsCount
= count
;
990 delete[] fShortMonths
;
991 fShortMonths
= newUnicodeStringArray(count
);
992 uprv_arrayCopy( monthsArray
,fShortMonths
,count
);
993 fShortMonthsCount
= count
;
997 delete[] fNarrowMonths
;
998 fNarrowMonths
= newUnicodeStringArray(count
);
999 uprv_arrayCopy( monthsArray
,fNarrowMonths
,count
);
1000 fNarrowMonthsCount
= count
;
1009 if (fStandaloneMonths
)
1010 delete[] fStandaloneMonths
;
1011 fStandaloneMonths
= newUnicodeStringArray(count
);
1012 uprv_arrayCopy( monthsArray
,fStandaloneMonths
,count
);
1013 fStandaloneMonthsCount
= count
;
1016 if (fStandaloneShortMonths
)
1017 delete[] fStandaloneShortMonths
;
1018 fStandaloneShortMonths
= newUnicodeStringArray(count
);
1019 uprv_arrayCopy( monthsArray
,fStandaloneShortMonths
,count
);
1020 fStandaloneShortMonthsCount
= count
;
1023 if (fStandaloneNarrowMonths
)
1024 delete[] fStandaloneNarrowMonths
;
1025 fStandaloneNarrowMonths
= newUnicodeStringArray(count
);
1026 uprv_arrayCopy( monthsArray
,fStandaloneNarrowMonths
,count
);
1027 fStandaloneNarrowMonthsCount
= count
;
1033 case DT_CONTEXT_COUNT
:
1038 void DateFormatSymbols::setWeekdays(const UnicodeString
* weekdaysArray
, int32_t count
)
1040 // delete the old list if we own it
1044 // we always own the new list, which we create here (we duplicate rather
1045 // than adopting the list passed in)
1046 fWeekdays
= newUnicodeStringArray(count
);
1047 uprv_arrayCopy(weekdaysArray
,fWeekdays
,count
);
1048 fWeekdaysCount
= count
;
1052 DateFormatSymbols::setShortWeekdays(const UnicodeString
* shortWeekdaysArray
, int32_t count
)
1054 // delete the old list if we own it
1056 delete[] fShortWeekdays
;
1058 // we always own the new list, which we create here (we duplicate rather
1059 // than adopting the list passed in)
1060 fShortWeekdays
= newUnicodeStringArray(count
);
1061 uprv_arrayCopy(shortWeekdaysArray
, fShortWeekdays
, count
);
1062 fShortWeekdaysCount
= count
;
1066 DateFormatSymbols::setWeekdays(const UnicodeString
* weekdaysArray
, int32_t count
, DtContextType context
, DtWidthType width
)
1068 // delete the old list if we own it
1069 // we always own the new list, which we create here (we duplicate rather
1070 // than adopting the list passed in)
1078 fWeekdays
= newUnicodeStringArray(count
);
1079 uprv_arrayCopy(weekdaysArray
, fWeekdays
, count
);
1080 fWeekdaysCount
= count
;
1084 delete[] fShortWeekdays
;
1085 fShortWeekdays
= newUnicodeStringArray(count
);
1086 uprv_arrayCopy(weekdaysArray
, fShortWeekdays
, count
);
1087 fShortWeekdaysCount
= count
;
1090 if (fShorterWeekdays
)
1091 delete[] fShorterWeekdays
;
1092 fShorterWeekdays
= newUnicodeStringArray(count
);
1093 uprv_arrayCopy(weekdaysArray
, fShorterWeekdays
, count
);
1094 fShorterWeekdaysCount
= count
;
1097 if (fNarrowWeekdays
)
1098 delete[] fNarrowWeekdays
;
1099 fNarrowWeekdays
= newUnicodeStringArray(count
);
1100 uprv_arrayCopy(weekdaysArray
, fNarrowWeekdays
, count
);
1101 fNarrowWeekdaysCount
= count
;
1103 case DT_WIDTH_COUNT
:
1110 if (fStandaloneWeekdays
)
1111 delete[] fStandaloneWeekdays
;
1112 fStandaloneWeekdays
= newUnicodeStringArray(count
);
1113 uprv_arrayCopy(weekdaysArray
, fStandaloneWeekdays
, count
);
1114 fStandaloneWeekdaysCount
= count
;
1117 if (fStandaloneShortWeekdays
)
1118 delete[] fStandaloneShortWeekdays
;
1119 fStandaloneShortWeekdays
= newUnicodeStringArray(count
);
1120 uprv_arrayCopy(weekdaysArray
, fStandaloneShortWeekdays
, count
);
1121 fStandaloneShortWeekdaysCount
= count
;
1124 if (fStandaloneShorterWeekdays
)
1125 delete[] fStandaloneShorterWeekdays
;
1126 fStandaloneShorterWeekdays
= newUnicodeStringArray(count
);
1127 uprv_arrayCopy(weekdaysArray
, fStandaloneShorterWeekdays
, count
);
1128 fStandaloneShorterWeekdaysCount
= count
;
1131 if (fStandaloneNarrowWeekdays
)
1132 delete[] fStandaloneNarrowWeekdays
;
1133 fStandaloneNarrowWeekdays
= newUnicodeStringArray(count
);
1134 uprv_arrayCopy(weekdaysArray
, fStandaloneNarrowWeekdays
, count
);
1135 fStandaloneNarrowWeekdaysCount
= count
;
1137 case DT_WIDTH_COUNT
:
1141 case DT_CONTEXT_COUNT
:
1147 DateFormatSymbols::setQuarters(const UnicodeString
* quartersArray
, int32_t count
, DtContextType context
, DtWidthType width
)
1149 // delete the old list if we own it
1150 // we always own the new list, which we create here (we duplicate rather
1151 // than adopting the list passed in)
1159 fQuarters
= newUnicodeStringArray(count
);
1160 uprv_arrayCopy( quartersArray
,fQuarters
,count
);
1161 fQuartersCount
= count
;
1165 delete[] fShortQuarters
;
1166 fShortQuarters
= newUnicodeStringArray(count
);
1167 uprv_arrayCopy( quartersArray
,fShortQuarters
,count
);
1168 fShortQuartersCount
= count
;
1172 if (fNarrowQuarters)
1173 delete[] fNarrowQuarters;
1174 fNarrowQuarters = newUnicodeStringArray(count);
1175 uprv_arrayCopy( quartersArray,fNarrowQuarters,count);
1176 fNarrowQuartersCount = count;
1186 if (fStandaloneQuarters
)
1187 delete[] fStandaloneQuarters
;
1188 fStandaloneQuarters
= newUnicodeStringArray(count
);
1189 uprv_arrayCopy( quartersArray
,fStandaloneQuarters
,count
);
1190 fStandaloneQuartersCount
= count
;
1193 if (fStandaloneShortQuarters
)
1194 delete[] fStandaloneShortQuarters
;
1195 fStandaloneShortQuarters
= newUnicodeStringArray(count
);
1196 uprv_arrayCopy( quartersArray
,fStandaloneShortQuarters
,count
);
1197 fStandaloneShortQuartersCount
= count
;
1201 if (fStandaloneNarrowQuarters)
1202 delete[] fStandaloneNarrowQuarters;
1203 fStandaloneNarrowQuarters = newUnicodeStringArray(count);
1204 uprv_arrayCopy( quartersArray,fStandaloneNarrowQuarters,count);
1205 fStandaloneNarrowQuartersCount = count;
1212 case DT_CONTEXT_COUNT
:
1218 DateFormatSymbols::setAmPmStrings(const UnicodeString
* amPmsArray
, int32_t count
)
1220 // delete the old list if we own it
1221 if (fAmPms
) delete[] fAmPms
;
1223 // we always own the new list, which we create here (we duplicate rather
1224 // than adopting the list passed in)
1225 fAmPms
= newUnicodeStringArray(count
);
1226 uprv_arrayCopy(amPmsArray
,fAmPms
,count
);
1227 fAmPmsCount
= count
;
1231 DateFormatSymbols::setTimeSeparatorString(const UnicodeString
& newTimeSeparator
)
1233 fTimeSeparator
= newTimeSeparator
;
1236 const UnicodeString
**
1237 DateFormatSymbols::getZoneStrings(int32_t& rowCount
, int32_t& columnCount
) const
1239 const UnicodeString
**result
= NULL
;
1242 if (fZoneStrings
== NULL
) {
1243 if (fLocaleZoneStrings
== NULL
) {
1244 ((DateFormatSymbols
*)this)->initZoneStringsArray();
1246 result
= (const UnicodeString
**)fLocaleZoneStrings
;
1248 result
= (const UnicodeString
**)fZoneStrings
;
1250 rowCount
= fZoneStringsRowCount
;
1251 columnCount
= fZoneStringsColCount
;
1257 // For now, we include all zones
1258 #define ZONE_SET UCAL_ZONE_TYPE_ANY
1260 // This code must be called within a synchronized block
1262 DateFormatSymbols::initZoneStringsArray(void) {
1263 if (fZoneStrings
!= NULL
|| fLocaleZoneStrings
!= NULL
) {
1267 UErrorCode status
= U_ZERO_ERROR
;
1269 StringEnumeration
*tzids
= NULL
;
1270 UnicodeString
** zarray
= NULL
;
1271 TimeZoneNames
*tzNames
= NULL
;
1274 do { // dummy do-while
1276 tzids
= TimeZone::createTimeZoneIDEnumeration(ZONE_SET
, NULL
, NULL
, status
);
1277 rows
= tzids
->count(status
);
1278 if (U_FAILURE(status
)) {
1283 int32_t size
= rows
* sizeof(UnicodeString
*);
1284 zarray
= (UnicodeString
**)uprv_malloc(size
);
1285 if (zarray
== NULL
) {
1286 status
= U_MEMORY_ALLOCATION_ERROR
;
1289 uprv_memset(zarray
, 0, size
);
1291 tzNames
= TimeZoneNames::createInstance(fZSFLocale
, status
);
1293 const UnicodeString
*tzid
;
1295 UDate now
= Calendar::getNow();
1296 UnicodeString tzDispName
;
1298 while ((tzid
= tzids
->snext(status
))) {
1299 if (U_FAILURE(status
)) {
1303 zarray
[i
] = new UnicodeString
[5];
1304 if (zarray
[i
] == NULL
) {
1305 status
= U_MEMORY_ALLOCATION_ERROR
;
1309 zarray
[i
][0].setTo(*tzid
);
1310 zarray
[i
][1].setTo(tzNames
->getDisplayName(*tzid
, UTZNM_LONG_STANDARD
, now
, tzDispName
));
1311 zarray
[i
][2].setTo(tzNames
->getDisplayName(*tzid
, UTZNM_SHORT_STANDARD
, now
, tzDispName
));
1312 zarray
[i
][3].setTo(tzNames
->getDisplayName(*tzid
, UTZNM_LONG_DAYLIGHT
, now
, tzDispName
));
1313 zarray
[i
][4].setTo(tzNames
->getDisplayName(*tzid
, UTZNM_SHORT_DAYLIGHT
, now
, tzDispName
));
1319 if (U_FAILURE(status
)) {
1321 for (int32_t i
= 0; i
< rows
; i
++) {
1337 fLocaleZoneStrings
= zarray
;
1338 fZoneStringsRowCount
= rows
;
1339 fZoneStringsColCount
= 5;
1343 DateFormatSymbols::setZoneStrings(const UnicodeString
* const *strings
, int32_t rowCount
, int32_t columnCount
)
1345 // since deleting a 2-d array is a pain in the butt, we offload that task to
1346 // a separate function
1347 disposeZoneStrings();
1348 // we always own the new list, which we create here (we duplicate rather
1349 // than adopting the list passed in)
1350 fZoneStringsRowCount
= rowCount
;
1351 fZoneStringsColCount
= columnCount
;
1352 createZoneStrings((const UnicodeString
**)strings
);
1355 //------------------------------------------------------
1357 const UChar
* U_EXPORT2
1358 DateFormatSymbols::getPatternUChars(void)
1360 return gPatternChars
;
1363 UDateFormatField U_EXPORT2
1364 DateFormatSymbols::getPatternCharIndex(UChar c
) {
1365 const UChar
*p
= u_strchr(gPatternChars
, c
);
1367 return UDAT_FIELD_COUNT
;
1369 return static_cast<UDateFormatField
>(p
- gPatternChars
);
1373 static const uint64_t kNumericFieldsAlways
=
1374 ((uint64_t)1 << UDAT_YEAR_FIELD
) | // y
1375 ((uint64_t)1 << UDAT_DATE_FIELD
) | // d
1376 ((uint64_t)1 << UDAT_HOUR_OF_DAY1_FIELD
) | // k
1377 ((uint64_t)1 << UDAT_HOUR_OF_DAY0_FIELD
) | // H
1378 ((uint64_t)1 << UDAT_MINUTE_FIELD
) | // m
1379 ((uint64_t)1 << UDAT_SECOND_FIELD
) | // s
1380 ((uint64_t)1 << UDAT_FRACTIONAL_SECOND_FIELD
) | // S
1381 ((uint64_t)1 << UDAT_DAY_OF_YEAR_FIELD
) | // D
1382 ((uint64_t)1 << UDAT_DAY_OF_WEEK_IN_MONTH_FIELD
) | // F
1383 ((uint64_t)1 << UDAT_WEEK_OF_YEAR_FIELD
) | // w
1384 ((uint64_t)1 << UDAT_WEEK_OF_MONTH_FIELD
) | // W
1385 ((uint64_t)1 << UDAT_HOUR1_FIELD
) | // h
1386 ((uint64_t)1 << UDAT_HOUR0_FIELD
) | // K
1387 ((uint64_t)1 << UDAT_YEAR_WOY_FIELD
) | // Y
1388 ((uint64_t)1 << UDAT_EXTENDED_YEAR_FIELD
) | // u
1389 ((uint64_t)1 << UDAT_JULIAN_DAY_FIELD
) | // g
1390 ((uint64_t)1 << UDAT_MILLISECONDS_IN_DAY_FIELD
) | // A
1391 ((uint64_t)1 << UDAT_RELATED_YEAR_FIELD
); // r
1393 static const uint64_t kNumericFieldsForCount12
=
1394 ((uint64_t)1 << UDAT_MONTH_FIELD
) | // M or MM
1395 ((uint64_t)1 << UDAT_DOW_LOCAL_FIELD
) | // e or ee
1396 ((uint64_t)1 << UDAT_STANDALONE_DAY_FIELD
) | // c or cc
1397 ((uint64_t)1 << UDAT_STANDALONE_MONTH_FIELD
) | // L or LL
1398 ((uint64_t)1 << UDAT_QUARTER_FIELD
) | // Q or QQ
1399 ((uint64_t)1 << UDAT_STANDALONE_QUARTER_FIELD
); // q or qq
1402 DateFormatSymbols::isNumericField(UDateFormatField f
, int32_t count
) {
1403 if (f
== UDAT_FIELD_COUNT
) {
1406 uint64_t flag
= ((uint64_t)1 << f
);
1407 return ((kNumericFieldsAlways
& flag
) != 0 || ((kNumericFieldsForCount12
& flag
) != 0 && count
< 3));
1411 DateFormatSymbols::isNumericPatternChar(UChar c
, int32_t count
) {
1412 return isNumericField(getPatternCharIndex(c
), count
);
1415 //------------------------------------------------------
1418 DateFormatSymbols::getLocalPatternChars(UnicodeString
& result
) const
1420 // fastCopyFrom() - see assignArray comments
1421 return result
.fastCopyFrom(fLocalPatternChars
);
1424 //------------------------------------------------------
1427 DateFormatSymbols::setLocalPatternChars(const UnicodeString
& newLocalPatternChars
)
1429 fLocalPatternChars
= newLocalPatternChars
;
1432 //------------------------------------------------------
1435 initField(UnicodeString
**field
, int32_t& length
, const UResourceBundle
*data
, UErrorCode
&status
) {
1436 if (U_SUCCESS(status
)) {
1438 length
= ures_getSize(data
);
1439 *field
= newUnicodeStringArray(length
);
1441 for(int32_t i
= 0; i
<length
; i
++) {
1442 const UChar
*resStr
= ures_getStringByIndex(data
, i
, &strLen
, &status
);
1443 // setTo() - see assignArray comments
1444 (*(field
)+i
)->setTo(TRUE
, resStr
, strLen
);
1449 status
= U_MEMORY_ALLOCATION_ERROR
;
1455 initField(UnicodeString
**field
, int32_t& length
, const UChar
*data
, LastResortSize numStr
, LastResortSize strLen
, UErrorCode
&status
) {
1456 if (U_SUCCESS(status
)) {
1458 *field
= newUnicodeStringArray((size_t)numStr
);
1460 for(int32_t i
= 0; i
<length
; i
++) {
1461 // readonly aliases - all "data" strings are constant
1462 // -1 as length for variable-length strings (gLastResortDayNames[0] is empty)
1463 (*(field
)+i
)->setTo(TRUE
, data
+(i
*((int32_t)strLen
)), -1);
1468 status
= U_MEMORY_ALLOCATION_ERROR
;
1474 initLeapMonthPattern(UnicodeString
*field
, int32_t index
, const UResourceBundle
*data
, UErrorCode
&status
) {
1475 field
[index
].remove();
1476 if (U_SUCCESS(status
)) {
1478 const UChar
*resStr
= ures_getStringByKey(data
, gNamesLeapTag
, &strLen
, &status
);
1479 if (U_SUCCESS(status
)) {
1480 field
[index
].setTo(TRUE
, resStr
, strLen
);
1483 status
= U_ZERO_ERROR
;
1487 const char * usageTypeName
;
1488 DateFormatSymbols::ECapitalizationContextUsageType usageTypeEnumValue
;
1489 } ContextUsageTypeNameToEnumValue
;
1491 static const ContextUsageTypeNameToEnumValue contextUsageTypeMap
[] = {
1492 // Entries must be sorted by usageTypeName; entry with NULL name terminates list.
1493 { "day-format-except-narrow", DateFormatSymbols::kCapContextUsageDayFormat
},
1494 { "day-narrow", DateFormatSymbols::kCapContextUsageDayNarrow
},
1495 { "day-standalone-except-narrow", DateFormatSymbols::kCapContextUsageDayStandalone
},
1496 { "era-abbr", DateFormatSymbols::kCapContextUsageEraAbbrev
},
1497 { "era-name", DateFormatSymbols::kCapContextUsageEraWide
},
1498 { "era-narrow", DateFormatSymbols::kCapContextUsageEraNarrow
},
1499 { "metazone-long", DateFormatSymbols::kCapContextUsageMetazoneLong
},
1500 { "metazone-short", DateFormatSymbols::kCapContextUsageMetazoneShort
},
1501 { "month-format-except-narrow", DateFormatSymbols::kCapContextUsageMonthFormat
},
1502 { "month-narrow", DateFormatSymbols::kCapContextUsageMonthNarrow
},
1503 { "month-standalone-except-narrow", DateFormatSymbols::kCapContextUsageMonthStandalone
},
1504 { "zone-long", DateFormatSymbols::kCapContextUsageZoneLong
},
1505 { "zone-short", DateFormatSymbols::kCapContextUsageZoneShort
},
1506 { NULL
, (DateFormatSymbols::ECapitalizationContextUsageType
)0 },
1509 // Resource keys to look up localized strings for day periods.
1510 // The first one must be midnight and the second must be noon, so that their indices coincide
1511 // with the am/pm field. Formatting and parsing code for day periods relies on this coincidence.
1512 static const char *dayPeriodKeys
[] = {"midnight", "noon",
1513 "morning1", "afternoon1", "evening1", "night1",
1514 "morning2", "afternoon2", "evening2", "night2"};
1516 UnicodeString
* loadDayPeriodStrings(CalendarData
&calData
, const char *tag
, UBool standalone
,
1517 int32_t &stringCount
, UErrorCode
&status
) {
1518 if (U_FAILURE(status
)) {
1522 UResourceBundle
*dayPeriodData
;
1525 dayPeriodData
= calData
.getByKey3(gDayPeriodTag
, gNamesStandaloneTag
, tag
, status
);
1527 dayPeriodData
= calData
.getByKey2(gDayPeriodTag
, tag
, status
);
1530 stringCount
= UPRV_LENGTHOF(dayPeriodKeys
);
1531 UnicodeString
*strings
= new UnicodeString
[stringCount
];
1532 for (int32_t i
= 0; i
< stringCount
; ++i
) {
1533 //TODO: Check if there are fallbacks/aliases defined in the data; e.g., if there
1534 //is no wide string, then use the narrow one?
1535 strings
[i
].fastCopyFrom(ures_getUnicodeStringByKey(dayPeriodData
, dayPeriodKeys
[i
], &status
));
1536 if (U_FAILURE(status
)) {
1537 // string[i] will be bogus if ures_getUnicodeString() returns with an error,
1538 // which is just the behavior we want. Simply reset the error code.
1539 status
= U_ZERO_ERROR
;
1546 DateFormatSymbols::initializeData(const Locale
& locale
, const char *type
, UErrorCode
& status
, UBool useLastResortData
)
1550 const UChar
*resStr
;
1551 /* In case something goes wrong, initialize all of the data to NULL. */
1557 fNarrowErasCount
= 0;
1560 fShortMonths
= NULL
;
1561 fShortMonthsCount
=0;
1562 fNarrowMonths
= NULL
;
1563 fNarrowMonthsCount
=0;
1564 fStandaloneMonths
= NULL
;
1565 fStandaloneMonthsCount
=0;
1566 fStandaloneShortMonths
= NULL
;
1567 fStandaloneShortMonthsCount
=0;
1568 fStandaloneNarrowMonths
= NULL
;
1569 fStandaloneNarrowMonthsCount
=0;
1572 fShortWeekdays
= NULL
;
1573 fShortWeekdaysCount
=0;
1574 fShorterWeekdays
= NULL
;
1575 fShorterWeekdaysCount
=0;
1576 fNarrowWeekdays
= NULL
;
1577 fNarrowWeekdaysCount
=0;
1578 fStandaloneWeekdays
= NULL
;
1579 fStandaloneWeekdaysCount
=0;
1580 fStandaloneShortWeekdays
= NULL
;
1581 fStandaloneShortWeekdaysCount
=0;
1582 fStandaloneShorterWeekdays
= NULL
;
1583 fStandaloneShorterWeekdaysCount
=0;
1584 fStandaloneNarrowWeekdays
= NULL
;
1585 fStandaloneNarrowWeekdaysCount
=0;
1588 fNarrowAmPms
= NULL
;
1589 fNarrowAmPmsCount
=0;
1590 fTimeSeparator
.setToBogus();
1593 fShortQuarters
= NULL
;
1594 fShortQuartersCount
= 0;
1595 fStandaloneQuarters
= NULL
;
1596 fStandaloneQuartersCount
= 0;
1597 fStandaloneShortQuarters
= NULL
;
1598 fStandaloneShortQuartersCount
= 0;
1599 fLeapMonthPatterns
= NULL
;
1600 fLeapMonthPatternsCount
= 0;
1601 fShortYearNames
= NULL
;
1602 fShortYearNamesCount
= 0;
1603 fShortZodiacNames
= NULL
;
1604 fShortZodiacNamesCount
= 0;
1605 fZoneStringsRowCount
= 0;
1606 fZoneStringsColCount
= 0;
1607 fZoneStrings
= NULL
;
1608 fLocaleZoneStrings
= NULL
;
1609 fAbbreviatedDayPeriods
= NULL
;
1610 fAbbreviatedDayPeriodsCount
= 0;
1611 fWideDayPeriods
= NULL
;
1612 fWideDayPeriodsCount
= 0;
1613 fNarrowDayPeriods
= NULL
;
1614 fNarrowDayPeriodsCount
= 0;
1615 fStandaloneAbbreviatedDayPeriods
= NULL
;
1616 fStandaloneAbbreviatedDayPeriodsCount
= 0;
1617 fStandaloneWideDayPeriods
= NULL
;
1618 fStandaloneWideDayPeriodsCount
= 0;
1619 fStandaloneNarrowDayPeriods
= NULL
;
1620 fStandaloneNarrowDayPeriodsCount
= 0;
1621 uprv_memset(fCapitalization
, 0, sizeof(fCapitalization
));
1623 // We need to preserve the requested locale for
1624 // lazy ZoneStringFormat instantiation. ZoneStringFormat
1625 // is region sensitive, thus, bundle locale bundle's locale
1626 // is not sufficient.
1627 fZSFLocale
= locale
;
1629 if (U_FAILURE(status
)) return;
1632 * Retrieve the string arrays we need from the resource bundle file.
1633 * We cast away const here, but that's okay; we won't delete any of
1636 CalendarData
calData(locale
, type
, status
);
1638 // load the first data item
1639 UResourceBundle
*erasMain
= calData
.getByKey(gErasTag
, status
);
1640 UResourceBundle
*eras
= ures_getByKeyWithFallback(erasMain
, gNamesAbbrTag
, NULL
, &status
);
1641 UErrorCode oldStatus
= status
;
1642 UResourceBundle
*eraNames
= ures_getByKeyWithFallback(erasMain
, gNamesWideTag
, NULL
, &status
);
1643 if ( status
== U_MISSING_RESOURCE_ERROR
) { // Workaround because eras/wide was omitted from CLDR 1.3
1645 eraNames
= ures_getByKeyWithFallback(erasMain
, gNamesAbbrTag
, NULL
, &status
);
1647 // current ICU4J falls back to abbreviated if narrow eras are missing, so we will too
1649 UResourceBundle
*narrowEras
= ures_getByKeyWithFallback(erasMain
, gNamesNarrowTag
, NULL
, &status
);
1650 if ( status
== U_MISSING_RESOURCE_ERROR
) {
1652 narrowEras
= ures_getByKeyWithFallback(erasMain
, gNamesAbbrTag
, NULL
, &status
);
1655 UErrorCode tempStatus
= U_ZERO_ERROR
;
1656 UResourceBundle
*monthPatterns
= calData
.getByKey(gMonthPatternsTag
, tempStatus
);
1657 if (U_SUCCESS(tempStatus
) && monthPatterns
!= NULL
) {
1658 fLeapMonthPatterns
= newUnicodeStringArray(kMonthPatternsCount
);
1659 if (fLeapMonthPatterns
) {
1660 initLeapMonthPattern(fLeapMonthPatterns
, kLeapMonthPatternFormatWide
, calData
.getByKey2(gMonthPatternsTag
, gNamesWideTag
, tempStatus
), tempStatus
);
1661 initLeapMonthPattern(fLeapMonthPatterns
, kLeapMonthPatternFormatAbbrev
, calData
.getByKey2(gMonthPatternsTag
, gNamesAbbrTag
, tempStatus
), tempStatus
);
1662 initLeapMonthPattern(fLeapMonthPatterns
, kLeapMonthPatternFormatNarrow
, calData
.getByKey2(gMonthPatternsTag
, gNamesNarrowTag
, tempStatus
), tempStatus
);
1663 initLeapMonthPattern(fLeapMonthPatterns
, kLeapMonthPatternStandaloneWide
, calData
.getByKey3(gMonthPatternsTag
, gNamesStandaloneTag
, gNamesWideTag
, tempStatus
), tempStatus
);
1664 initLeapMonthPattern(fLeapMonthPatterns
, kLeapMonthPatternStandaloneAbbrev
, calData
.getByKey3(gMonthPatternsTag
, gNamesStandaloneTag
, gNamesAbbrTag
, tempStatus
), tempStatus
);
1665 initLeapMonthPattern(fLeapMonthPatterns
, kLeapMonthPatternStandaloneNarrow
, calData
.getByKey3(gMonthPatternsTag
, gNamesStandaloneTag
, gNamesNarrowTag
, tempStatus
), tempStatus
);
1666 initLeapMonthPattern(fLeapMonthPatterns
, kLeapMonthPatternNumeric
, calData
.getByKey3(gMonthPatternsTag
, gNamesNumericTag
, gNamesAllTag
, tempStatus
), tempStatus
);
1667 if (U_SUCCESS(tempStatus
)) {
1668 // Hack to fix bad C inheritance for dangi monthPatterns (OK in J); this should be handled by aliases in root, but isn't.
1669 // The ordering of the following statements is important.
1670 if (fLeapMonthPatterns
[kLeapMonthPatternFormatAbbrev
].isEmpty()) {
1671 fLeapMonthPatterns
[kLeapMonthPatternFormatAbbrev
].setTo(fLeapMonthPatterns
[kLeapMonthPatternFormatWide
]);
1673 if (fLeapMonthPatterns
[kLeapMonthPatternFormatNarrow
].isEmpty()) {
1674 fLeapMonthPatterns
[kLeapMonthPatternFormatNarrow
].setTo(fLeapMonthPatterns
[kLeapMonthPatternStandaloneNarrow
]);
1676 if (fLeapMonthPatterns
[kLeapMonthPatternStandaloneWide
].isEmpty()) {
1677 fLeapMonthPatterns
[kLeapMonthPatternStandaloneWide
].setTo(fLeapMonthPatterns
[kLeapMonthPatternFormatWide
]);
1679 if (fLeapMonthPatterns
[kLeapMonthPatternStandaloneAbbrev
].isEmpty()) {
1680 fLeapMonthPatterns
[kLeapMonthPatternStandaloneAbbrev
].setTo(fLeapMonthPatterns
[kLeapMonthPatternFormatAbbrev
]);
1683 fLeapMonthPatternsCount
= kMonthPatternsCount
;
1685 delete[] fLeapMonthPatterns
;
1686 fLeapMonthPatterns
= NULL
;
1691 tempStatus
= U_ZERO_ERROR
;
1692 UResourceBundle
*cyclicNameSets
= calData
.getByKey(gCyclicNameSetsTag
, tempStatus
);
1693 if (U_SUCCESS(tempStatus
) && cyclicNameSets
!= NULL
) {
1694 UResourceBundle
*nameSetYears
= ures_getByKeyWithFallback(cyclicNameSets
, gNameSetYearsTag
, NULL
, &tempStatus
);
1695 if (U_SUCCESS(tempStatus
)) {
1696 UResourceBundle
*nameSetYearsFmt
= ures_getByKeyWithFallback(nameSetYears
, gNamesFormatTag
, NULL
, &tempStatus
);
1697 if (U_SUCCESS(tempStatus
)) {
1698 UResourceBundle
*nameSetYearsFmtAbbrev
= ures_getByKeyWithFallback(nameSetYearsFmt
, gNamesAbbrTag
, NULL
, &tempStatus
);
1699 if (U_SUCCESS(tempStatus
)) {
1700 initField(&fShortYearNames
, fShortYearNamesCount
, nameSetYearsFmtAbbrev
, tempStatus
);
1701 ures_close(nameSetYearsFmtAbbrev
);
1703 ures_close(nameSetYearsFmt
);
1705 ures_close(nameSetYears
);
1707 UResourceBundle
*nameSetZodiacs
= ures_getByKeyWithFallback(cyclicNameSets
, gNameSetZodiacsTag
, NULL
, &tempStatus
);
1708 if (U_SUCCESS(tempStatus
)) {
1709 UResourceBundle
*nameSetZodiacsFmt
= ures_getByKeyWithFallback(nameSetZodiacs
, gNamesFormatTag
, NULL
, &tempStatus
);
1710 if (U_SUCCESS(tempStatus
)) {
1711 UResourceBundle
*nameSetZodiacsFmtAbbrev
= ures_getByKeyWithFallback(nameSetZodiacsFmt
, gNamesAbbrTag
, NULL
, &tempStatus
);
1712 if (U_SUCCESS(tempStatus
)) {
1713 initField(&fShortZodiacNames
, fShortZodiacNamesCount
, nameSetZodiacsFmtAbbrev
, tempStatus
);
1714 ures_close(nameSetZodiacsFmtAbbrev
);
1716 ures_close(nameSetZodiacsFmt
);
1718 ures_close(nameSetZodiacs
);
1722 tempStatus
= U_ZERO_ERROR
;
1723 UResourceBundle
*localeBundle
= ures_open(NULL
, locale
.getName(), &tempStatus
);
1724 if (U_SUCCESS(tempStatus
)) {
1725 UResourceBundle
*contextTransforms
= ures_getByKeyWithFallback(localeBundle
, gContextTransformsTag
, NULL
, &tempStatus
);
1726 if (U_SUCCESS(tempStatus
)) {
1727 UResourceBundle
*contextTransformUsage
;
1728 while ( (contextTransformUsage
= ures_getNextResource(contextTransforms
, NULL
, &tempStatus
)) != NULL
) {
1729 const int32_t * intVector
= ures_getIntVector(contextTransformUsage
, &len
, &status
);
1730 if (U_SUCCESS(tempStatus
) && intVector
!= NULL
&& len
>= 2) {
1731 const char* usageType
= ures_getKey(contextTransformUsage
);
1732 if (usageType
!= NULL
) {
1733 const ContextUsageTypeNameToEnumValue
* typeMapPtr
= contextUsageTypeMap
;
1734 int32_t compResult
= 0;
1735 // linear search; list is short and we cannot be sure that bsearch is available
1736 while ( typeMapPtr
->usageTypeName
!= NULL
&& (compResult
= uprv_strcmp(usageType
, typeMapPtr
->usageTypeName
)) > 0 ) {
1739 if (typeMapPtr
->usageTypeName
!= NULL
&& compResult
== 0) {
1740 fCapitalization
[typeMapPtr
->usageTypeEnumValue
][0] = intVector
[0];
1741 fCapitalization
[typeMapPtr
->usageTypeEnumValue
][1] = intVector
[1];
1745 tempStatus
= U_ZERO_ERROR
;
1746 ures_close(contextTransformUsage
);
1748 ures_close(contextTransforms
);
1751 tempStatus
= U_ZERO_ERROR
;
1752 const LocalPointer
<NumberingSystem
> numberingSystem(
1753 NumberingSystem::createInstance(locale
, tempStatus
), tempStatus
);
1754 if (U_SUCCESS(tempStatus
)) {
1755 // These functions all fail gracefully if passed NULL pointers and
1756 // do nothing unless U_SUCCESS(tempStatus), so it's only necessary
1757 // to check for errors once after all calls are made.
1758 const LocalUResourceBundlePointer
numberElementsData(ures_getByKeyWithFallback(
1759 localeBundle
, gNumberElementsTag
, NULL
, &tempStatus
));
1760 const LocalUResourceBundlePointer
nsNameData(ures_getByKeyWithFallback(
1761 numberElementsData
.getAlias(), numberingSystem
->getName(), NULL
, &tempStatus
));
1762 const LocalUResourceBundlePointer
symbolsData(ures_getByKeyWithFallback(
1763 nsNameData
.getAlias(), gSymbolsTag
, NULL
, &tempStatus
));
1764 fTimeSeparator
= ures_getUnicodeStringByKey(
1765 symbolsData
.getAlias(), gTimeSeparatorTag
, &tempStatus
);
1766 if (U_FAILURE(tempStatus
)) {
1767 fTimeSeparator
.setToBogus();
1771 ures_close(localeBundle
);
1774 if (fTimeSeparator
.isBogus()) {
1775 fTimeSeparator
.setTo(DateFormatSymbols::DEFAULT_TIME_SEPARATOR
);
1778 fWideDayPeriods
= loadDayPeriodStrings(calData
, gNamesWideTag
, FALSE
,
1779 fWideDayPeriodsCount
, status
);
1780 fNarrowDayPeriods
= loadDayPeriodStrings(calData
, gNamesNarrowTag
, FALSE
,
1781 fNarrowDayPeriodsCount
, status
);
1782 fAbbreviatedDayPeriods
= loadDayPeriodStrings(calData
, gNamesAbbrTag
, FALSE
,
1783 fAbbreviatedDayPeriodsCount
, status
);
1784 fStandaloneWideDayPeriods
= loadDayPeriodStrings(calData
, gNamesWideTag
, TRUE
,
1785 fStandaloneWideDayPeriodsCount
, status
);
1786 fStandaloneNarrowDayPeriods
= loadDayPeriodStrings(calData
, gNamesNarrowTag
, TRUE
,
1787 fStandaloneNarrowDayPeriodsCount
, status
);
1788 fStandaloneAbbreviatedDayPeriods
= loadDayPeriodStrings(calData
, gNamesAbbrTag
, TRUE
,
1789 fStandaloneAbbreviatedDayPeriodsCount
, status
);
1791 UResourceBundle
*weekdaysData
= NULL
; // Data closed by calData
1792 UResourceBundle
*abbrWeekdaysData
= NULL
; // Data closed by calData
1793 UResourceBundle
*shorterWeekdaysData
= NULL
; // Data closed by calData
1794 UResourceBundle
*narrowWeekdaysData
= NULL
; // Data closed by calData
1795 UResourceBundle
*standaloneWeekdaysData
= NULL
; // Data closed by calData
1796 UResourceBundle
*standaloneAbbrWeekdaysData
= NULL
; // Data closed by calData
1797 UResourceBundle
*standaloneShorterWeekdaysData
= NULL
; // Data closed by calData
1798 UResourceBundle
*standaloneNarrowWeekdaysData
= NULL
; // Data closed by calData
1800 U_LOCALE_BASED(locBased
, *this);
1801 if (U_FAILURE(status
))
1803 if (useLastResortData
)
1805 // Handle the case in which there is no resource data present.
1806 // We don't have to generate usable patterns in this situation;
1807 // we just need to produce something that will be semi-intelligible
1810 status
= U_USING_FALLBACK_WARNING
;
1812 initField(&fEras
, fErasCount
, (const UChar
*)gLastResortEras
, kEraNum
, kEraLen
, status
);
1813 initField(&fEraNames
, fEraNamesCount
, (const UChar
*)gLastResortEras
, kEraNum
, kEraLen
, status
);
1814 initField(&fNarrowEras
, fNarrowErasCount
, (const UChar
*)gLastResortEras
, kEraNum
, kEraLen
, status
);
1815 initField(&fMonths
, fMonthsCount
, (const UChar
*)gLastResortMonthNames
, kMonthNum
, kMonthLen
, status
);
1816 initField(&fShortMonths
, fShortMonthsCount
, (const UChar
*)gLastResortMonthNames
, kMonthNum
, kMonthLen
, status
);
1817 initField(&fNarrowMonths
, fNarrowMonthsCount
, (const UChar
*)gLastResortMonthNames
, kMonthNum
, kMonthLen
, status
);
1818 initField(&fStandaloneMonths
, fStandaloneMonthsCount
, (const UChar
*)gLastResortMonthNames
, kMonthNum
, kMonthLen
, status
);
1819 initField(&fStandaloneShortMonths
, fStandaloneShortMonthsCount
, (const UChar
*)gLastResortMonthNames
, kMonthNum
, kMonthLen
, status
);
1820 initField(&fStandaloneNarrowMonths
, fStandaloneNarrowMonthsCount
, (const UChar
*)gLastResortMonthNames
, kMonthNum
, kMonthLen
, status
);
1821 initField(&fWeekdays
, fWeekdaysCount
, (const UChar
*)gLastResortDayNames
, kDayNum
, kDayLen
, status
);
1822 initField(&fShortWeekdays
, fShortWeekdaysCount
, (const UChar
*)gLastResortDayNames
, kDayNum
, kDayLen
, status
);
1823 initField(&fShorterWeekdays
, fShorterWeekdaysCount
, (const UChar
*)gLastResortDayNames
, kDayNum
, kDayLen
, status
);
1824 initField(&fNarrowWeekdays
, fNarrowWeekdaysCount
, (const UChar
*)gLastResortDayNames
, kDayNum
, kDayLen
, status
);
1825 initField(&fStandaloneWeekdays
, fStandaloneWeekdaysCount
, (const UChar
*)gLastResortDayNames
, kDayNum
, kDayLen
, status
);
1826 initField(&fStandaloneShortWeekdays
, fStandaloneShortWeekdaysCount
, (const UChar
*)gLastResortDayNames
, kDayNum
, kDayLen
, status
);
1827 initField(&fStandaloneShorterWeekdays
, fStandaloneShorterWeekdaysCount
, (const UChar
*)gLastResortDayNames
, kDayNum
, kDayLen
, status
);
1828 initField(&fStandaloneNarrowWeekdays
, fStandaloneNarrowWeekdaysCount
, (const UChar
*)gLastResortDayNames
, kDayNum
, kDayLen
, status
);
1829 initField(&fAmPms
, fAmPmsCount
, (const UChar
*)gLastResortAmPmMarkers
, kAmPmNum
, kAmPmLen
, status
);
1830 initField(&fNarrowAmPms
, fNarrowAmPmsCount
, (const UChar
*)gLastResortAmPmMarkers
, kAmPmNum
, kAmPmLen
, status
);
1831 initField(&fQuarters
, fQuartersCount
, (const UChar
*)gLastResortQuarters
, kQuarterNum
, kQuarterLen
, status
);
1832 initField(&fShortQuarters
, fShortQuartersCount
, (const UChar
*)gLastResortQuarters
, kQuarterNum
, kQuarterLen
, status
);
1833 initField(&fStandaloneQuarters
, fStandaloneQuartersCount
, (const UChar
*)gLastResortQuarters
, kQuarterNum
, kQuarterLen
, status
);
1834 initField(&fStandaloneShortQuarters
, fStandaloneShortQuartersCount
, (const UChar
*)gLastResortQuarters
, kQuarterNum
, kQuarterLen
, status
);
1835 fLocalPatternChars
.setTo(TRUE
, gPatternChars
, PATTERN_CHARS_LEN
);
1840 // if we make it to here, the resource data is cool, and we can get everything out
1841 // of it that we need except for the time-zone and localized-pattern data, which
1842 // are stored in a separate file
1843 locBased
.setLocaleIDs(ures_getLocaleByType(eras
, ULOC_VALID_LOCALE
, &status
),
1844 ures_getLocaleByType(eras
, ULOC_ACTUAL_LOCALE
, &status
));
1846 initField(&fEras
, fErasCount
, eras
, status
);
1847 initField(&fEraNames
, fEraNamesCount
, eraNames
, status
);
1848 initField(&fNarrowEras
, fNarrowErasCount
, narrowEras
, status
);
1850 initField(&fMonths
, fMonthsCount
, calData
.getByKey2(gMonthNamesTag
, gNamesWideTag
, status
), status
);
1851 initField(&fShortMonths
, fShortMonthsCount
, calData
.getByKey2(gMonthNamesTag
, gNamesAbbrTag
, status
), status
);
1853 initField(&fNarrowMonths
, fNarrowMonthsCount
, calData
.getByKey2(gMonthNamesTag
, gNamesNarrowTag
, status
), status
);
1854 if(status
== U_MISSING_RESOURCE_ERROR
) {
1855 status
= U_ZERO_ERROR
;
1856 initField(&fNarrowMonths
, fNarrowMonthsCount
, calData
.getByKey3(gMonthNamesTag
, gNamesStandaloneTag
, gNamesNarrowTag
, status
), status
);
1858 if ( status
== U_MISSING_RESOURCE_ERROR
) { /* If format/narrow not available, use format/abbreviated */
1859 status
= U_ZERO_ERROR
;
1860 initField(&fNarrowMonths
, fNarrowMonthsCount
, calData
.getByKey2(gMonthNamesTag
, gNamesAbbrTag
, status
), status
);
1863 initField(&fStandaloneMonths
, fStandaloneMonthsCount
, calData
.getByKey3(gMonthNamesTag
, gNamesStandaloneTag
, gNamesWideTag
, status
), status
);
1864 if ( status
== U_MISSING_RESOURCE_ERROR
) { /* If standalone/wide not available, use format/wide */
1865 status
= U_ZERO_ERROR
;
1866 initField(&fStandaloneMonths
, fStandaloneMonthsCount
, calData
.getByKey2(gMonthNamesTag
, gNamesWideTag
, status
), status
);
1868 initField(&fStandaloneShortMonths
, fStandaloneShortMonthsCount
, calData
.getByKey3(gMonthNamesTag
, gNamesStandaloneTag
, gNamesAbbrTag
, status
), status
);
1869 if ( status
== U_MISSING_RESOURCE_ERROR
) { /* If standalone/abbreviated not available, use format/abbreviated */
1870 status
= U_ZERO_ERROR
;
1871 initField(&fStandaloneShortMonths
, fStandaloneShortMonthsCount
, calData
.getByKey2(gMonthNamesTag
, gNamesAbbrTag
, status
), status
);
1873 initField(&fStandaloneNarrowMonths
, fStandaloneNarrowMonthsCount
, calData
.getByKey3(gMonthNamesTag
, gNamesStandaloneTag
, gNamesNarrowTag
, status
), status
);
1874 if ( status
== U_MISSING_RESOURCE_ERROR
) { /* if standalone/narrow not availabe, try format/narrow */
1875 status
= U_ZERO_ERROR
;
1876 initField(&fStandaloneNarrowMonths
, fStandaloneNarrowMonthsCount
, calData
.getByKey2(gMonthNamesTag
, gNamesNarrowTag
, status
), status
);
1877 if ( status
== U_MISSING_RESOURCE_ERROR
) { /* if still not there, use format/abbreviated */
1878 status
= U_ZERO_ERROR
;
1879 initField(&fStandaloneNarrowMonths
, fStandaloneNarrowMonthsCount
, calData
.getByKey2(gMonthNamesTag
, gNamesAbbrTag
, status
), status
);
1882 initField(&fAmPms
, fAmPmsCount
, calData
.getByKey(gAmPmMarkersTag
, status
), status
);
1883 initField(&fNarrowAmPms
, fNarrowAmPmsCount
, calData
.getByKey(gAmPmMarkersNarrowTag
, status
), status
);
1885 initField(&fQuarters
, fQuartersCount
, calData
.getByKey2(gQuartersTag
, gNamesWideTag
, status
), status
);
1886 initField(&fShortQuarters
, fShortQuartersCount
, calData
.getByKey2(gQuartersTag
, gNamesAbbrTag
, status
), status
);
1888 initField(&fStandaloneQuarters
, fStandaloneQuartersCount
, calData
.getByKey3(gQuartersTag
, gNamesStandaloneTag
, gNamesWideTag
, status
), status
);
1889 if(status
== U_MISSING_RESOURCE_ERROR
) {
1890 status
= U_ZERO_ERROR
;
1891 initField(&fStandaloneQuarters
, fStandaloneQuartersCount
, calData
.getByKey2(gQuartersTag
, gNamesWideTag
, status
), status
);
1894 initField(&fStandaloneShortQuarters
, fStandaloneShortQuartersCount
, calData
.getByKey3(gQuartersTag
, gNamesStandaloneTag
, gNamesAbbrTag
, status
), status
);
1895 if(status
== U_MISSING_RESOURCE_ERROR
) {
1896 status
= U_ZERO_ERROR
;
1897 initField(&fStandaloneShortQuarters
, fStandaloneShortQuartersCount
, calData
.getByKey2(gQuartersTag
, gNamesAbbrTag
, status
), status
);
1900 // ICU 3.8 or later version no longer uses localized date-time pattern characters by default (ticket#5597)
1902 // fastCopyFrom()/setTo() - see assignArray comments
1903 resStr = ures_getStringByKey(fResourceBundle, gLocalPatternCharsTag, &len, &status);
1904 fLocalPatternChars.setTo(TRUE, resStr, len);
1905 // If the locale data does not include new pattern chars, use the defaults
1906 // TODO: Consider making this an error, since this may add conflicting characters.
1907 if (len < PATTERN_CHARS_LEN) {
1908 fLocalPatternChars.append(UnicodeString(TRUE, &gPatternChars[len], PATTERN_CHARS_LEN-len));
1911 fLocalPatternChars
.setTo(TRUE
, gPatternChars
, PATTERN_CHARS_LEN
);
1913 // Format wide weekdays -> fWeekdays
1914 // {sfb} fixed to handle 1-based weekdays
1915 weekdaysData
= calData
.getByKey2(gDayNamesTag
, gNamesWideTag
, status
);
1916 fWeekdaysCount
= ures_getSize(weekdaysData
);
1917 fWeekdays
= new UnicodeString
[fWeekdaysCount
+1];
1918 /* pin the blame on system. If we cannot get a chunk of memory .. the system is dying!*/
1919 if (fWeekdays
== NULL
) {
1920 status
= U_MEMORY_ALLOCATION_ERROR
;
1923 // leave fWeekdays[0] empty
1924 for(i
= 0; i
<fWeekdaysCount
; i
++) {
1925 resStr
= ures_getStringByIndex(weekdaysData
, i
, &len
, &status
);
1926 // setTo() - see assignArray comments
1927 fWeekdays
[i
+1].setTo(TRUE
, resStr
, len
);
1931 // Format abbreviated weekdays -> fShortWeekdays
1932 abbrWeekdaysData
= calData
.getByKey2(gDayNamesTag
, gNamesAbbrTag
, status
);
1933 fShortWeekdaysCount
= ures_getSize(abbrWeekdaysData
);
1934 fShortWeekdays
= new UnicodeString
[fShortWeekdaysCount
+1];
1936 if (fShortWeekdays
== 0) {
1937 status
= U_MEMORY_ALLOCATION_ERROR
;
1940 // leave fShortWeekdays[0] empty
1941 for(i
= 0; i
<fShortWeekdaysCount
; i
++) {
1942 resStr
= ures_getStringByIndex(abbrWeekdaysData
, i
, &len
, &status
);
1943 // setTo() - see assignArray comments
1944 fShortWeekdays
[i
+1].setTo(TRUE
, resStr
, len
);
1946 fShortWeekdaysCount
++;
1948 // Format short weekdays -> fShorterWeekdays (fall back to abbreviated)
1949 shorterWeekdaysData
= calData
.getByKey2(gDayNamesTag
, gNamesShortTag
, status
);
1950 if ( status
== U_MISSING_RESOURCE_ERROR
) {
1951 status
= U_ZERO_ERROR
;
1952 shorterWeekdaysData
= calData
.getByKey2(gDayNamesTag
, gNamesAbbrTag
, status
);
1954 fShorterWeekdaysCount
= ures_getSize(shorterWeekdaysData
);
1955 fShorterWeekdays
= new UnicodeString
[fShorterWeekdaysCount
+1];
1957 if (fShorterWeekdays
== 0) {
1958 status
= U_MEMORY_ALLOCATION_ERROR
;
1961 // leave fShorterWeekdays[0] empty
1962 for(i
= 0; i
<fShorterWeekdaysCount
; i
++) {
1963 resStr
= ures_getStringByIndex(shorterWeekdaysData
, i
, &len
, &status
);
1964 // setTo() - see assignArray comments
1965 fShorterWeekdays
[i
+1].setTo(TRUE
, resStr
, len
);
1967 fShorterWeekdaysCount
++;
1969 // Format narrow weekdays -> fNarrowWeekdays
1970 narrowWeekdaysData
= calData
.getByKey2(gDayNamesTag
, gNamesNarrowTag
, status
);
1971 if(status
== U_MISSING_RESOURCE_ERROR
) {
1972 status
= U_ZERO_ERROR
;
1973 narrowWeekdaysData
= calData
.getByKey3(gDayNamesTag
, gNamesStandaloneTag
, gNamesNarrowTag
, status
);
1975 if ( status
== U_MISSING_RESOURCE_ERROR
) {
1976 status
= U_ZERO_ERROR
;
1977 narrowWeekdaysData
= calData
.getByKey2(gDayNamesTag
, gNamesAbbrTag
, status
);
1979 fNarrowWeekdaysCount
= ures_getSize(narrowWeekdaysData
);
1980 fNarrowWeekdays
= new UnicodeString
[fNarrowWeekdaysCount
+1];
1982 if (fNarrowWeekdays
== 0) {
1983 status
= U_MEMORY_ALLOCATION_ERROR
;
1986 // leave fNarrowWeekdays[0] empty
1987 for(i
= 0; i
<fNarrowWeekdaysCount
; i
++) {
1988 resStr
= ures_getStringByIndex(narrowWeekdaysData
, i
, &len
, &status
);
1989 // setTo() - see assignArray comments
1990 fNarrowWeekdays
[i
+1].setTo(TRUE
, resStr
, len
);
1992 fNarrowWeekdaysCount
++;
1994 // Stand-alone wide weekdays -> fStandaloneWeekdays
1995 standaloneWeekdaysData
= calData
.getByKey3(gDayNamesTag
, gNamesStandaloneTag
, gNamesWideTag
, status
);
1996 if ( status
== U_MISSING_RESOURCE_ERROR
) {
1997 status
= U_ZERO_ERROR
;
1998 standaloneWeekdaysData
= calData
.getByKey2(gDayNamesTag
, gNamesWideTag
, status
);
2000 fStandaloneWeekdaysCount
= ures_getSize(standaloneWeekdaysData
);
2001 fStandaloneWeekdays
= new UnicodeString
[fStandaloneWeekdaysCount
+1];
2003 if (fStandaloneWeekdays
== 0) {
2004 status
= U_MEMORY_ALLOCATION_ERROR
;
2007 // leave fStandaloneWeekdays[0] empty
2008 for(i
= 0; i
<fStandaloneWeekdaysCount
; i
++) {
2009 resStr
= ures_getStringByIndex(standaloneWeekdaysData
, i
, &len
, &status
);
2010 // setTo() - see assignArray comments
2011 fStandaloneWeekdays
[i
+1].setTo(TRUE
, resStr
, len
);
2013 fStandaloneWeekdaysCount
++;
2015 // Stand-alone abbreviated weekdays -> fStandaloneShortWeekdays
2016 standaloneAbbrWeekdaysData
= calData
.getByKey3(gDayNamesTag
, gNamesStandaloneTag
, gNamesAbbrTag
, status
);
2017 if ( status
== U_MISSING_RESOURCE_ERROR
) {
2018 status
= U_ZERO_ERROR
;
2019 standaloneAbbrWeekdaysData
= calData
.getByKey2(gDayNamesTag
, gNamesAbbrTag
, status
);
2021 fStandaloneShortWeekdaysCount
= ures_getSize(standaloneAbbrWeekdaysData
);
2022 fStandaloneShortWeekdays
= new UnicodeString
[fStandaloneShortWeekdaysCount
+1];
2024 if (fStandaloneShortWeekdays
== 0) {
2025 status
= U_MEMORY_ALLOCATION_ERROR
;
2028 // leave fStandaloneShortWeekdays[0] empty
2029 for(i
= 0; i
<fStandaloneShortWeekdaysCount
; i
++) {
2030 resStr
= ures_getStringByIndex(standaloneAbbrWeekdaysData
, i
, &len
, &status
);
2031 // setTo() - see assignArray comments
2032 fStandaloneShortWeekdays
[i
+1].setTo(TRUE
, resStr
, len
);
2034 fStandaloneShortWeekdaysCount
++;
2036 // Stand-alone short weekdays -> fStandaloneShorterWeekdays (fall back to format abbreviated)
2037 standaloneShorterWeekdaysData
= calData
.getByKey3(gDayNamesTag
, gNamesStandaloneTag
, gNamesShortTag
, status
);
2038 if ( status
== U_MISSING_RESOURCE_ERROR
) {
2039 status
= U_ZERO_ERROR
;
2040 standaloneShorterWeekdaysData
= calData
.getByKey2(gDayNamesTag
, gNamesAbbrTag
, status
);
2042 fStandaloneShorterWeekdaysCount
= ures_getSize(standaloneShorterWeekdaysData
);
2043 fStandaloneShorterWeekdays
= new UnicodeString
[fStandaloneShorterWeekdaysCount
+1];
2045 if (fStandaloneShorterWeekdays
== 0) {
2046 status
= U_MEMORY_ALLOCATION_ERROR
;
2049 // leave fStandaloneShorterWeekdays[0] empty
2050 for(i
= 0; i
<fStandaloneShorterWeekdaysCount
; i
++) {
2051 resStr
= ures_getStringByIndex(standaloneShorterWeekdaysData
, i
, &len
, &status
);
2052 // setTo() - see assignArray comments
2053 fStandaloneShorterWeekdays
[i
+1].setTo(TRUE
, resStr
, len
);
2055 fStandaloneShorterWeekdaysCount
++;
2057 // Stand-alone narrow weekdays -> fStandaloneNarrowWeekdays
2058 standaloneNarrowWeekdaysData
= calData
.getByKey3(gDayNamesTag
, gNamesStandaloneTag
, gNamesNarrowTag
, status
);
2059 if ( status
== U_MISSING_RESOURCE_ERROR
) {
2060 status
= U_ZERO_ERROR
;
2061 standaloneNarrowWeekdaysData
= calData
.getByKey2(gDayNamesTag
, gNamesNarrowTag
, status
);
2062 if ( status
== U_MISSING_RESOURCE_ERROR
) {
2063 status
= U_ZERO_ERROR
;
2064 standaloneNarrowWeekdaysData
= calData
.getByKey2(gDayNamesTag
, gNamesAbbrTag
, status
);
2067 fStandaloneNarrowWeekdaysCount
= ures_getSize(standaloneNarrowWeekdaysData
);
2068 fStandaloneNarrowWeekdays
= new UnicodeString
[fStandaloneNarrowWeekdaysCount
+1];
2070 if (fStandaloneNarrowWeekdays
== 0) {
2071 status
= U_MEMORY_ALLOCATION_ERROR
;
2074 // leave fStandaloneNarrowWeekdays[0] empty
2075 for(i
= 0; i
<fStandaloneNarrowWeekdaysCount
; i
++) {
2076 resStr
= ures_getStringByIndex(standaloneNarrowWeekdaysData
, i
, &len
, &status
);
2077 // setTo() - see assignArray comments
2078 fStandaloneNarrowWeekdays
[i
+1].setTo(TRUE
, resStr
, len
);
2080 fStandaloneNarrowWeekdaysCount
++;
2084 ures_close(eraNames
);
2085 ures_close(narrowEras
);
2089 DateFormatSymbols::getLocale(ULocDataLocaleType type
, UErrorCode
& status
) const {
2090 U_LOCALE_BASED(locBased
, *this);
2091 return locBased
.getLocale(type
, status
);
2096 #endif /* #if !UCONFIG_NO_FORMATTING */