]> git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/dtfmtsym.cpp
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / i18n / dtfmtsym.cpp
1 /*
2 *******************************************************************************
3 * Copyright (C) 1997-2003, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
6 *
7 * File DTFMTSYM.CPP
8 *
9 * Modification History:
10 *
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 *******************************************************************************
19 */
20
21 #include "unicode/utypes.h"
22
23 #if !UCONFIG_NO_FORMATTING
24
25 #include "unicode/dtfmtsym.h"
26 #include "unicode/resbund.h"
27 #include "unicode/smpdtfmt.h"
28 #include "ucln_in.h"
29 #include "mutex.h"
30 #include "cmemory.h"
31 #include "cstring.h"
32
33 // *****************************************************************************
34 // class DateFormatSymbols
35 // *****************************************************************************
36 /**
37 * These are static arrays we use only in the case where we have no
38 * resource data.
39 */
40
41 #define PATTERN_CHARS_LEN 20
42
43 /**
44 * Unlocalized date-time pattern characters. For example: 'y', 'd', etc. All
45 * locales use the same these unlocalized pattern characters.
46 */
47 static const UChar gPatternChars[] =
48 {
49 0x47, 0x79, 0x4D, 0x64, 0x6B, 0x48, 0x6D, 0x73, 0x53, 0x45,
50 0x44, 0x46, 0x77, 0x57, 0x61, 0x68, 0x4B, 0x7A, 0x59, 0x65, 0 /* "GyMdkHmsSEDFwWahKzYe" */
51 };
52
53 //------------------------------------------------------
54 // Strings of last resort. These are only used if we have no resource
55 // files. They aren't designed for actual use, just for backup.
56
57 // These are the month names and abbreviations of last resort.
58 static const UChar gLastResortMonthNames[13][3] =
59 {
60 {0x0030, 0x0031, 0x0000}, /* "01" */
61 {0x0030, 0x0032, 0x0000}, /* "02" */
62 {0x0030, 0x0033, 0x0000}, /* "03" */
63 {0x0030, 0x0034, 0x0000}, /* "04" */
64 {0x0030, 0x0035, 0x0000}, /* "05" */
65 {0x0030, 0x0036, 0x0000}, /* "06" */
66 {0x0030, 0x0037, 0x0000}, /* "07" */
67 {0x0030, 0x0038, 0x0000}, /* "08" */
68 {0x0030, 0x0039, 0x0000}, /* "09" */
69 {0x0031, 0x0030, 0x0000}, /* "10" */
70 {0x0031, 0x0031, 0x0000}, /* "11" */
71 {0x0031, 0x0032, 0x0000}, /* "12" */
72 {0x0031, 0x0033, 0x0000} /* "13" */
73 };
74
75 // These are the weekday names and abbreviations of last resort.
76 static const UChar gLastResortDayNames[8][2] =
77 {
78 {0x0000, 0x0000}, /* "" */
79 {0x0031, 0x0000}, /* "1" */
80 {0x0032, 0x0000}, /* "2" */
81 {0x0033, 0x0000}, /* "3" */
82 {0x0034, 0x0000}, /* "4" */
83 {0x0035, 0x0000}, /* "5" */
84 {0x0036, 0x0000}, /* "6" */
85 {0x0037, 0x0000} /* "7" */
86 };
87
88 // These are the am/pm and BC/AD markers of last resort.
89 static const UChar gLastResortAmPmMarkers[2][3] =
90 {
91 {0x0041, 0x004D, 0x0000}, /* "AM" */
92 {0x0050, 0x004D, 0x0000} /* "PM" */
93 };
94
95 static const UChar gLastResortEras[2][3] =
96 {
97 {0x0042, 0x0043, 0x0000}, /* "BC" */
98 {0x0041, 0x0044, 0x0000} /* "AD" */
99 };
100
101
102 // These are the zone strings of last resort.
103 static const UChar gLastResortZoneStrings[5][4] =
104 {
105 {0x0047, 0x004D, 0x0054, 0x0000}, /* "GMT" */
106 {0x0047, 0x004D, 0x0054, 0x0000}, /* "GMT" */
107 {0x0047, 0x004D, 0x0054, 0x0000}, /* "GMT" */
108 {0x0047, 0x004D, 0x0054, 0x0000}, /* "GMT" */
109 {0x0047, 0x004D, 0x0054, 0x0000} /* "GMT" */
110 };
111
112 U_NAMESPACE_BEGIN
113
114 const char DateFormatSymbols::fgClassID=0;
115
116 /**
117 * These are the tags we expect to see in normal resource bundle files associated
118 * with a locale.
119 */
120 const char DateFormatSymbols::fgErasTag[]="Eras";
121 const char DateFormatSymbols::fgMonthNamesTag[]="MonthNames";
122 const char DateFormatSymbols::fgMonthAbbreviationsTag[]="MonthAbbreviations";
123 const char DateFormatSymbols::fgDayNamesTag[]="DayNames";
124 const char DateFormatSymbols::fgDayAbbreviationsTag[]="DayAbbreviations";
125 const char DateFormatSymbols::fgAmPmMarkersTag[]="AmPmMarkers";
126
127 /**
128 * These are the tags we expect to see in time zone data resource bundle files
129 * associated with a locale.
130 */
131 const char DateFormatSymbols::fgZoneStringsTag[]="zoneStrings";
132 const char DateFormatSymbols::fgLocalPatternCharsTag[]="localPatternChars";
133
134 /**
135 * Jitterbug 2974: MSVC has a bug whereby new X[0] behaves badly.
136 * Work around this.
137 */
138 static inline UnicodeString* newUnicodeStringArray(size_t count) {
139 return new UnicodeString[count ? count : 1];
140 }
141
142 //------------------------------------------------------
143
144 DateFormatSymbols::DateFormatSymbols(const Locale& locale,
145 UErrorCode& status)
146 : UObject()
147 {
148 initializeData(locale, NULL, status);
149 }
150
151 DateFormatSymbols::DateFormatSymbols(UErrorCode& status)
152 : UObject()
153 {
154 initializeData(Locale::getDefault(), NULL, status, TRUE);
155 }
156
157
158 DateFormatSymbols::DateFormatSymbols(const Locale& locale,
159 const char *type,
160 UErrorCode& status)
161 : UObject()
162 {
163 initializeData(locale, type, status);
164 }
165
166 DateFormatSymbols::DateFormatSymbols(const char *type, UErrorCode& status)
167 : UObject()
168 {
169 initializeData(Locale::getDefault(), type, status, TRUE);
170 }
171
172 DateFormatSymbols::DateFormatSymbols(const DateFormatSymbols& other)
173 : UObject(other)
174 {
175 copyData(other);
176 }
177
178 void
179 DateFormatSymbols::assignArray(UnicodeString*& dstArray,
180 int32_t& dstCount,
181 const UnicodeString* srcArray,
182 int32_t srcCount)
183 {
184 // assignArray() is only called by copyData(), which in turn implements the
185 // copy constructor and the assignment operator.
186 // All strings in a DateFormatSymbols object are created in one of the following
187 // three ways that all allow to safely use UnicodeString::fastCopyFrom():
188 // - readonly-aliases from resource bundles
189 // - readonly-aliases or allocated strings from constants
190 // - safely cloned strings (with owned buffers) from setXYZ() functions
191 //
192 // Note that this is true for as long as DateFormatSymbols can be constructed
193 // only from a locale bundle or set via the cloning API,
194 // *and* for as long as all the strings are in *private* fields, preventing
195 // a subclass from creating these strings in an "unsafe" way (with respect to fastCopyFrom()).
196 dstCount = srcCount;
197 dstArray = newUnicodeStringArray(srcCount);
198 if(dstArray != NULL) {
199 int32_t i;
200 for(i=0; i<srcCount; ++i) {
201 dstArray[i].fastCopyFrom(srcArray[i]);
202 }
203 }
204 }
205
206 /**
207 * Create a copy, in fZoneStrings, of the given zone strings array. The
208 * member variables fZoneStringsRowCount and fZoneStringsColCount should
209 * be set already by the caller.
210 */
211 void
212 DateFormatSymbols::createZoneStrings(const UnicodeString *const * otherStrings)
213 {
214 int32_t row, col;
215
216 fZoneStrings = (UnicodeString **)uprv_malloc(fZoneStringsRowCount * sizeof(UnicodeString *));
217 for (row=0; row<fZoneStringsRowCount; ++row)
218 {
219 fZoneStrings[row] = newUnicodeStringArray(fZoneStringsColCount);
220 for (col=0; col<fZoneStringsColCount; ++col) {
221 // fastCopyFrom() - see assignArray comments
222 fZoneStrings[row][col].fastCopyFrom(otherStrings[row][col]);
223 }
224 }
225 }
226
227 /**
228 * Copy all of the other's data to this.
229 */
230 void
231 DateFormatSymbols::copyData(const DateFormatSymbols& other) {
232 assignArray(fEras, fErasCount, other.fEras, other.fErasCount);
233 assignArray(fMonths, fMonthsCount, other.fMonths, other.fMonthsCount);
234 assignArray(fShortMonths, fShortMonthsCount, other.fShortMonths, other.fShortMonthsCount);
235 assignArray(fWeekdays, fWeekdaysCount, other.fWeekdays, other.fWeekdaysCount);
236 assignArray(fShortWeekdays, fShortWeekdaysCount, other.fShortWeekdays, other.fShortWeekdaysCount);
237 assignArray(fAmPms, fAmPmsCount, other.fAmPms, other.fAmPmsCount);
238
239 fZoneStringsRowCount = other.fZoneStringsRowCount;
240 fZoneStringsColCount = other.fZoneStringsColCount;
241 createZoneStrings((const UnicodeString**)other.fZoneStrings);
242
243 // fastCopyFrom() - see assignArray comments
244 fLocalPatternChars.fastCopyFrom(other.fLocalPatternChars);
245 }
246
247 /**
248 * Assignment operator.
249 */
250 DateFormatSymbols& DateFormatSymbols::operator=(const DateFormatSymbols& other)
251 {
252 dispose();
253 copyData(other);
254
255 return *this;
256 }
257
258 DateFormatSymbols::~DateFormatSymbols()
259 {
260 dispose();
261 }
262
263 void DateFormatSymbols::dispose()
264 {
265 if (fEras) delete[] fEras;
266 if (fMonths) delete[] fMonths;
267 if (fShortMonths) delete[] fShortMonths;
268 if (fWeekdays) delete[] fWeekdays;
269 if (fShortWeekdays) delete[] fShortWeekdays;
270 if (fAmPms) delete[] fAmPms;
271
272 disposeZoneStrings();
273 }
274
275 void DateFormatSymbols::disposeZoneStrings()
276 {
277 if (fZoneStrings) {
278 for (int32_t row=0; row<fZoneStringsRowCount; ++row)
279 delete[] fZoneStrings[row];
280 uprv_free(fZoneStrings);
281 }
282 }
283
284 UBool
285 DateFormatSymbols::arrayCompare(const UnicodeString* array1,
286 const UnicodeString* array2,
287 int32_t count)
288 {
289 if (array1 == array2) return TRUE;
290 while (count>0)
291 {
292 --count;
293 if (array1[count] != array2[count]) return FALSE;
294 }
295 return TRUE;
296 }
297
298 UBool
299 DateFormatSymbols::operator==(const DateFormatSymbols& other) const
300 {
301 // First do cheap comparisons
302 if (this == &other) {
303 return TRUE;
304 }
305 if (fErasCount == other.fErasCount &&
306 fMonthsCount == other.fMonthsCount &&
307 fShortMonthsCount == other.fShortMonthsCount &&
308 fWeekdaysCount == other.fWeekdaysCount &&
309 fShortWeekdaysCount == other.fShortWeekdaysCount &&
310 fAmPmsCount == other.fAmPmsCount &&
311 fZoneStringsRowCount == other.fZoneStringsRowCount &&
312 fZoneStringsColCount == other.fZoneStringsColCount)
313 {
314 // Now compare the arrays themselves
315 if (arrayCompare(fEras, other.fEras, fErasCount) &&
316 arrayCompare(fMonths, other.fMonths, fMonthsCount) &&
317 arrayCompare(fShortMonths, other.fShortMonths, fShortMonthsCount) &&
318 arrayCompare(fWeekdays, other.fWeekdays, fWeekdaysCount) &&
319 arrayCompare(fShortWeekdays, other.fShortWeekdays, fShortWeekdaysCount) &&
320 arrayCompare(fAmPms, other.fAmPms, fAmPmsCount))
321 {
322 if (fZoneStrings == other.fZoneStrings) return TRUE;
323
324 for (int32_t row=0; row<fZoneStringsRowCount; ++row)
325 {
326 if (!arrayCompare(fZoneStrings[row], other.fZoneStrings[row], fZoneStringsColCount))
327 return FALSE;
328 }
329 return TRUE;
330 }
331 }
332 return FALSE;
333 }
334
335 //------------------------------------------------------
336
337 const UnicodeString*
338 DateFormatSymbols::getEras(int32_t &count) const
339 {
340 count = fErasCount;
341 return fEras;
342 }
343
344 const UnicodeString*
345 DateFormatSymbols::getMonths(int32_t &count) const
346 {
347 count = fMonthsCount;
348 return fMonths;
349 }
350
351 const UnicodeString*
352 DateFormatSymbols::getShortMonths(int32_t &count) const
353 {
354 count = fShortMonthsCount;
355 return fShortMonths;
356 }
357
358 const UnicodeString*
359 DateFormatSymbols::getWeekdays(int32_t &count) const
360 {
361 count = fWeekdaysCount;
362 return fWeekdays;
363 }
364
365 const UnicodeString*
366 DateFormatSymbols::getShortWeekdays(int32_t &count) const
367 {
368 count = fShortWeekdaysCount;
369 return fShortWeekdays;
370 }
371
372 const UnicodeString*
373 DateFormatSymbols::getAmPmStrings(int32_t &count) const
374 {
375 count = fAmPmsCount;
376 return fAmPms;
377 }
378
379 //------------------------------------------------------
380
381 void
382 DateFormatSymbols::setEras(const UnicodeString* erasArray, int32_t count)
383 {
384 // delete the old list if we own it
385 if (fEras) delete[] fEras;
386
387 // we always own the new list, which we create here (we duplicate rather
388 // than adopting the list passed in)
389 fEras = newUnicodeStringArray(count);
390 uprv_arrayCopy(erasArray,fEras, count);
391 fErasCount = count;
392 }
393
394 void
395 DateFormatSymbols::setMonths(const UnicodeString* monthsArray, int32_t count)
396 {
397 // delete the old list if we own it
398 if (fMonths) delete[] fMonths;
399
400 // we always own the new list, which we create here (we duplicate rather
401 // than adopting the list passed in)
402 fMonths = newUnicodeStringArray(count);
403 uprv_arrayCopy( monthsArray,fMonths,count);
404 fMonthsCount = count;
405 }
406
407 void
408 DateFormatSymbols::setShortMonths(const UnicodeString* shortMonthsArray, int32_t count)
409 {
410 // delete the old list if we own it
411 if (fShortMonths) delete[] fShortMonths;
412
413 // we always own the new list, which we create here (we duplicate rather
414 // than adopting the list passed in)
415 fShortMonths = newUnicodeStringArray(count);
416 uprv_arrayCopy(shortMonthsArray,fShortMonths, count);
417 fShortMonthsCount = count;
418 }
419
420 void DateFormatSymbols::setWeekdays(const UnicodeString* weekdaysArray, int32_t count)
421 {
422 // delete the old list if we own it
423 if (fWeekdays) delete[] fWeekdays;
424
425 // we always own the new list, which we create here (we duplicate rather
426 // than adopting the list passed in)
427 fWeekdays = newUnicodeStringArray(count);
428 uprv_arrayCopy(weekdaysArray,fWeekdays,count);
429 fWeekdaysCount = count;
430 }
431
432 void
433 DateFormatSymbols::setShortWeekdays(const UnicodeString* shortWeekdaysArray, int32_t count)
434 {
435 // delete the old list if we own it
436 if (fShortWeekdays) delete[] fShortWeekdays;
437
438 // we always own the new list, which we create here (we duplicate rather
439 // than adopting the list passed in)
440 fShortWeekdays = newUnicodeStringArray(count);
441 uprv_arrayCopy( shortWeekdaysArray,fShortWeekdays,count);
442 fShortWeekdaysCount = count;
443 }
444
445 void
446 DateFormatSymbols::setAmPmStrings(const UnicodeString* amPmsArray, int32_t count)
447 {
448 // delete the old list if we own it
449 if (fAmPms) delete[] fAmPms;
450
451 // we always own the new list, which we create here (we duplicate rather
452 // than adopting the list passed in)
453 fAmPms = newUnicodeStringArray(count);
454 uprv_arrayCopy(amPmsArray,fAmPms,count);
455 fAmPmsCount = count;
456 }
457
458 //------------------------------------------------------
459
460 const UnicodeString**
461 DateFormatSymbols::getZoneStrings(int32_t& rowCount, int32_t& columnCount) const
462 {
463 rowCount = fZoneStringsRowCount;
464 columnCount = fZoneStringsColCount;
465 return (const UnicodeString**)fZoneStrings; // Compiler requires cast
466 }
467
468 void
469 DateFormatSymbols::setZoneStrings(const UnicodeString* const *strings, int32_t rowCount, int32_t columnCount)
470 {
471 // since deleting a 2-d array is a pain in the butt, we offload that task to
472 // a separate function
473 disposeZoneStrings();
474
475 // we always own the new list, which we create here (we duplicate rather
476 // than adopting the list passed in)
477 fZoneStringsRowCount = rowCount;
478 fZoneStringsColCount = columnCount;
479 createZoneStrings((const UnicodeString**)strings);
480 }
481
482 //------------------------------------------------------
483
484 const UChar *
485 DateFormatSymbols::getPatternUChars(void)
486 {
487 return gPatternChars;
488 }
489
490 //------------------------------------------------------
491
492 UnicodeString&
493 DateFormatSymbols::getLocalPatternChars(UnicodeString& result) const
494 {
495 // fastCopyFrom() - see assignArray comments
496 return result.fastCopyFrom(fLocalPatternChars);
497 }
498
499 //------------------------------------------------------
500
501 void
502 DateFormatSymbols::setLocalPatternChars(const UnicodeString& newLocalPatternChars)
503 {
504 fLocalPatternChars = newLocalPatternChars;
505 }
506
507 //------------------------------------------------------
508
509 void
510 DateFormatSymbols::initField(UnicodeString **field, int32_t& length, const ResourceBundle data, UErrorCode &status) {
511 if (U_SUCCESS(status)) {
512 length = data.getSize();
513 *field = newUnicodeStringArray(length);
514 if (*field) {
515 for(int32_t i = 0; i<length; i++) {
516 // fastCopyFrom() - see assignArray comments
517 (*(field)+i)->fastCopyFrom(data.getStringEx(i, status));
518 }
519 }
520 else {
521 length = 0;
522 status = U_MEMORY_ALLOCATION_ERROR;
523 }
524 }
525 }
526
527 void
528 DateFormatSymbols::initField(UnicodeString **field, int32_t& length, const UChar *data, LastResortSize numStr, LastResortSize strLen, UErrorCode &status) {
529 if (U_SUCCESS(status)) {
530 length = numStr;
531 *field = newUnicodeStringArray((size_t)numStr);
532 if (*field) {
533 for(int32_t i = 0; i<length; i++) {
534 // readonly aliases - all "data" strings are constant
535 // -1 as length for variable-length strings (gLastResortDayNames[0] is empty)
536 (*(field)+i)->setTo(TRUE, data+(i*((int32_t)strLen)), -1);
537 }
538 }
539 else {
540 length = 0;
541 status = U_MEMORY_ALLOCATION_ERROR;
542 }
543 }
544 }
545
546 ResourceBundle
547 DateFormatSymbols::getData(ResourceBundle &rb, const char *tag, const char *type, UErrorCode& status )
548 {
549 char tmp[100];
550 char *fullTag = tmp;
551
552 if(!type || !*type) {
553 type = "gregorian";
554 }
555
556 int32_t len = uprv_strlen(tag) + 1 + uprv_strlen(type); // tag + _ + type (i.e. Eras_Japanese )
557 if(len >= (int32_t)sizeof(tmp)) {
558 fullTag = (char*)uprv_malloc(len+1);
559 }
560
561 uprv_strcpy(fullTag, tag);
562 uprv_strcat(fullTag, "_");
563 uprv_strcat(fullTag, type);
564
565 ResourceBundle resource = rb.get(fullTag, status);
566
567 if(status == U_MISSING_RESOURCE_ERROR) {
568 status = U_ZERO_ERROR;
569 resource = rb.get(tag, status);
570 }
571
572 if(fullTag != tmp) {
573 uprv_free(fullTag); // not stack allocated
574 }
575
576 return resource;
577 }
578
579 void
580 DateFormatSymbols::initializeData(const Locale& locale, const char *type, UErrorCode& status, UBool useLastResortData)
581 {
582 int32_t i;
583
584 /* In case something goes wrong, initialize all of the data to NULL. */
585 fEras = NULL;
586 fErasCount = 0;
587 fMonths = NULL;
588 fMonthsCount=0;
589 fShortMonths = NULL;
590 fShortMonthsCount=0;
591 fWeekdays = NULL;
592 fWeekdaysCount=0;
593 fShortWeekdays = NULL;
594 fShortWeekdaysCount=0;
595 fAmPms = NULL;
596 fAmPmsCount=0;
597 fZoneStringsRowCount = 0;
598 fZoneStringsColCount = 0;
599 fZoneStrings = NULL;
600
601
602 if (U_FAILURE(status)) return;
603
604 /**
605 * Retrieve the string arrays we need from the resource bundle file.
606 * We cast away const here, but that's okay; we won't delete any of
607 * these.
608 */
609 ResourceBundle resource((char *)0, locale, status);
610
611 if (U_FAILURE(status))
612 {
613 if (useLastResortData)
614 {
615 // Handle the case in which there is no resource data present.
616 // We don't have to generate usable patterns in this situation;
617 // we just need to produce something that will be semi-intelligible
618 // in most locales.
619
620 status = U_USING_FALLBACK_WARNING;
621
622 initField(&fEras, fErasCount, (const UChar *)gLastResortEras, kEraNum, kEraLen, status);
623 initField(&fMonths, fMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status);
624 initField(&fShortMonths, fShortMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status);
625 initField(&fWeekdays, fWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status);
626 initField(&fShortWeekdays, fShortWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status);
627 initField(&fAmPms, fAmPmsCount, (const UChar *)gLastResortAmPmMarkers, kAmPmNum, kAmPmLen, status);
628
629 fZoneStrings = (UnicodeString **)uprv_malloc(sizeof(UnicodeString *));
630 /* test for NULL */
631 if (fZoneStrings == 0) {
632 status = U_MEMORY_ALLOCATION_ERROR;
633 return;
634 }
635 fZoneStringsRowCount = 1;
636 initField(fZoneStrings, fZoneStringsColCount, (const UChar *)gLastResortZoneStrings, kZoneNum, kZoneLen, status);
637 fLocalPatternChars = gPatternChars;
638 }
639 return;
640 }
641
642 // if we make it to here, the resource data is cool, and we can get everything out
643 // of it that we need except for the time-zone and localized-pattern data, which
644 // are stoerd in a separate file
645 initField(&fEras, fErasCount, getData(resource, fgErasTag, type, status), status);
646 initField(&fMonths, fMonthsCount, getData(resource, fgMonthNamesTag, type, status), status);
647 initField(&fShortMonths, fShortMonthsCount, getData(resource, fgMonthAbbreviationsTag, type, status), status);
648 initField(&fAmPms, fAmPmsCount, getData(resource, fgAmPmMarkersTag, type, status), status);
649 // fastCopyFrom() - see assignArray comments
650 fLocalPatternChars.fastCopyFrom(resource.getStringEx(fgLocalPatternCharsTag, status));
651
652 ResourceBundle zoneArray = resource.get(fgZoneStringsTag, status);
653 fZoneStringsRowCount = zoneArray.getSize();
654 ResourceBundle zoneRow = zoneArray.get((int32_t)0, status);
655 /* TODO: Fix the case where the zoneStrings is not a perfect square array of information. */
656 fZoneStringsColCount = zoneRow.getSize();
657 fZoneStrings = (UnicodeString **)uprv_malloc(fZoneStringsRowCount * sizeof(UnicodeString *));
658 /* test for NULL */
659 if (fZoneStrings == 0) {
660 status = U_MEMORY_ALLOCATION_ERROR;
661 return;
662 }
663 for(i = 0; i<fZoneStringsRowCount; i++) {
664 *(fZoneStrings+i) = newUnicodeStringArray(fZoneStringsColCount);
665 /* test for NULL */
666 if ((*(fZoneStrings+i)) == 0) {
667 status = U_MEMORY_ALLOCATION_ERROR;
668 return;
669 }
670 zoneRow = zoneArray.get(i, status);
671 for(int32_t j = 0; j<fZoneStringsColCount; j++) {
672 // fastCopyFrom() - see assignArray comments
673 fZoneStrings[i][j].fastCopyFrom(zoneRow.getStringEx(j, status));
674 }
675 }
676
677 // {sfb} fixed to handle 1-based weekdays
678 ResourceBundle weekdaysData = getData(resource, fgDayNamesTag, type, status);
679 fWeekdaysCount = weekdaysData.getSize();
680 fWeekdays = new UnicodeString[fWeekdaysCount+1];
681 /* test for NULL */
682 if (fWeekdays == 0) {
683 status = U_MEMORY_ALLOCATION_ERROR;
684 return;
685 }
686 // leave fWeekdays[0] empty
687 for(i = 0; i<fWeekdaysCount; i++) {
688 // fastCopyFrom() - see assignArray comments
689 fWeekdays[i+1].fastCopyFrom(weekdaysData.getStringEx(i, status));
690 }
691
692 ResourceBundle lsweekdaysData = getData(resource, fgDayAbbreviationsTag, type, status);
693 fShortWeekdaysCount = lsweekdaysData.getSize();
694 fShortWeekdays = new UnicodeString[fShortWeekdaysCount+1];
695 /* test for NULL */
696 if (fShortWeekdays == 0) {
697 status = U_MEMORY_ALLOCATION_ERROR;
698 return;
699 }
700 // leave fShortWeekdays[0] empty
701 for(i = 0; i<fShortWeekdaysCount; i++) {
702 // fastCopyFrom() - see assignArray comments
703 fShortWeekdays[i+1].fastCopyFrom(lsweekdaysData.getStringEx(i, status));
704 }
705
706 fWeekdaysCount = fShortWeekdaysCount = 8;
707
708 // If the locale data does not include new pattern chars, use the defaults
709 if (fLocalPatternChars.length() < PATTERN_CHARS_LEN) {
710 fLocalPatternChars.append(&gPatternChars[fLocalPatternChars.length()]);
711 }
712 }
713
714 /**
715 * Package private: used by SimpleDateFormat
716 * Gets the index for the given time zone ID to obtain the timezone
717 * strings for formatting. The time zone ID is just for programmatic
718 * lookup. NOT LOCALIZED!!!
719 * @param ID the given time zone ID.
720 * @return the index of the given time zone ID. Returns -1 if
721 * the given time zone ID can't be located in the DateFormatSymbols object.
722 * @see java.util.SimpleTimeZone
723 */
724 int32_t DateFormatSymbols::getZoneIndex(const UnicodeString& ID) const
725 {
726 int32_t result = _getZoneIndex(ID);
727 if (result >= 0) {
728 return result;
729 }
730
731 // Do a search through the equivalency group for the given ID
732 int32_t n = TimeZone::countEquivalentIDs(ID);
733 if (n > 1) {
734 int32_t i;
735 for (i=0; i<n; ++i) {
736 UnicodeString equivID = TimeZone::getEquivalentID(ID, i);
737 if (equivID != ID) {
738 int32_t equivResult = _getZoneIndex(equivID);
739 if (equivResult >= 0) {
740 return equivResult;
741 }
742 }
743 }
744 }
745
746 return -1;
747 }
748
749 /**
750 * Lookup the given ID. Do NOT do an equivalency search.
751 */
752 int32_t DateFormatSymbols::_getZoneIndex(const UnicodeString& ID) const
753 {
754 for(int32_t index = 0; index < fZoneStringsRowCount; index++) {
755 if (0 == ID.caseCompare(fZoneStrings[index][0], 0)) {
756 return index;
757 }
758 }
759
760 return -1;
761 }
762
763 U_NAMESPACE_END
764
765 #endif /* #if !UCONFIG_NO_FORMATTING */
766
767 //eof