2 *******************************************************************************
3 * Copyright (C) 1997-2006, 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 *******************************************************************************
23 #include "unicode/utypes.h"
25 #if !UCONFIG_NO_FORMATTING
27 #include "unicode/dtfmtsym.h"
28 #include "unicode/smpdtfmt.h"
39 // *****************************************************************************
40 // class DateFormatSymbols
41 // *****************************************************************************
43 * These are static arrays we use only in the case where we have no
47 #define PATTERN_CHARS_LEN 26
50 * Unlocalized date-time pattern characters. For example: 'y', 'd', etc. All
51 * locales use the same these unlocalized pattern characters.
53 static const UChar gPatternChars
[] = {
54 // GyMdkHmsSEDFwWahKzYeugAZvcLQq
55 0x47, 0x79, 0x4D, 0x64, 0x6B, 0x48, 0x6D, 0x73, 0x53, 0x45,
56 0x44, 0x46, 0x77, 0x57, 0x61, 0x68, 0x4B, 0x7A, 0x59, 0x65,
57 0x75, 0x67, 0x41, 0x5A, 0x76, 0x63, 0x4c, 0x51, 0x71, 0
60 /* length of an array */
61 #define ARRAY_LENGTH(array) (sizeof(array)/sizeof(array[0]))
63 //------------------------------------------------------
64 // Strings of last resort. These are only used if we have no resource
65 // files. They aren't designed for actual use, just for backup.
67 // These are the month names and abbreviations of last resort.
68 static const UChar gLastResortMonthNames
[13][3] =
70 {0x0030, 0x0031, 0x0000}, /* "01" */
71 {0x0030, 0x0032, 0x0000}, /* "02" */
72 {0x0030, 0x0033, 0x0000}, /* "03" */
73 {0x0030, 0x0034, 0x0000}, /* "04" */
74 {0x0030, 0x0035, 0x0000}, /* "05" */
75 {0x0030, 0x0036, 0x0000}, /* "06" */
76 {0x0030, 0x0037, 0x0000}, /* "07" */
77 {0x0030, 0x0038, 0x0000}, /* "08" */
78 {0x0030, 0x0039, 0x0000}, /* "09" */
79 {0x0031, 0x0030, 0x0000}, /* "10" */
80 {0x0031, 0x0031, 0x0000}, /* "11" */
81 {0x0031, 0x0032, 0x0000}, /* "12" */
82 {0x0031, 0x0033, 0x0000} /* "13" */
85 // These are the weekday names and abbreviations of last resort.
86 static const UChar gLastResortDayNames
[8][2] =
88 {0x0030, 0x0000}, /* "0" */
89 {0x0031, 0x0000}, /* "1" */
90 {0x0032, 0x0000}, /* "2" */
91 {0x0033, 0x0000}, /* "3" */
92 {0x0034, 0x0000}, /* "4" */
93 {0x0035, 0x0000}, /* "5" */
94 {0x0036, 0x0000}, /* "6" */
95 {0x0037, 0x0000} /* "7" */
98 // These are the quarter names and abbreviations of last resort.
99 static const UChar gLastResortQuarters
[4][2] =
101 {0x0031, 0x0000}, /* "1" */
102 {0x0032, 0x0000}, /* "2" */
103 {0x0033, 0x0000}, /* "3" */
104 {0x0034, 0x0000}, /* "4" */
107 // These are the am/pm and BC/AD markers of last resort.
108 static const UChar gLastResortAmPmMarkers
[2][3] =
110 {0x0041, 0x004D, 0x0000}, /* "AM" */
111 {0x0050, 0x004D, 0x0000} /* "PM" */
114 static const UChar gLastResortEras
[2][3] =
116 {0x0042, 0x0043, 0x0000}, /* "BC" */
117 {0x0041, 0x0044, 0x0000} /* "AD" */
121 // These are the zone strings of last resort.
122 static const UChar gLastResortZoneStrings
[7][4] =
124 {0x0047, 0x004D, 0x0054, 0x0000}, /* "GMT" */
125 {0x0047, 0x004D, 0x0054, 0x0000}, /* "GMT" */
126 {0x0047, 0x004D, 0x0054, 0x0000}, /* "GMT" */
127 {0x0047, 0x004D, 0x0054, 0x0000}, /* "GMT" */
128 {0x0047, 0x004D, 0x0054, 0x0000}, /* "GMT" */
129 {0x0047, 0x004D, 0x0054, 0x0000}, /* "GMT" */
130 {0x0047, 0x004D, 0x0054, 0x0000} /* "GMT" */
133 /* Sizes for the last resort string arrays */
134 typedef enum LastResortSize
{
156 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateFormatSymbols
)
159 * These are the tags we expect to see in normal resource bundle files associated
160 * with a locale and calendar
162 static const char gErasTag
[]="eras";
163 static const char gAbbreviatedTag
[] = "abbreviated";
164 static const char gMonthNamesTag
[]="monthNames";
165 static const char gDayNamesTag
[]="dayNames";
166 static const char gNamesWideTag
[]="wide";
167 static const char gNamesAbbrTag
[]="abbreviated";
168 static const char gNamesNarrowTag
[]="narrow";
169 static const char gNamesStandaloneTag
[]="stand-alone";
170 static const char gAmPmMarkersTag
[]="AmPmMarkers";
171 static const char gQuartersTag
[]="quarters";
174 * These are the tags we expect to see in time zone data resource bundle files
175 * associated with a locale.
177 static const char gZoneStringsTag
[]="zoneStrings";
178 static const char gLocalPatternCharsTag
[]="localPatternChars";
183 * Keep this variable in synch with max length of display strings
185 #define UTZ_MAX_DISPLAY_STRINGS_LENGTH 7
186 #define UTZ_SHORT_GENERIC "sg"
187 #define UTZ_SHORT_STANDARD "ss"
188 #define UTZ_SHORT_DAYLIGHT "sd"
189 #define UTZ_LONG_GENERIC "lg"
190 #define UTZ_LONG_STANDARD "ls"
191 #define UTZ_LONG_DAYLIGHT "ld"
192 #define UTZ_EXEMPLAR_CITY "ec"
195 * Jitterbug 2974: MSVC has a bug whereby new X[0] behaves badly.
198 static inline UnicodeString
* newUnicodeStringArray(size_t count
) {
199 return new UnicodeString
[count
? count
: 1];
203 static void deleteUnicodeStringArray(void* obj
) {
204 delete[] (UnicodeString
*)obj
;
208 //------------------------------------------------------
210 DateFormatSymbols::DateFormatSymbols(const Locale
& locale
,
214 initializeData(locale
, NULL
, status
);
217 DateFormatSymbols::DateFormatSymbols(UErrorCode
& status
)
220 initializeData(Locale::getDefault(), NULL
, status
, TRUE
);
224 DateFormatSymbols::DateFormatSymbols(const Locale
& locale
,
229 initializeData(locale
, type
, status
);
232 DateFormatSymbols::DateFormatSymbols(const char *type
, UErrorCode
& status
)
235 initializeData(Locale::getDefault(), type
, status
, TRUE
);
238 DateFormatSymbols::DateFormatSymbols(const DateFormatSymbols
& other
)
245 DateFormatSymbols::assignArray(UnicodeString
*& dstArray
,
247 const UnicodeString
* srcArray
,
250 // assignArray() is only called by copyData(), which in turn implements the
251 // copy constructor and the assignment operator.
252 // All strings in a DateFormatSymbols object are created in one of the following
253 // three ways that all allow to safely use UnicodeString::fastCopyFrom():
254 // - readonly-aliases from resource bundles
255 // - readonly-aliases or allocated strings from constants
256 // - safely cloned strings (with owned buffers) from setXYZ() functions
258 // Note that this is true for as long as DateFormatSymbols can be constructed
259 // only from a locale bundle or set via the cloning API,
260 // *and* for as long as all the strings are in *private* fields, preventing
261 // a subclass from creating these strings in an "unsafe" way (with respect to fastCopyFrom()).
263 dstArray
= newUnicodeStringArray(srcCount
);
264 if(dstArray
!= NULL
) {
266 for(i
=0; i
<srcCount
; ++i
) {
267 dstArray
[i
].fastCopyFrom(srcArray
[i
]);
273 * Create a copy, in fZoneStrings, of the given zone strings array. The
274 * member variables fZoneStringsRowCount and fZoneStringsColCount should
275 * be set already by the caller.
278 DateFormatSymbols::createZoneStrings(const UnicodeString
*const * otherStrings
)
282 fZoneStrings
= (UnicodeString
**)uprv_malloc(fZoneStringsRowCount
* sizeof(UnicodeString
*));
283 for (row
=0; row
<fZoneStringsRowCount
; ++row
)
285 fZoneStrings
[row
] = newUnicodeStringArray(fZoneStringsColCount
);
286 for (col
=0; col
<fZoneStringsColCount
; ++col
) {
287 // fastCopyFrom() - see assignArray comments
288 fZoneStrings
[row
][col
].fastCopyFrom(otherStrings
[row
][col
]);
294 * Copy all of the other's data to this.
297 DateFormatSymbols::copyData(const DateFormatSymbols
& other
) {
298 assignArray(fEras
, fErasCount
, other
.fEras
, other
.fErasCount
);
299 assignArray(fEraNames
, fEraNamesCount
, other
.fEraNames
, other
.fEraNamesCount
);
300 assignArray(fMonths
, fMonthsCount
, other
.fMonths
, other
.fMonthsCount
);
301 assignArray(fShortMonths
, fShortMonthsCount
, other
.fShortMonths
, other
.fShortMonthsCount
);
302 assignArray(fNarrowMonths
, fNarrowMonthsCount
, other
.fNarrowMonths
, other
.fNarrowMonthsCount
);
303 assignArray(fStandaloneMonths
, fStandaloneMonthsCount
, other
.fStandaloneMonths
, other
.fStandaloneMonthsCount
);
304 assignArray(fStandaloneShortMonths
, fStandaloneShortMonthsCount
, other
.fStandaloneShortMonths
, other
.fStandaloneShortMonthsCount
);
305 assignArray(fStandaloneNarrowMonths
, fStandaloneNarrowMonthsCount
, other
.fStandaloneNarrowMonths
, other
.fStandaloneNarrowMonthsCount
);
306 assignArray(fWeekdays
, fWeekdaysCount
, other
.fWeekdays
, other
.fWeekdaysCount
);
307 assignArray(fShortWeekdays
, fShortWeekdaysCount
, other
.fShortWeekdays
, other
.fShortWeekdaysCount
);
308 assignArray(fNarrowWeekdays
, fNarrowWeekdaysCount
, other
.fNarrowWeekdays
, other
.fNarrowWeekdaysCount
);
309 assignArray(fStandaloneWeekdays
, fStandaloneWeekdaysCount
, other
.fStandaloneWeekdays
, other
.fStandaloneWeekdaysCount
);
310 assignArray(fStandaloneShortWeekdays
, fStandaloneShortWeekdaysCount
, other
.fStandaloneShortWeekdays
, other
.fStandaloneShortWeekdaysCount
);
311 assignArray(fStandaloneNarrowWeekdays
, fStandaloneNarrowWeekdaysCount
, other
.fStandaloneNarrowWeekdays
, other
.fStandaloneNarrowWeekdaysCount
);
312 assignArray(fAmPms
, fAmPmsCount
, other
.fAmPms
, other
.fAmPmsCount
);
313 assignArray(fQuarters
, fQuartersCount
, other
.fQuarters
, other
.fQuartersCount
);
314 assignArray(fShortQuarters
, fShortQuartersCount
, other
.fShortQuarters
, other
.fShortQuartersCount
);
315 assignArray(fStandaloneQuarters
, fStandaloneQuartersCount
, other
.fStandaloneQuarters
, other
.fStandaloneQuartersCount
);
316 assignArray(fStandaloneShortQuarters
, fStandaloneShortQuartersCount
, other
.fStandaloneShortQuarters
, other
.fStandaloneShortQuartersCount
);
317 // the zoneStrings data is initialized on demand
318 //fZoneStringsRowCount = other.fZoneStringsRowCount;
319 //fZoneStringsColCount = other.fZoneStringsColCount;
320 //createZoneStrings((const UnicodeString**)other.fZoneStrings);
321 // initialize on demand
322 fZoneStringsHash
= NULL
;
323 fZoneIDEnumeration
= NULL
;
325 fZoneStringsColCount
= 0;
326 fZoneStringsRowCount
= 0;
327 fResourceBundle
= NULL
;
328 if(other
.fZoneStringsHash
!=NULL
){
329 fZoneStringsHash
= createZoneStringsHash(other
.fZoneStringsHash
);
330 fZoneIDEnumeration
= other
.fZoneIDEnumeration
->clone();
332 UErrorCode status
=U_ZERO_ERROR
;
333 fResourceBundle
= ures_clone(other
.fResourceBundle
, &status
);
334 // TODO: what should be done in case of error?
337 // fastCopyFrom() - see assignArray comments
338 fLocalPatternChars
.fastCopyFrom(other
.fLocalPatternChars
);
342 * Assignment operator.
344 DateFormatSymbols
& DateFormatSymbols::operator=(const DateFormatSymbols
& other
)
352 DateFormatSymbols::~DateFormatSymbols()
357 void DateFormatSymbols::dispose()
359 if (fEras
) delete[] fEras
;
360 if (fEraNames
) delete[] fEraNames
;
361 if (fMonths
) delete[] fMonths
;
362 if (fShortMonths
) delete[] fShortMonths
;
363 if (fNarrowMonths
) delete[] fNarrowMonths
;
364 if (fStandaloneMonths
) delete[] fStandaloneMonths
;
365 if (fStandaloneShortMonths
) delete[] fStandaloneShortMonths
;
366 if (fStandaloneNarrowMonths
) delete[] fStandaloneNarrowMonths
;
367 if (fWeekdays
) delete[] fWeekdays
;
368 if (fShortWeekdays
) delete[] fShortWeekdays
;
369 if (fNarrowWeekdays
) delete[] fNarrowWeekdays
;
370 if (fStandaloneWeekdays
) delete[] fStandaloneWeekdays
;
371 if (fStandaloneShortWeekdays
) delete[] fStandaloneShortWeekdays
;
372 if (fStandaloneNarrowWeekdays
) delete[] fStandaloneNarrowWeekdays
;
373 if (fAmPms
) delete[] fAmPms
;
374 if (fQuarters
) delete[] fQuarters
;
375 if (fShortQuarters
) delete[] fShortQuarters
;
376 if (fStandaloneQuarters
) delete[] fStandaloneQuarters
;
377 if (fStandaloneShortQuarters
) delete[] fStandaloneShortQuarters
;
379 disposeZoneStrings();
382 void DateFormatSymbols::disposeZoneStrings()
385 for (int32_t row
=0; row
<fZoneStringsRowCount
; ++row
)
386 delete[] fZoneStrings
[row
];
387 uprv_free(fZoneStrings
);
389 if(fZoneStringsHash
){
390 delete fZoneStringsHash
;
391 fZoneStringsHash
= NULL
;
393 if(fZoneIDEnumeration
){
394 delete fZoneIDEnumeration
;
395 fZoneIDEnumeration
= NULL
;
397 ures_close(fResourceBundle
);
398 fResourceBundle
= NULL
;
402 DateFormatSymbols::arrayCompare(const UnicodeString
* array1
,
403 const UnicodeString
* array2
,
406 if (array1
== array2
) return TRUE
;
410 if (array1
[count
] != array2
[count
]) return FALSE
;
416 DateFormatSymbols::operator==(const DateFormatSymbols
& other
) const
418 // First do cheap comparisons
419 if (this == &other
) {
422 if (fErasCount
== other
.fErasCount
&&
423 fEraNamesCount
== other
.fEraNamesCount
&&
424 fMonthsCount
== other
.fMonthsCount
&&
425 fShortMonthsCount
== other
.fShortMonthsCount
&&
426 fNarrowMonthsCount
== other
.fNarrowMonthsCount
&&
427 fStandaloneMonthsCount
== other
.fStandaloneMonthsCount
&&
428 fStandaloneShortMonthsCount
== other
.fStandaloneShortMonthsCount
&&
429 fStandaloneNarrowMonthsCount
== other
.fStandaloneNarrowMonthsCount
&&
430 fWeekdaysCount
== other
.fWeekdaysCount
&&
431 fShortWeekdaysCount
== other
.fShortWeekdaysCount
&&
432 fNarrowWeekdaysCount
== other
.fNarrowWeekdaysCount
&&
433 fStandaloneWeekdaysCount
== other
.fStandaloneWeekdaysCount
&&
434 fStandaloneShortWeekdaysCount
== other
.fStandaloneShortWeekdaysCount
&&
435 fStandaloneNarrowWeekdaysCount
== other
.fStandaloneNarrowWeekdaysCount
&&
436 fAmPmsCount
== other
.fAmPmsCount
&&
437 fQuartersCount
== other
.fQuartersCount
&&
438 fShortQuartersCount
== other
.fShortQuartersCount
&&
439 fStandaloneQuartersCount
== other
.fStandaloneQuartersCount
&&
440 fStandaloneShortQuartersCount
== other
.fStandaloneShortQuartersCount
)
442 // Now compare the arrays themselves
443 if (arrayCompare(fEras
, other
.fEras
, fErasCount
) &&
444 arrayCompare(fEraNames
, other
.fEraNames
, fEraNamesCount
) &&
445 arrayCompare(fMonths
, other
.fMonths
, fMonthsCount
) &&
446 arrayCompare(fShortMonths
, other
.fShortMonths
, fShortMonthsCount
) &&
447 arrayCompare(fNarrowMonths
, other
.fNarrowMonths
, fNarrowMonthsCount
) &&
448 arrayCompare(fStandaloneMonths
, other
.fStandaloneMonths
, fStandaloneMonthsCount
) &&
449 arrayCompare(fStandaloneShortMonths
, other
.fStandaloneShortMonths
, fStandaloneShortMonthsCount
) &&
450 arrayCompare(fStandaloneNarrowMonths
, other
.fStandaloneNarrowMonths
, fStandaloneNarrowMonthsCount
) &&
451 arrayCompare(fWeekdays
, other
.fWeekdays
, fWeekdaysCount
) &&
452 arrayCompare(fShortWeekdays
, other
.fShortWeekdays
, fShortWeekdaysCount
) &&
453 arrayCompare(fNarrowWeekdays
, other
.fNarrowWeekdays
, fNarrowWeekdaysCount
) &&
454 arrayCompare(fStandaloneWeekdays
, other
.fStandaloneWeekdays
, fStandaloneWeekdaysCount
) &&
455 arrayCompare(fStandaloneShortWeekdays
, other
.fStandaloneShortWeekdays
, fStandaloneShortWeekdaysCount
) &&
456 arrayCompare(fStandaloneNarrowWeekdays
, other
.fStandaloneNarrowWeekdays
, fStandaloneNarrowWeekdaysCount
) &&
457 arrayCompare(fAmPms
, other
.fAmPms
, fAmPmsCount
) &&
458 arrayCompare(fQuarters
, other
.fQuarters
, fQuartersCount
) &&
459 arrayCompare(fShortQuarters
, other
.fShortQuarters
, fShortQuartersCount
) &&
460 arrayCompare(fStandaloneQuarters
, other
.fStandaloneQuarters
, fStandaloneQuartersCount
) &&
461 arrayCompare(fStandaloneShortQuarters
, other
.fStandaloneShortQuarters
, fStandaloneShortQuartersCount
))
464 if(fZoneStringsHash
== NULL
|| other
.fZoneStringsHash
== NULL
){
465 // fZoneStringsHash is not initialized compare the resource bundles
466 if(ures_equal(fResourceBundle
, other
.fResourceBundle
)== FALSE
){
470 if(fZoneStringsHash
->equals(*other
.fZoneStringsHash
) == FALSE
){
473 // we always make sure that we update the enumeration when the hash is
474 // updated. So we can be sure that once we compare the hashes the
475 // enumerations are also equal
477 // since fZoneStrings data member is deprecated .. and may not be initialized
478 // so don't compare them
485 //------------------------------------------------------
488 DateFormatSymbols::getEras(int32_t &count
) const
495 DateFormatSymbols::getEraNames(int32_t &count
) const
497 count
= fEraNamesCount
;
502 DateFormatSymbols::getMonths(int32_t &count
) const
504 count
= fMonthsCount
;
509 DateFormatSymbols::getShortMonths(int32_t &count
) const
511 count
= fShortMonthsCount
;
516 DateFormatSymbols::getMonths(int32_t &count
, DtContextType context
, DtWidthType width
) const
518 UnicodeString
*returnValue
= NULL
;
524 count
= fMonthsCount
;
525 returnValue
= fMonths
;
528 count
= fShortMonthsCount
;
529 returnValue
= fShortMonths
;
532 count
= fNarrowMonthsCount
;
533 returnValue
= fNarrowMonths
;
535 case DT_WIDTH_COUNT
:
542 count
= fStandaloneMonthsCount
;
543 returnValue
= fStandaloneMonths
;
546 count
= fStandaloneShortMonthsCount
;
547 returnValue
= fStandaloneShortMonths
;
550 count
= fStandaloneNarrowMonthsCount
;
551 returnValue
= fStandaloneNarrowMonths
;
553 case DT_WIDTH_COUNT
:
557 case DT_CONTEXT_COUNT
:
564 DateFormatSymbols::getWeekdays(int32_t &count
) const
566 count
= fWeekdaysCount
;
571 DateFormatSymbols::getShortWeekdays(int32_t &count
) const
573 count
= fShortWeekdaysCount
;
574 return fShortWeekdays
;
578 DateFormatSymbols::getWeekdays(int32_t &count
, DtContextType context
, DtWidthType width
) const
580 UnicodeString
*returnValue
= NULL
;
585 count
= fWeekdaysCount
;
586 returnValue
= fWeekdays
;
589 count
= fShortWeekdaysCount
;
590 returnValue
= fShortWeekdays
;
593 count
= fNarrowWeekdaysCount
;
594 returnValue
= fNarrowWeekdays
;
596 case DT_WIDTH_COUNT
:
603 count
= fStandaloneWeekdaysCount
;
604 returnValue
= fStandaloneWeekdays
;
607 count
= fStandaloneShortWeekdaysCount
;
608 returnValue
= fStandaloneShortWeekdays
;
611 count
= fStandaloneNarrowWeekdaysCount
;
612 returnValue
= fStandaloneNarrowWeekdays
;
614 case DT_WIDTH_COUNT
:
618 case DT_CONTEXT_COUNT
:
625 DateFormatSymbols::getQuarters(int32_t &count
, DtContextType context
, DtWidthType width
) const
627 UnicodeString
*returnValue
= NULL
;
633 count
= fQuartersCount
;
634 returnValue
= fQuarters
;
637 count
= fShortQuartersCount
;
638 returnValue
= fShortQuarters
;
644 case DT_WIDTH_COUNT
:
651 count
= fStandaloneQuartersCount
;
652 returnValue
= fStandaloneQuarters
;
655 count
= fStandaloneShortQuartersCount
;
656 returnValue
= fStandaloneShortQuarters
;
662 case DT_WIDTH_COUNT
:
666 case DT_CONTEXT_COUNT
:
673 DateFormatSymbols::getAmPmStrings(int32_t &count
) const
679 //------------------------------------------------------
682 DateFormatSymbols::setEras(const UnicodeString
* erasArray
, int32_t count
)
684 // delete the old list if we own it
688 // we always own the new list, which we create here (we duplicate rather
689 // than adopting the list passed in)
690 fEras
= newUnicodeStringArray(count
);
691 uprv_arrayCopy(erasArray
,fEras
, count
);
696 DateFormatSymbols::setEraNames(const UnicodeString
* eraNamesArray
, int32_t count
)
698 // delete the old list if we own it
702 // we always own the new list, which we create here (we duplicate rather
703 // than adopting the list passed in)
704 fEraNames
= newUnicodeStringArray(count
);
705 uprv_arrayCopy(eraNamesArray
,fEraNames
, count
);
706 fEraNamesCount
= count
;
710 DateFormatSymbols::setMonths(const UnicodeString
* monthsArray
, int32_t count
)
712 // delete the old list if we own it
716 // we always own the new list, which we create here (we duplicate rather
717 // than adopting the list passed in)
718 fMonths
= newUnicodeStringArray(count
);
719 uprv_arrayCopy( monthsArray
,fMonths
,count
);
720 fMonthsCount
= count
;
724 DateFormatSymbols::setShortMonths(const UnicodeString
* shortMonthsArray
, int32_t count
)
726 // delete the old list if we own it
728 delete[] fShortMonths
;
730 // we always own the new list, which we create here (we duplicate rather
731 // than adopting the list passed in)
732 fShortMonths
= newUnicodeStringArray(count
);
733 uprv_arrayCopy(shortMonthsArray
,fShortMonths
, count
);
734 fShortMonthsCount
= count
;
738 DateFormatSymbols::setMonths(const UnicodeString
* monthsArray
, int32_t count
, DtContextType context
, DtWidthType width
)
740 // delete the old list if we own it
741 // we always own the new list, which we create here (we duplicate rather
742 // than adopting the list passed in)
750 fMonths
= newUnicodeStringArray(count
);
751 uprv_arrayCopy( monthsArray
,fMonths
,count
);
752 fMonthsCount
= count
;
756 delete[] fShortMonths
;
757 fShortMonths
= newUnicodeStringArray(count
);
758 uprv_arrayCopy( monthsArray
,fShortMonths
,count
);
759 fShortMonthsCount
= count
;
763 delete[] fNarrowMonths
;
764 fNarrowMonths
= newUnicodeStringArray(count
);
765 uprv_arrayCopy( monthsArray
,fNarrowMonths
,count
);
766 fNarrowMonthsCount
= count
;
768 case DT_WIDTH_COUNT
:
775 if (fStandaloneMonths
)
776 delete[] fStandaloneMonths
;
777 fStandaloneMonths
= newUnicodeStringArray(count
);
778 uprv_arrayCopy( monthsArray
,fStandaloneMonths
,count
);
779 fStandaloneMonthsCount
= count
;
782 if (fStandaloneShortMonths
)
783 delete[] fStandaloneShortMonths
;
784 fStandaloneShortMonths
= newUnicodeStringArray(count
);
785 uprv_arrayCopy( monthsArray
,fStandaloneShortMonths
,count
);
786 fStandaloneShortMonthsCount
= count
;
789 if (fStandaloneNarrowMonths
)
790 delete[] fStandaloneNarrowMonths
;
791 fStandaloneNarrowMonths
= newUnicodeStringArray(count
);
792 uprv_arrayCopy( monthsArray
,fStandaloneNarrowMonths
,count
);
793 fStandaloneNarrowMonthsCount
= count
;
795 case DT_WIDTH_COUNT
:
799 case DT_CONTEXT_COUNT
:
804 void DateFormatSymbols::setWeekdays(const UnicodeString
* weekdaysArray
, int32_t count
)
806 // delete the old list if we own it
810 // we always own the new list, which we create here (we duplicate rather
811 // than adopting the list passed in)
812 fWeekdays
= newUnicodeStringArray(count
);
813 uprv_arrayCopy(weekdaysArray
,fWeekdays
,count
);
814 fWeekdaysCount
= count
;
818 DateFormatSymbols::setShortWeekdays(const UnicodeString
* shortWeekdaysArray
, int32_t count
)
820 // delete the old list if we own it
822 delete[] fShortWeekdays
;
824 // we always own the new list, which we create here (we duplicate rather
825 // than adopting the list passed in)
826 fShortWeekdays
= newUnicodeStringArray(count
);
827 uprv_arrayCopy(shortWeekdaysArray
, fShortWeekdays
, count
);
828 fShortWeekdaysCount
= count
;
832 DateFormatSymbols::setWeekdays(const UnicodeString
* weekdaysArray
, int32_t count
, DtContextType context
, DtWidthType width
)
834 // delete the old list if we own it
835 // we always own the new list, which we create here (we duplicate rather
836 // than adopting the list passed in)
844 fWeekdays
= newUnicodeStringArray(count
);
845 uprv_arrayCopy(weekdaysArray
, fWeekdays
, count
);
846 fWeekdaysCount
= count
;
850 delete[] fShortWeekdays
;
851 fShortWeekdays
= newUnicodeStringArray(count
);
852 uprv_arrayCopy(weekdaysArray
, fShortWeekdays
, count
);
853 fShortWeekdaysCount
= count
;
857 delete[] fNarrowWeekdays
;
858 fNarrowWeekdays
= newUnicodeStringArray(count
);
859 uprv_arrayCopy(weekdaysArray
, fNarrowWeekdays
, count
);
860 fNarrowWeekdaysCount
= count
;
862 case DT_WIDTH_COUNT
:
869 if (fStandaloneWeekdays
)
870 delete[] fStandaloneWeekdays
;
871 fStandaloneWeekdays
= newUnicodeStringArray(count
);
872 uprv_arrayCopy(weekdaysArray
, fStandaloneWeekdays
, count
);
873 fStandaloneWeekdaysCount
= count
;
876 if (fStandaloneShortWeekdays
)
877 delete[] fStandaloneShortWeekdays
;
878 fStandaloneShortWeekdays
= newUnicodeStringArray(count
);
879 uprv_arrayCopy(weekdaysArray
, fStandaloneShortWeekdays
, count
);
880 fStandaloneShortWeekdaysCount
= count
;
883 if (fStandaloneNarrowWeekdays
)
884 delete[] fStandaloneNarrowWeekdays
;
885 fStandaloneNarrowWeekdays
= newUnicodeStringArray(count
);
886 uprv_arrayCopy(weekdaysArray
, fStandaloneNarrowWeekdays
, count
);
887 fStandaloneNarrowWeekdaysCount
= count
;
889 case DT_WIDTH_COUNT
:
893 case DT_CONTEXT_COUNT
:
899 DateFormatSymbols::setQuarters(const UnicodeString
* quartersArray
, int32_t count
, DtContextType context
, DtWidthType width
)
901 // delete the old list if we own it
902 // we always own the new list, which we create here (we duplicate rather
903 // than adopting the list passed in)
911 fQuarters
= newUnicodeStringArray(count
);
912 uprv_arrayCopy( quartersArray
,fQuarters
,count
);
913 fQuartersCount
= count
;
917 delete[] fShortQuarters
;
918 fShortQuarters
= newUnicodeStringArray(count
);
919 uprv_arrayCopy( quartersArray
,fShortQuarters
,count
);
920 fShortQuartersCount
= count
;
925 delete[] fNarrowQuarters;
926 fNarrowQuarters = newUnicodeStringArray(count);
927 uprv_arrayCopy( quartersArray,fNarrowQuarters,count);
928 fNarrowQuartersCount = count;
931 case DT_WIDTH_COUNT
:
938 if (fStandaloneQuarters
)
939 delete[] fStandaloneQuarters
;
940 fStandaloneQuarters
= newUnicodeStringArray(count
);
941 uprv_arrayCopy( quartersArray
,fStandaloneQuarters
,count
);
942 fStandaloneQuartersCount
= count
;
945 if (fStandaloneShortQuarters
)
946 delete[] fStandaloneShortQuarters
;
947 fStandaloneShortQuarters
= newUnicodeStringArray(count
);
948 uprv_arrayCopy( quartersArray
,fStandaloneShortQuarters
,count
);
949 fStandaloneShortQuartersCount
= count
;
953 if (fStandaloneNarrowQuarters)
954 delete[] fStandaloneNarrowQuarters;
955 fStandaloneNarrowQuarters = newUnicodeStringArray(count);
956 uprv_arrayCopy( quartersArray,fStandaloneNarrowQuarters,count);
957 fStandaloneNarrowQuartersCount = count;
960 case DT_WIDTH_COUNT
:
964 case DT_CONTEXT_COUNT
:
970 DateFormatSymbols::setAmPmStrings(const UnicodeString
* amPmsArray
, int32_t count
)
972 // delete the old list if we own it
973 if (fAmPms
) delete[] fAmPms
;
975 // we always own the new list, which we create here (we duplicate rather
976 // than adopting the list passed in)
977 fAmPms
= newUnicodeStringArray(count
);
978 uprv_arrayCopy(amPmsArray
,fAmPms
,count
);
982 //------------------------------------------------------
984 const UnicodeString
**
985 DateFormatSymbols::getZoneStrings(int32_t& rowCount
, int32_t& columnCount
) const
988 UErrorCode status
= U_ZERO_ERROR
;
989 if(fZoneStrings
==NULL
){
990 // cast away const to get around the problem for lazy initialization
991 ((DateFormatSymbols
*)this)->initZoneStringsArray(status
);
992 if(U_FAILURE(status
)){
996 rowCount
= fZoneStringsRowCount
;
997 columnCount
= fZoneStringsColCount
;
999 return (const UnicodeString
**)fZoneStrings
; // Compiler requires cast
1003 DateFormatSymbols::setZoneStrings(const UnicodeString
* const *strings
, int32_t rowCount
, int32_t columnCount
)
1005 // since deleting a 2-d array is a pain in the butt, we offload that task to
1006 // a separate function
1007 disposeZoneStrings();
1008 UErrorCode status
= U_ZERO_ERROR
;
1009 // we always own the new list, which we create here (we duplicate rather
1010 // than adopting the list passed in)
1011 fZoneStringsRowCount
= rowCount
;
1012 fZoneStringsColCount
= columnCount
;
1013 createZoneStrings((const UnicodeString
**)strings
);
1014 initZoneStrings((const UnicodeString
**)strings
, rowCount
,columnCount
, status
);
1017 //------------------------------------------------------
1019 const UChar
* U_EXPORT2
1020 DateFormatSymbols::getPatternUChars(void)
1022 return gPatternChars
;
1025 //------------------------------------------------------
1028 DateFormatSymbols::getLocalPatternChars(UnicodeString
& result
) const
1030 // fastCopyFrom() - see assignArray comments
1031 return result
.fastCopyFrom(fLocalPatternChars
);
1034 //------------------------------------------------------
1037 DateFormatSymbols::setLocalPatternChars(const UnicodeString
& newLocalPatternChars
)
1039 fLocalPatternChars
= newLocalPatternChars
;
1042 //------------------------------------------------------
1045 initField(UnicodeString
**field
, int32_t& length
, const UResourceBundle
*data
, UErrorCode
&status
) {
1046 if (U_SUCCESS(status
)) {
1048 length
= ures_getSize(data
);
1049 *field
= newUnicodeStringArray(length
);
1051 for(int32_t i
= 0; i
<length
; i
++) {
1052 const UChar
*resStr
= ures_getStringByIndex(data
, i
, &strLen
, &status
);
1053 // setTo() - see assignArray comments
1054 (*(field
)+i
)->setTo(TRUE
, resStr
, strLen
);
1059 status
= U_MEMORY_ALLOCATION_ERROR
;
1065 initField(UnicodeString
**field
, int32_t& length
, const UChar
*data
, LastResortSize numStr
, LastResortSize strLen
, UErrorCode
&status
) {
1066 if (U_SUCCESS(status
)) {
1068 *field
= newUnicodeStringArray((size_t)numStr
);
1070 for(int32_t i
= 0; i
<length
; i
++) {
1071 // readonly aliases - all "data" strings are constant
1072 // -1 as length for variable-length strings (gLastResortDayNames[0] is empty)
1073 (*(field
)+i
)->setTo(TRUE
, data
+(i
*((int32_t)strLen
)), -1);
1078 status
= U_MEMORY_ALLOCATION_ERROR
;
1084 DateFormatSymbols::initializeData(const Locale
& locale
, const char *type
, UErrorCode
& status
, UBool useLastResortData
)
1088 const UChar
*resStr
;
1089 /* In case something goes wrong, initialize all of the data to NULL. */
1096 fShortMonths
= NULL
;
1097 fShortMonthsCount
=0;
1098 fNarrowMonths
= NULL
;
1099 fNarrowMonthsCount
=0;
1100 fStandaloneMonths
= NULL
;
1101 fStandaloneMonthsCount
=0;
1102 fStandaloneShortMonths
= NULL
;
1103 fStandaloneShortMonthsCount
=0;
1104 fStandaloneNarrowMonths
= NULL
;
1105 fStandaloneNarrowMonthsCount
=0;
1108 fShortWeekdays
= NULL
;
1109 fShortWeekdaysCount
=0;
1110 fNarrowWeekdays
= NULL
;
1111 fNarrowWeekdaysCount
=0;
1112 fStandaloneWeekdays
= NULL
;
1113 fStandaloneWeekdaysCount
=0;
1114 fStandaloneShortWeekdays
= NULL
;
1115 fStandaloneShortWeekdaysCount
=0;
1116 fStandaloneNarrowWeekdays
= NULL
;
1117 fStandaloneNarrowWeekdaysCount
=0;
1122 fShortQuarters
= NULL
;
1123 fShortQuartersCount
= 0;
1124 fStandaloneQuarters
= NULL
;
1125 fStandaloneQuartersCount
= 0;
1126 fStandaloneShortQuarters
= NULL
;
1127 fStandaloneShortQuartersCount
= 0;
1128 fZoneStringsRowCount
= 0;
1129 fZoneStringsColCount
= 0;
1130 fZoneStrings
= NULL
;
1131 fZoneStringsHash
= NULL
;
1132 fZoneIDEnumeration
= NULL
;
1133 fResourceBundle
= NULL
;
1136 if (U_FAILURE(status
)) return;
1139 * Retrieve the string arrays we need from the resource bundle file.
1140 * We cast away const here, but that's okay; we won't delete any of
1143 CalendarData
calData(locale
, type
, status
);
1144 fResourceBundle
= ures_open((char*)0, locale
.getName(), &status
);
1146 // load the first data item
1147 UResourceBundle
*erasMain
= calData
.getByKey(gErasTag
, status
);
1148 UResourceBundle
*eras
= ures_getByKeyWithFallback(erasMain
, gAbbreviatedTag
, NULL
, &status
);
1149 UErrorCode oldStatus
= status
;
1150 UResourceBundle
*eraNames
= ures_getByKeyWithFallback(erasMain
, gNamesWideTag
, NULL
, &status
);
1151 if ( status
== U_MISSING_RESOURCE_ERROR
) { // Workaround because eras/wide was omitted from CLDR 1.3
1153 eraNames
= ures_getByKeyWithFallback(erasMain
, gAbbreviatedTag
, NULL
, &status
);
1156 UResourceBundle
*lsweekdaysData
= NULL
; // Data closed by calData
1157 UResourceBundle
*weekdaysData
= NULL
; // Data closed by calData
1158 UResourceBundle
*narrowWeekdaysData
= NULL
; // Data closed by calData
1159 UResourceBundle
*standaloneWeekdaysData
= NULL
; // Data closed by calData
1160 UResourceBundle
*standaloneShortWeekdaysData
= NULL
; // Data closed by calData
1161 UResourceBundle
*standaloneNarrowWeekdaysData
= NULL
; // Data closed by calData
1163 U_LOCALE_BASED(locBased
, *this);
1164 if (U_FAILURE(status
))
1166 if (useLastResortData
)
1168 // Handle the case in which there is no resource data present.
1169 // We don't have to generate usable patterns in this situation;
1170 // we just need to produce something that will be semi-intelligible
1173 status
= U_USING_FALLBACK_WARNING
;
1175 initField(&fEras
, fErasCount
, (const UChar
*)gLastResortEras
, kEraNum
, kEraLen
, status
);
1176 initField(&fEraNames
, fEraNamesCount
, (const UChar
*)gLastResortEras
, kEraNum
, kEraLen
, status
);
1177 initField(&fMonths
, fMonthsCount
, (const UChar
*)gLastResortMonthNames
, kMonthNum
, kMonthLen
, status
);
1178 initField(&fShortMonths
, fShortMonthsCount
, (const UChar
*)gLastResortMonthNames
, kMonthNum
, kMonthLen
, status
);
1179 initField(&fNarrowMonths
, fNarrowMonthsCount
, (const UChar
*)gLastResortMonthNames
, kMonthNum
, kMonthLen
, status
);
1180 initField(&fStandaloneMonths
, fStandaloneMonthsCount
, (const UChar
*)gLastResortMonthNames
, kMonthNum
, kMonthLen
, status
);
1181 initField(&fStandaloneShortMonths
, fStandaloneShortMonthsCount
, (const UChar
*)gLastResortMonthNames
, kMonthNum
, kMonthLen
, status
);
1182 initField(&fStandaloneNarrowMonths
, fStandaloneNarrowMonthsCount
, (const UChar
*)gLastResortMonthNames
, kMonthNum
, kMonthLen
, status
);
1183 initField(&fWeekdays
, fWeekdaysCount
, (const UChar
*)gLastResortDayNames
, kDayNum
, kDayLen
, status
);
1184 initField(&fShortWeekdays
, fShortWeekdaysCount
, (const UChar
*)gLastResortDayNames
, kDayNum
, kDayLen
, status
);
1185 initField(&fNarrowWeekdays
, fNarrowWeekdaysCount
, (const UChar
*)gLastResortDayNames
, kDayNum
, kDayLen
, status
);
1186 initField(&fStandaloneWeekdays
, fStandaloneWeekdaysCount
, (const UChar
*)gLastResortDayNames
, kDayNum
, kDayLen
, status
);
1187 initField(&fStandaloneShortWeekdays
, fStandaloneShortWeekdaysCount
, (const UChar
*)gLastResortDayNames
, kDayNum
, kDayLen
, status
);
1188 initField(&fStandaloneNarrowWeekdays
, fStandaloneNarrowWeekdaysCount
, (const UChar
*)gLastResortDayNames
, kDayNum
, kDayLen
, status
);
1189 initField(&fAmPms
, fAmPmsCount
, (const UChar
*)gLastResortAmPmMarkers
, kAmPmNum
, kAmPmLen
, status
);
1190 initField(&fQuarters
, fQuartersCount
, (const UChar
*)gLastResortQuarters
, kQuarterNum
, kQuarterLen
, status
);
1191 initField(&fShortQuarters
, fShortQuartersCount
, (const UChar
*)gLastResortQuarters
, kQuarterNum
, kQuarterLen
, status
);
1192 initField(&fStandaloneQuarters
, fStandaloneQuartersCount
, (const UChar
*)gLastResortQuarters
, kQuarterNum
, kQuarterLen
, status
);
1193 initField(&fStandaloneShortQuarters
, fStandaloneShortQuartersCount
, (const UChar
*)gLastResortQuarters
, kQuarterNum
, kQuarterLen
, status
);
1194 fLocalPatternChars
= gPatternChars
;
1199 // if we make it to here, the resource data is cool, and we can get everything out
1200 // of it that we need except for the time-zone and localized-pattern data, which
1201 // are stored in a separate file
1202 locBased
.setLocaleIDs(ures_getLocaleByType(eras
, ULOC_VALID_LOCALE
, &status
),
1203 ures_getLocaleByType(eras
, ULOC_ACTUAL_LOCALE
, &status
));
1205 initField(&fEras
, fErasCount
, eras
, status
);
1206 initField(&fEraNames
, fEraNamesCount
, eraNames
, status
);
1208 initField(&fMonths
, fMonthsCount
, calData
.getByKey2(gMonthNamesTag
, gNamesWideTag
, status
), status
);
1209 initField(&fShortMonths
, fShortMonthsCount
, calData
.getByKey2(gMonthNamesTag
, gNamesAbbrTag
, status
), status
);
1211 initField(&fNarrowMonths
, fNarrowMonthsCount
, calData
.getByKey2(gMonthNamesTag
, gNamesNarrowTag
, status
), status
);
1212 if(status
== U_MISSING_RESOURCE_ERROR
) {
1213 status
= U_ZERO_ERROR
;
1214 initField(&fNarrowMonths
, fNarrowMonthsCount
, calData
.getByKey3(gMonthNamesTag
, gNamesStandaloneTag
, gNamesNarrowTag
, status
), status
);
1216 if ( status
== U_MISSING_RESOURCE_ERROR
) { /* If format/narrow not available, use format/abbreviated */
1217 status
= U_ZERO_ERROR
;
1218 initField(&fNarrowMonths
, fNarrowMonthsCount
, calData
.getByKey2(gMonthNamesTag
, gNamesAbbrTag
, status
), status
);
1221 initField(&fStandaloneMonths
, fStandaloneMonthsCount
, calData
.getByKey3(gMonthNamesTag
, gNamesStandaloneTag
, gNamesWideTag
, status
), status
);
1222 if ( status
== U_MISSING_RESOURCE_ERROR
) { /* If standalone/wide not available, use format/wide */
1223 status
= U_ZERO_ERROR
;
1224 initField(&fStandaloneMonths
, fStandaloneMonthsCount
, calData
.getByKey2(gMonthNamesTag
, gNamesWideTag
, status
), status
);
1226 initField(&fStandaloneShortMonths
, fStandaloneShortMonthsCount
, calData
.getByKey3(gMonthNamesTag
, gNamesStandaloneTag
, gNamesAbbrTag
, status
), status
);
1227 if ( status
== U_MISSING_RESOURCE_ERROR
) { /* If standalone/abbreviated not available, use format/abbreviated */
1228 status
= U_ZERO_ERROR
;
1229 initField(&fStandaloneShortMonths
, fStandaloneShortMonthsCount
, calData
.getByKey2(gMonthNamesTag
, gNamesAbbrTag
, status
), status
);
1231 initField(&fStandaloneNarrowMonths
, fStandaloneNarrowMonthsCount
, calData
.getByKey3(gMonthNamesTag
, gNamesStandaloneTag
, gNamesNarrowTag
, status
), status
);
1232 if ( status
== U_MISSING_RESOURCE_ERROR
) { /* if standalone/narrow not availabe, try format/narrow */
1233 status
= U_ZERO_ERROR
;
1234 initField(&fStandaloneNarrowMonths
, fStandaloneNarrowMonthsCount
, calData
.getByKey2(gMonthNamesTag
, gNamesNarrowTag
, status
), status
);
1235 if ( status
== U_MISSING_RESOURCE_ERROR
) { /* if still not there, use format/abbreviated */
1236 status
= U_ZERO_ERROR
;
1237 initField(&fStandaloneNarrowMonths
, fStandaloneNarrowMonthsCount
, calData
.getByKey2(gMonthNamesTag
, gNamesAbbrTag
, status
), status
);
1240 initField(&fAmPms
, fAmPmsCount
, calData
.getByKey(gAmPmMarkersTag
, status
), status
);
1242 initField(&fQuarters
, fQuartersCount
, calData
.getByKey2(gQuartersTag
, gNamesWideTag
, status
), status
);
1243 initField(&fShortQuarters
, fShortQuartersCount
, calData
.getByKey2(gQuartersTag
, gNamesAbbrTag
, status
), status
);
1245 initField(&fStandaloneQuarters
, fStandaloneQuartersCount
, calData
.getByKey3(gQuartersTag
, gNamesStandaloneTag
, gNamesWideTag
, status
), status
);
1246 if(status
== U_MISSING_RESOURCE_ERROR
) {
1247 status
= U_ZERO_ERROR
;
1248 initField(&fStandaloneQuarters
, fStandaloneQuartersCount
, calData
.getByKey2(gQuartersTag
, gNamesWideTag
, status
), status
);
1251 initField(&fStandaloneShortQuarters
, fStandaloneShortQuartersCount
, calData
.getByKey3(gQuartersTag
, gNamesStandaloneTag
, gNamesAbbrTag
, status
), status
);
1252 if(status
== U_MISSING_RESOURCE_ERROR
) {
1253 status
= U_ZERO_ERROR
;
1254 initField(&fStandaloneShortQuarters
, fStandaloneShortQuartersCount
, calData
.getByKey2(gQuartersTag
, gNamesAbbrTag
, status
), status
);
1257 // fastCopyFrom()/setTo() - see assignArray comments
1258 resStr
= ures_getStringByKey(fResourceBundle
, gLocalPatternCharsTag
, &len
, &status
);
1259 fLocalPatternChars
.setTo(TRUE
, resStr
, len
);
1260 // If the locale data does not include new pattern chars, use the defaults
1261 // TODO: Consider making this an error, since this may add conflicting characters.
1262 if (len
< PATTERN_CHARS_LEN
) {
1263 fLocalPatternChars
.append(UnicodeString(TRUE
, &gPatternChars
[len
], PATTERN_CHARS_LEN
-len
));
1266 // {sfb} fixed to handle 1-based weekdays
1267 weekdaysData
= calData
.getByKey2(gDayNamesTag
, gNamesWideTag
, status
);
1268 fWeekdaysCount
= ures_getSize(weekdaysData
);
1269 fWeekdays
= new UnicodeString
[fWeekdaysCount
+1];
1270 /* pin the blame on system. If we cannot get a chunk of memory .. the system is dying!*/
1271 if (fWeekdays
== NULL
) {
1272 status
= U_MEMORY_ALLOCATION_ERROR
;
1275 // leave fWeekdays[0] empty
1276 for(i
= 0; i
<fWeekdaysCount
; i
++) {
1277 resStr
= ures_getStringByIndex(weekdaysData
, i
, &len
, &status
);
1278 // setTo() - see assignArray comments
1279 fWeekdays
[i
+1].setTo(TRUE
, resStr
, len
);
1283 lsweekdaysData
= calData
.getByKey2(gDayNamesTag
, gNamesAbbrTag
, status
);
1284 fShortWeekdaysCount
= ures_getSize(lsweekdaysData
);
1285 fShortWeekdays
= new UnicodeString
[fShortWeekdaysCount
+1];
1287 if (fShortWeekdays
== 0) {
1288 status
= U_MEMORY_ALLOCATION_ERROR
;
1291 // leave fShortWeekdays[0] empty
1292 for(i
= 0; i
<fShortWeekdaysCount
; i
++) {
1293 resStr
= ures_getStringByIndex(lsweekdaysData
, i
, &len
, &status
);
1294 // setTo() - see assignArray comments
1295 fShortWeekdays
[i
+1].setTo(TRUE
, resStr
, len
);
1297 fShortWeekdaysCount
++;
1299 narrowWeekdaysData
= calData
.getByKey2(gDayNamesTag
, gNamesNarrowTag
, status
);
1300 if(status
== U_MISSING_RESOURCE_ERROR
) {
1301 status
= U_ZERO_ERROR
;
1302 narrowWeekdaysData
= calData
.getByKey3(gDayNamesTag
, gNamesStandaloneTag
, gNamesNarrowTag
, status
);
1304 if ( status
== U_MISSING_RESOURCE_ERROR
) {
1305 status
= U_ZERO_ERROR
;
1306 narrowWeekdaysData
= calData
.getByKey2(gDayNamesTag
, gNamesAbbrTag
, status
);
1308 fNarrowWeekdaysCount
= ures_getSize(narrowWeekdaysData
);
1309 fNarrowWeekdays
= new UnicodeString
[fNarrowWeekdaysCount
+1];
1311 if (fNarrowWeekdays
== 0) {
1312 status
= U_MEMORY_ALLOCATION_ERROR
;
1315 // leave fNarrowWeekdays[0] empty
1316 for(i
= 0; i
<fNarrowWeekdaysCount
; i
++) {
1317 resStr
= ures_getStringByIndex(narrowWeekdaysData
, i
, &len
, &status
);
1318 // setTo() - see assignArray comments
1319 fNarrowWeekdays
[i
+1].setTo(TRUE
, resStr
, len
);
1321 fNarrowWeekdaysCount
++;
1323 standaloneWeekdaysData
= calData
.getByKey3(gDayNamesTag
, gNamesStandaloneTag
, gNamesWideTag
, status
);
1324 if ( status
== U_MISSING_RESOURCE_ERROR
) {
1325 status
= U_ZERO_ERROR
;
1326 standaloneWeekdaysData
= calData
.getByKey2(gDayNamesTag
, gNamesWideTag
, status
);
1328 fStandaloneWeekdaysCount
= ures_getSize(standaloneWeekdaysData
);
1329 fStandaloneWeekdays
= new UnicodeString
[fStandaloneWeekdaysCount
+1];
1331 if (fStandaloneWeekdays
== 0) {
1332 status
= U_MEMORY_ALLOCATION_ERROR
;
1335 // leave fStandaloneWeekdays[0] empty
1336 for(i
= 0; i
<fStandaloneWeekdaysCount
; i
++) {
1337 resStr
= ures_getStringByIndex(standaloneWeekdaysData
, i
, &len
, &status
);
1338 // setTo() - see assignArray comments
1339 fStandaloneWeekdays
[i
+1].setTo(TRUE
, resStr
, len
);
1341 fStandaloneWeekdaysCount
++;
1343 standaloneShortWeekdaysData
= calData
.getByKey3(gDayNamesTag
, gNamesStandaloneTag
, gNamesAbbrTag
, status
);
1344 if ( status
== U_MISSING_RESOURCE_ERROR
) {
1345 status
= U_ZERO_ERROR
;
1346 standaloneShortWeekdaysData
= calData
.getByKey2(gDayNamesTag
, gNamesAbbrTag
, status
);
1348 fStandaloneShortWeekdaysCount
= ures_getSize(standaloneShortWeekdaysData
);
1349 fStandaloneShortWeekdays
= new UnicodeString
[fStandaloneShortWeekdaysCount
+1];
1351 if (fStandaloneShortWeekdays
== 0) {
1352 status
= U_MEMORY_ALLOCATION_ERROR
;
1355 // leave fStandaloneShortWeekdays[0] empty
1356 for(i
= 0; i
<fStandaloneShortWeekdaysCount
; i
++) {
1357 resStr
= ures_getStringByIndex(standaloneShortWeekdaysData
, i
, &len
, &status
);
1358 // setTo() - see assignArray comments
1359 fStandaloneShortWeekdays
[i
+1].setTo(TRUE
, resStr
, len
);
1361 fStandaloneShortWeekdaysCount
++;
1363 standaloneNarrowWeekdaysData
= calData
.getByKey3(gDayNamesTag
, gNamesStandaloneTag
, gNamesNarrowTag
, status
);
1364 if ( status
== U_MISSING_RESOURCE_ERROR
) {
1365 status
= U_ZERO_ERROR
;
1366 standaloneNarrowWeekdaysData
= calData
.getByKey2(gDayNamesTag
, gNamesNarrowTag
, status
);
1367 if ( status
== U_MISSING_RESOURCE_ERROR
) {
1368 status
= U_ZERO_ERROR
;
1369 standaloneNarrowWeekdaysData
= calData
.getByKey2(gDayNamesTag
, gNamesAbbrTag
, status
);
1372 fStandaloneNarrowWeekdaysCount
= ures_getSize(standaloneNarrowWeekdaysData
);
1373 fStandaloneNarrowWeekdays
= new UnicodeString
[fStandaloneNarrowWeekdaysCount
+1];
1375 if (fStandaloneNarrowWeekdays
== 0) {
1376 status
= U_MEMORY_ALLOCATION_ERROR
;
1379 // leave fStandaloneNarrowWeekdays[0] empty
1380 for(i
= 0; i
<fStandaloneNarrowWeekdaysCount
; i
++) {
1381 resStr
= ures_getStringByIndex(standaloneNarrowWeekdaysData
, i
, &len
, &status
);
1382 // setTo() - see assignArray comments
1383 fStandaloneNarrowWeekdays
[i
+1].setTo(TRUE
, resStr
, len
);
1385 fStandaloneNarrowWeekdaysCount
++;
1389 ures_close(eraNames
);
1393 * Package private: used by SimpleDateFormat
1394 * Gets the index for the given time zone ID to obtain the timezone
1395 * strings for formatting. The time zone ID is just for programmatic
1396 * lookup. NOT LOCALIZED!!!
1397 * @param ID the given time zone ID.
1398 * @return the index of the given time zone ID. Returns -1 if
1399 * the given time zone ID can't be located in the DateFormatSymbols object.
1400 * @see java.util.SimpleTimeZone
1402 int32_t DateFormatSymbols::getZoneIndex(const UnicodeString
& ID
) const
1404 int32_t result
= _getZoneIndex(ID
);
1409 // Do a search through the equivalency group for the given ID
1410 int32_t n
= TimeZone::countEquivalentIDs(ID
);
1413 for (i
=0; i
<n
; ++i
) {
1414 UnicodeString equivID
= TimeZone::getEquivalentID(ID
, i
);
1415 if (equivID
!= ID
) {
1416 int32_t equivResult
= _getZoneIndex(equivID
);
1417 if (equivResult
>= 0) {
1428 * Lookup the given ID. Do NOT do an equivalency search.
1430 int32_t DateFormatSymbols::_getZoneIndex(const UnicodeString
& ID
) const
1432 for(int32_t index
= 0; index
< fZoneStringsRowCount
; index
++) {
1433 if (0 == ID
.caseCompare(fZoneStrings
[index
][0], 0)) {
1442 DateFormatSymbols::getLocale(ULocDataLocaleType type
, UErrorCode
& status
) const {
1443 U_LOCALE_BASED(locBased
, *this);
1444 return locBased
.getLocale(type
, status
);
1447 class TimeZoneKeysEnumeration
: public StringEnumeration
{
1449 UnicodeString
* strings
;
1453 TimeZoneKeysEnumeration(UnicodeString
* oldStrs
, int32_t count
){
1454 strings
= newUnicodeStringArray(count
);
1460 for(length
= 0; length
<capacity
; length
++){
1461 strings
[length
].setTo(oldStrs
[length
]);
1465 static UClassID U_EXPORT2
getStaticClassID(void);
1466 virtual UClassID
getDynamicClassID(void) const;
1468 TimeZoneKeysEnumeration(int32_t count
, UErrorCode status
){
1469 strings
= newUnicodeStringArray(count
);
1470 if(strings
== NULL
){
1471 status
= U_MEMORY_ALLOCATION_ERROR
;
1478 void put(const UnicodeString
& str
, UErrorCode
& status
){
1479 if(length
< capacity
){
1480 strings
[length
++].setTo(str
);
1482 status
= U_INDEX_OUTOFBOUNDS_ERROR
;
1485 virtual ~TimeZoneKeysEnumeration() {
1489 virtual StringEnumeration
* clone() const
1491 return new TimeZoneKeysEnumeration(strings
, length
);
1494 virtual int32_t count(UErrorCode
&/*status*/) const {
1497 virtual const UChar
* unext(int32_t *resultLength
, UErrorCode
& /*status*/){
1498 if(current
< length
){
1499 const UChar
* ret
= strings
[current
].getBuffer();
1500 *resultLength
= strings
[current
].length();
1507 virtual const UnicodeString
* snext(UErrorCode
& status
) {
1508 if(U_FAILURE(status
)){
1511 if(current
< length
){
1512 return &strings
[current
++];
1516 /* this method is for thread safe iteration */
1517 const UnicodeString
* snext(int32_t& pos
, UErrorCode
& status
)const {
1518 if(U_FAILURE(status
)){
1522 return &strings
[pos
++];
1527 virtual void reset(UErrorCode
& /*status*/) {
1532 UBool
equals(const StringEnumeration
& other
) const{
1533 if (other
.getDynamicClassID() != TimeZoneKeysEnumeration::getStaticClassID()) {
1536 TimeZoneKeysEnumeration
& enum2
= (TimeZoneKeysEnumeration
&)(other
);
1537 UErrorCode status
= U_ZERO_ERROR
;
1539 int32_t count1
= count(status
);
1540 int32_t count2
= other
.count(status
);
1541 if(count1
!= count2
){
1546 const UnicodeString
* str1
= NULL
;
1547 const UnicodeString
* str2
= NULL
;
1549 while((str1
= snext(pos1
, status
))!=NULL
){
1550 str2
= enum2
.snext(pos2
, status
);
1551 if(U_FAILURE(status
)){
1555 // bail out at the first failure
1560 // if we reached here that means that the enumerations are equal
1564 virtual UBool
operator==(const StringEnumeration
& that
)const{
1565 return ((this == &that
) ||
1566 (getDynamicClassID() == that
.getDynamicClassID() &&
1567 StringEnumeration::operator==(that
) &&
1572 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TimeZoneKeysEnumeration
)
1575 DateFormatSymbols::initZoneStringsArray(UErrorCode
& status
){
1576 if(fZoneStringsHash
== NULL
){
1577 initZoneStrings(status
);
1579 if(U_FAILURE(status
)){
1582 fZoneStringsRowCount
= fZoneIDEnumeration
->count(status
);
1583 fZoneStringsColCount
= 8;
1584 fZoneStrings
= (UnicodeString
**)uprv_malloc(fZoneStringsRowCount
* sizeof(UnicodeString
*));
1585 /* if we can't get a chunk of heap then the system is going down. Pin the blame on system*/
1586 if (fZoneStrings
== NULL
) {
1587 status
= U_MEMORY_ALLOCATION_ERROR
;
1590 const UnicodeString
*zid
= NULL
;
1591 TimeZoneKeysEnumeration
*keys
= (TimeZoneKeysEnumeration
*) fZoneIDEnumeration
;
1594 while((zid
=keys
->snext(pos
,status
))!=NULL
){
1595 *(fZoneStrings
+i
) = newUnicodeStringArray(fZoneStringsColCount
);
1597 if ((*(fZoneStrings
+i
)) == 0) {
1598 status
= U_MEMORY_ALLOCATION_ERROR
;
1601 UnicodeString
* strings
= (UnicodeString
*)fZoneStringsHash
->get(*zid
);
1602 fZoneStrings
[i
][0].setTo(*zid
);
1603 fZoneStrings
[i
][1].setTo(strings
[TIMEZONE_LONG_STANDARD
]);
1604 fZoneStrings
[i
][2].setTo(strings
[TIMEZONE_SHORT_STANDARD
]);
1605 fZoneStrings
[i
][3].setTo(strings
[TIMEZONE_LONG_DAYLIGHT
]);
1606 fZoneStrings
[i
][4].setTo(strings
[TIMEZONE_SHORT_DAYLIGHT
]);
1607 fZoneStrings
[i
][5].setTo(strings
[TIMEZONE_EXEMPLAR_CITY
]);
1608 if(fZoneStrings
[i
][5].length()==0){
1609 fZoneStrings
[i
][5].setTo(strings
[TIMEZONE_LONG_GENERIC
]);
1611 fZoneStrings
[i
][6].setTo(strings
[TIMEZONE_LONG_GENERIC
]);
1613 if(fZoneStrings
[i
][6].length()==0){
1614 fZoneStrings
[i
][6].setTo(strings
[TIMEZONE_LONG_GENERIC
]);
1616 fZoneStrings
[i
][7].setTo(strings
[TIMEZONE_LONG_GENERIC
]);
1623 static UBool U_CALLCONV
1624 compareTZHashValues(const UHashTok val1
, const UHashTok val2
){
1626 const UnicodeString
* array1
= (UnicodeString
*) val1
.pointer
;
1627 const UnicodeString
* array2
= (UnicodeString
*) val2
.pointer
;
1631 if(array1
==NULL
|| array2
==NULL
){
1634 for(int32_t j
=0; j
< UTZ_MAX_DISPLAY_STRINGS_LENGTH
; j
++){
1635 if(array1
[j
] != array2
[j
]){
1644 DateFormatSymbols::initZoneStrings(UErrorCode
&status
){
1645 if(U_FAILURE(status
)){
1649 if(fZoneStringsHash
!= NULL
){
1654 fZoneStringsHash
= new Hashtable(uhash_compareUnicodeString
, compareTZHashValues
, status
);
1655 if(fZoneStringsHash
==NULL
){
1656 status
= U_MEMORY_ALLOCATION_ERROR
;
1659 fZoneStringsHash
->setValueDeleter(deleteUnicodeStringArray
);
1661 if(fResourceBundle
!= NULL
){
1662 UnicodeString solidus
= UNICODE_STRING_SIMPLE("/");
1663 UnicodeString colon
= UNICODE_STRING_SIMPLE(":");
1664 UResourceBundle zoneArray
,zoneItem
;
1665 ures_initStackObject(&zoneItem
);
1666 ures_initStackObject(&zoneArray
);
1667 for(const UResourceBundle
* rb
= fResourceBundle
; rb
!=NULL
; rb
=ures_getParentBundle(rb
)){
1668 ures_getByKey(rb
, gZoneStringsTag
, &zoneArray
, &status
);
1669 if(U_FAILURE(status
)){
1672 while(ures_hasNext(&zoneArray
)){
1673 UErrorCode tempStatus
= U_ZERO_ERROR
;
1674 UnicodeString
* array
= newUnicodeStringArray(UTZ_MAX_DISPLAY_STRINGS_LENGTH
);
1675 ures_getNextResource(&zoneArray
, &zoneItem
, &status
);
1676 UnicodeString
key(ures_getKey(&zoneItem
), -1, US_INV
);
1677 key
.findAndReplace(colon
, solidus
);
1679 //fetch the strings with fine grained fallback
1680 const UChar
* str
= ures_getStringByKeyWithFallback(&zoneItem
,UTZ_SHORT_STANDARD
, &len
, &tempStatus
);
1681 if(U_SUCCESS(tempStatus
)){
1682 array
[TIMEZONE_SHORT_STANDARD
].setTo(TRUE
, str
, len
);
1684 tempStatus
= U_ZERO_ERROR
;
1686 str
= ures_getStringByKeyWithFallback(&zoneItem
,UTZ_SHORT_GENERIC
, &len
, &tempStatus
);
1687 if(U_SUCCESS(tempStatus
)){
1688 array
[TIMEZONE_SHORT_GENERIC
].setTo(TRUE
, str
, len
);
1690 tempStatus
= U_ZERO_ERROR
;
1692 str
= ures_getStringByKeyWithFallback(&zoneItem
,UTZ_SHORT_DAYLIGHT
, &len
, &tempStatus
);
1693 if(U_SUCCESS(tempStatus
)){
1694 array
[TIMEZONE_SHORT_DAYLIGHT
].setTo(TRUE
, str
, len
);
1696 tempStatus
= U_ZERO_ERROR
;
1698 str
= ures_getStringByKeyWithFallback(&zoneItem
,UTZ_LONG_STANDARD
, &len
, &tempStatus
);
1699 if(U_SUCCESS(tempStatus
)){
1700 array
[TIMEZONE_LONG_STANDARD
].setTo(TRUE
, str
, len
);
1702 tempStatus
= U_ZERO_ERROR
;
1704 str
= ures_getStringByKeyWithFallback(&zoneItem
,UTZ_LONG_GENERIC
, &len
, &tempStatus
);
1705 if(U_SUCCESS(tempStatus
)){
1706 array
[TIMEZONE_LONG_GENERIC
].setTo(TRUE
, str
, len
);
1708 tempStatus
= U_ZERO_ERROR
;
1710 str
= ures_getStringByKeyWithFallback(&zoneItem
,UTZ_LONG_DAYLIGHT
, &len
, &tempStatus
);
1711 if(U_SUCCESS(tempStatus
)){
1712 array
[TIMEZONE_LONG_DAYLIGHT
].setTo(TRUE
, str
, len
);
1714 tempStatus
= U_ZERO_ERROR
;
1716 str
= ures_getStringByKeyWithFallback(&zoneItem
,UTZ_EXEMPLAR_CITY
, &len
, &tempStatus
);
1717 if(U_SUCCESS(tempStatus
)){
1718 array
[TIMEZONE_EXEMPLAR_CITY
].setTo(TRUE
, str
, len
);
1720 tempStatus
= U_ZERO_ERROR
;
1722 // store the strings in hash
1723 fZoneStringsHash
->put(key
, array
, status
);
1725 ures_close(&zoneItem
);
1726 ures_close(&zoneArray
);
1728 int32_t length
= fZoneStringsHash
->count();
1729 TimeZoneKeysEnumeration
* keysEnum
= new TimeZoneKeysEnumeration(length
, status
);
1730 fZoneIDEnumeration
= keysEnum
;
1731 if(fZoneIDEnumeration
==NULL
){
1732 delete fZoneStringsHash
;
1733 fZoneStringsHash
= NULL
;
1734 status
= U_MEMORY_ALLOCATION_ERROR
;
1738 const UnicodeString
* key
;
1739 const UHashElement
* elem
= NULL
;
1740 while((elem
= fZoneStringsHash
->nextElement(pos
))!= NULL
){
1741 const UHashTok keyTok
= elem
->key
;
1742 key
= (const UnicodeString
*)keyTok
.pointer
;
1743 keysEnum
->put(*key
, status
);
1746 //last resort strings
1747 UnicodeString
* array
= newUnicodeStringArray(UTZ_MAX_DISPLAY_STRINGS_LENGTH
);
1749 delete fZoneStringsHash
;
1750 status
= U_MEMORY_ALLOCATION_ERROR
;
1753 int32_t length
= ARRAY_LENGTH(gLastResortZoneStrings
);
1754 UnicodeString
key(gLastResortZoneStrings
[0]);
1755 TimeZoneKeysEnumeration
* keysEnum
= new TimeZoneKeysEnumeration(length
, status
);
1756 fZoneIDEnumeration
= keysEnum
;
1757 if(fZoneIDEnumeration
==NULL
){
1758 delete fZoneStringsHash
;
1760 fZoneStringsHash
= NULL
;
1761 status
= U_MEMORY_ALLOCATION_ERROR
;
1764 keysEnum
->put(key
, status
);
1766 for(i
=0; i
< length
; ){
1767 array
[i
++].setTo(gLastResortZoneStrings
[j
++]);
1769 fZoneStringsHash
->put(key
, array
, status
);
1773 DateFormatSymbols::initZoneStrings(const UnicodeString
** strings
, int32_t rowCount
, int32_t columnCount
, UErrorCode
& status
){
1774 if(strings
==NULL
|| rowCount
<0 || columnCount
<0){
1775 status
= U_ILLEGAL_ARGUMENT_ERROR
;
1778 TimeZoneKeysEnumeration
* keysEnum
= new TimeZoneKeysEnumeration(rowCount
, status
);
1779 fZoneIDEnumeration
= keysEnum
;
1780 if(U_FAILURE(status
)){
1783 if(fZoneIDEnumeration
==NULL
){
1784 status
= U_MEMORY_ALLOCATION_ERROR
;
1787 fZoneStringsHash
= new Hashtable(uhash_compareUnicodeString
, compareTZHashValues
, status
);
1788 if(U_FAILURE(status
)){
1791 if(fZoneStringsHash
==NULL
){
1792 status
= U_MEMORY_ALLOCATION_ERROR
;
1795 fZoneStringsHash
->setValueDeleter(deleteUnicodeStringArray
);
1796 for (int32_t row
=0; row
<rowCount
; ++row
){
1797 // the first string in the array is the key.
1798 UnicodeString key
= strings
[row
][0];
1799 keysEnum
->put(key
, status
);
1800 UnicodeString
* array
= newUnicodeStringArray(UTZ_MAX_DISPLAY_STRINGS_LENGTH
);
1802 status
= U_MEMORY_ALLOCATION_ERROR
;
1805 for (int32_t col
=1; col
<columnCount
; ++col
) {
1806 // fastCopyFrom() - see assignArray comments
1809 array
[TIMEZONE_LONG_STANDARD
].setTo(strings
[row
][col
]);
1812 array
[TIMEZONE_SHORT_STANDARD
].setTo(strings
[row
][col
]);
1815 array
[TIMEZONE_LONG_DAYLIGHT
].setTo(strings
[row
][col
]);
1818 array
[TIMEZONE_LONG_DAYLIGHT
].setTo(strings
[row
][col
]);
1821 if(fZoneStringsColCount
==6 || fZoneStringsColCount
==8){
1822 array
[TIMEZONE_EXEMPLAR_CITY
].setTo(strings
[row
][col
]);
1824 array
[TIMEZONE_LONG_GENERIC
].setTo(strings
[row
][col
]);
1828 if(fZoneStringsColCount
==8){
1829 array
[TIMEZONE_LONG_GENERIC
].setTo(strings
[row
][col
]);
1831 array
[TIMEZONE_SHORT_GENERIC
].setTo(strings
[row
][col
]);
1835 array
[TIMEZONE_SHORT_GENERIC
].setTo(strings
[row
][col
]);
1838 status
= U_ILLEGAL_ARGUMENT_ERROR
;
1840 // populate the hash table
1841 fZoneStringsHash
->put(strings
[row
][0], array
, status
);
1848 DateFormatSymbols::getZoneString(const UnicodeString
&zid
, const TimeZoneTranslationType type
,
1849 UnicodeString
&result
, UErrorCode
&status
){
1851 if(fZoneStringsHash
== NULL
){
1852 //lazy initialization
1853 initZoneStrings(status
);
1855 if(U_FAILURE(status
)){
1858 UnicodeString
* stringsArray
= (UnicodeString
*)fZoneStringsHash
->get(zid
);
1859 if(stringsArray
!= NULL
){
1860 result
.setTo(stringsArray
[type
],0);
1867 DateFormatSymbols::createZoneStringIDs(UErrorCode
&status
){
1868 if(U_FAILURE(status
)){
1871 if(fZoneStringsHash
== NULL
){
1872 //lazy initialization
1873 initZoneStrings(status
);
1875 return fZoneIDEnumeration
->clone();
1879 * Sets timezone strings.
1883 DateFormatSymbols::setZoneString(const UnicodeString
&zid
, const TimeZoneTranslationType type
,
1884 const UnicodeString
&value
, UErrorCode
&status
){
1885 if(fZoneStringsHash
== NULL
){
1886 //lazy initialization
1887 initZoneStrings(status
);
1889 if(U_FAILURE(status
)){
1892 UnicodeString
* stringsArray
= (UnicodeString
*)fZoneStringsHash
->get(zid
);
1893 if(stringsArray
!= NULL
){
1894 stringsArray
[type
].setTo(value
);
1896 stringsArray
= newUnicodeStringArray(UTZ_MAX_DISPLAY_STRINGS_LENGTH
);
1897 if(stringsArray
==NULL
){
1898 status
= U_MEMORY_ALLOCATION_ERROR
;
1901 stringsArray
[type
].setTo(value
);
1902 fZoneStringsHash
->put(zid
, stringsArray
, status
);
1903 TimeZoneKeysEnumeration
* keys
= (TimeZoneKeysEnumeration
*) fZoneIDEnumeration
;
1904 keys
->put(zid
, status
);
1909 DateFormatSymbols::createZoneStringsHash(const Hashtable
* otherHash
){
1910 UErrorCode status
= U_ZERO_ERROR
;
1911 Hashtable
* hash
= new Hashtable(uhash_compareUnicodeString
, compareTZHashValues
, status
);
1915 if(U_FAILURE(status
)){
1918 hash
->setValueDeleter(deleteUnicodeStringArray
);
1920 const UHashElement
* elem
= NULL
;
1921 // walk through the hash table and create a deep clone
1922 while((elem
= otherHash
->nextElement(pos
))!= NULL
){
1923 const UHashTok otherKeyTok
= elem
->key
;
1924 const UHashTok otherValueTok
= elem
->value
;
1925 UnicodeString
* otherKey
= (UnicodeString
*)otherKeyTok
.pointer
;
1926 UnicodeString
* otherArray
= (UnicodeString
*)otherValueTok
.pointer
;
1927 UnicodeString
* array
= newUnicodeStringArray(UTZ_MAX_DISPLAY_STRINGS_LENGTH
);
1931 UnicodeString
key(*otherKey
);
1932 for(int32_t i
=0; i
<UTZ_MAX_DISPLAY_STRINGS_LENGTH
; i
++){
1933 array
[i
].setTo(otherArray
[i
]);
1935 hash
->put(key
, array
, status
);
1936 if(U_FAILURE(status
)){
1946 DateFormatSymbols::getZoneID(const UnicodeString
& zid
, UnicodeString
& result
, UErrorCode
& status
){
1947 if(fZoneStringsHash
== NULL
){
1948 initZoneStrings(status
);
1950 if(U_FAILURE(status
)){
1953 UnicodeString
* strings
= (UnicodeString
*)fZoneStringsHash
->get(zid
);
1954 if (strings
!= NULL
) {
1955 return result
.setTo(zid
,0);
1958 // Do a search through the equivalency group for the given ID
1959 int32_t n
= TimeZone::countEquivalentIDs(zid
);
1962 for (i
=0; i
<n
; ++i
) {
1963 UnicodeString equivID
= TimeZone::getEquivalentID(zid
, i
);
1964 if (equivID
!= zid
) {
1965 strings
= (UnicodeString
*)fZoneStringsHash
->get(equivID
);
1966 if (strings
!= NULL
) {
1967 return result
.setTo(equivID
,0);
1978 DateFormatSymbols::getZoneType(const UnicodeString
& zid
, const UnicodeString
& text
, int32_t start
,
1979 TimeZoneTranslationType
& type
, UnicodeString
& value
, UErrorCode
& status
){
1980 if(fZoneStringsHash
== NULL
){
1981 initZoneStrings(status
);
1983 if(U_FAILURE(status
)){
1986 type
= TIMEZONE_COUNT
;
1987 UnicodeString
* strings
= (UnicodeString
*)fZoneStringsHash
->get(zid
);
1988 if(strings
!= NULL
){
1989 for(int32_t j
=0; j
<UTZ_MAX_DISPLAY_STRINGS_LENGTH
; j
++){
1990 if(strings
[j
].length() >0 && text
.caseCompare(start
, strings
[j
].length(), strings
[j
], 0)==0){
1991 type
= (TimeZoneTranslationType
)j
;
1992 value
.setTo(strings
[j
]);
1999 DateFormatSymbols::findZoneIDTypeValue( UnicodeString
& zid
, const UnicodeString
& text
, int32_t start
,
2000 TimeZoneTranslationType
& type
, UnicodeString
& value
,
2001 UErrorCode
& status
){
2002 if(fZoneStringsHash
== NULL
){
2003 initZoneStrings(status
);
2005 if(U_FAILURE(status
)){
2008 const UnicodeString
* myKey
= NULL
;
2010 TimeZoneKeysEnumeration
*keys
= (TimeZoneKeysEnumeration
*)fZoneIDEnumeration
;
2011 while( (myKey
=keys
->snext(pos
, status
))!= NULL
){
2012 UnicodeString
* strings
= (UnicodeString
*)fZoneStringsHash
->get(*myKey
);
2013 if(strings
!= NULL
){
2014 for(int32_t j
=0; j
<UTZ_MAX_DISPLAY_STRINGS_LENGTH
; j
++){
2015 if(strings
[j
].length()>0 && text
.caseCompare(start
, strings
[j
].length(), strings
[j
], 0)==0){
2016 type
= (TimeZoneTranslationType
)j
;
2017 value
.setTo(strings
[j
]);
2027 #endif /* #if !UCONFIG_NO_FORMATTING */