]> git.saurik.com Git - apple/icu.git/blame_incremental - icuSources/i18n/dtfmtsym.cpp
ICU-57149.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / dtfmtsym.cpp
... / ...
CommitLineData
1/*
2*******************************************************************************
3* Copyright (C) 1997-2016, 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* 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*******************************************************************************
21*/
22#include "unicode/utypes.h"
23
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"
32#include "cpputils.h"
33#include "umutex.h"
34#include "cmemory.h"
35#include "cstring.h"
36#include "locbased.h"
37#include "gregoimp.h"
38#include "hash.h"
39#include "uresimp.h"
40#include "ureslocs.h"
41#include "shareddateformatsymbols.h"
42#include "unicode/calendar.h"
43#include "unifiedcache.h"
44
45// *****************************************************************************
46// class DateFormatSymbols
47// *****************************************************************************
48
49/**
50 * These are static arrays we use only in the case where we have no
51 * resource data.
52 */
53
54#if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR
55#define PATTERN_CHARS_LEN 38
56#else
57#define PATTERN_CHARS_LEN 37
58#endif
59
60/**
61 * Unlocalized date-time pattern characters. For example: 'y', 'd', etc. All
62 * locales use the same these unlocalized pattern characters.
63 */
64static const UChar gPatternChars[] = {
65 // if UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR:
66 // GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXxrbB:
67 // else:
68 // GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXxrbB
69
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
75 0x3a,
76#endif
77 0
78};
79
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.
83
84// These are the month names and abbreviations of last resort.
85static const UChar gLastResortMonthNames[13][3] =
86{
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" */
100};
101
102// These are the weekday names and abbreviations of last resort.
103static const UChar gLastResortDayNames[8][2] =
104{
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" */
113};
114
115// These are the quarter names and abbreviations of last resort.
116static const UChar gLastResortQuarters[4][2] =
117{
118 {0x0031, 0x0000}, /* "1" */
119 {0x0032, 0x0000}, /* "2" */
120 {0x0033, 0x0000}, /* "3" */
121 {0x0034, 0x0000}, /* "4" */
122};
123
124// These are the am/pm and BC/AD markers of last resort.
125static const UChar gLastResortAmPmMarkers[2][3] =
126{
127 {0x0041, 0x004D, 0x0000}, /* "AM" */
128 {0x0050, 0x004D, 0x0000} /* "PM" */
129};
130
131static const UChar gLastResortEras[2][3] =
132{
133 {0x0042, 0x0043, 0x0000}, /* "BC" */
134 {0x0041, 0x0044, 0x0000} /* "AD" */
135};
136
137/* Sizes for the last resort string arrays */
138typedef enum LastResortSize {
139 kMonthNum = 13,
140 kMonthLen = 3,
141
142 kDayNum = 8,
143 kDayLen = 2,
144
145 kAmPmNum = 2,
146 kAmPmLen = 3,
147
148 kQuarterNum = 4,
149 kQuarterLen = 2,
150
151 kEraNum = 2,
152 kEraLen = 3,
153
154 kZoneNum = 5,
155 kZoneLen = 4,
156
157 kGmtHourNum = 4,
158 kGmtHourLen = 10
159} LastResortSize;
160
161U_NAMESPACE_BEGIN
162
163SharedDateFormatSymbols::~SharedDateFormatSymbols() {
164}
165
166template<> U_I18N_API
167const SharedDateFormatSymbols *
168 LocaleCacheKey<SharedDateFormatSymbols>::createObject(
169 const void * /*unusedContext*/, UErrorCode &status) const {
170 char type[256];
171 Calendar::getCalendarTypeFromLocale(fLoc, type, UPRV_LENGTHOF(type), status);
172 if (U_FAILURE(status)) {
173 return NULL;
174 }
175 SharedDateFormatSymbols *shared
176 = new SharedDateFormatSymbols(fLoc, type, status);
177 if (shared == NULL) {
178 status = U_MEMORY_ALLOCATION_ERROR;
179 return NULL;
180 }
181 if (U_FAILURE(status)) {
182 delete shared;
183 return NULL;
184 }
185 shared->addRef();
186 return shared;
187}
188
189UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateFormatSymbols)
190
191#define kSUPPLEMENTAL "supplementalData"
192
193/**
194 * These are the tags we expect to see in normal resource bundle files associated
195 * with a locale and calendar
196 */
197static const char gErasTag[]="eras";
198static const char gCyclicNameSetsTag[]="cyclicNameSets";
199static const char gNameSetYearsTag[]="years";
200static const char gNameSetZodiacsTag[]="zodiacs";
201static const char gMonthNamesTag[]="monthNames";
202static const char gMonthPatternsTag[]="monthPatterns";
203static const char gDayNamesTag[]="dayNames";
204static const char gNamesWideTag[]="wide";
205static const char gNamesAbbrTag[]="abbreviated";
206static const char gNamesShortTag[]="short";
207static const char gNamesNarrowTag[]="narrow";
208static const char gNamesAllTag[]="all";
209static const char gNamesLeapTag[]="leap";
210static const char gNamesFormatTag[]="format";
211static const char gNamesStandaloneTag[]="stand-alone";
212static const char gNamesNumericTag[]="numeric";
213static const char gAmPmMarkersTag[]="AmPmMarkers";
214static const char gAmPmMarkersNarrowTag[]="AmPmMarkersNarrow";
215static const char gQuartersTag[]="quarters";
216static const char gNumberElementsTag[]="NumberElements";
217static const char gSymbolsTag[]="symbols";
218static const char gTimeSeparatorTag[]="timeSeparator";
219static const char gDayPeriodTag[]="dayPeriod";
220
221// static const char gZoneStringsTag[]="zoneStrings";
222
223// static const char gLocalPatternCharsTag[]="localPatternChars";
224
225static const char gContextTransformsTag[]="contextTransforms";
226
227static UMutex LOCK = U_MUTEX_INITIALIZER;
228
229/**
230 * Jitterbug 2974: MSVC has a bug whereby new X[0] behaves badly.
231 * Work around this.
232 */
233static inline UnicodeString* newUnicodeStringArray(size_t count) {
234 return new UnicodeString[count ? count : 1];
235}
236
237//------------------------------------------------------
238
239DateFormatSymbols * U_EXPORT2
240DateFormatSymbols::createForLocale(
241 const Locale& locale, UErrorCode &status) {
242 const SharedDateFormatSymbols *shared = NULL;
243 UnifiedCache::getByLocale(locale, shared, status);
244 if (U_FAILURE(status)) {
245 return NULL;
246 }
247 DateFormatSymbols *result = new DateFormatSymbols(shared->get());
248 shared->removeRef();
249 if (result == NULL) {
250 status = U_MEMORY_ALLOCATION_ERROR;
251 return NULL;
252 }
253 return result;
254}
255
256DateFormatSymbols::DateFormatSymbols(const Locale& locale,
257 UErrorCode& status)
258 : UObject()
259{
260 initializeData(locale, NULL, status);
261}
262
263DateFormatSymbols::DateFormatSymbols(UErrorCode& status)
264 : UObject()
265{
266 initializeData(Locale::getDefault(), NULL, status, TRUE);
267}
268
269
270DateFormatSymbols::DateFormatSymbols(const Locale& locale,
271 const char *type,
272 UErrorCode& status)
273 : UObject()
274{
275 initializeData(locale, type, status);
276}
277
278DateFormatSymbols::DateFormatSymbols(const char *type, UErrorCode& status)
279 : UObject()
280{
281 initializeData(Locale::getDefault(), type, status, TRUE);
282}
283
284DateFormatSymbols::DateFormatSymbols(const DateFormatSymbols& other)
285 : UObject(other)
286{
287 copyData(other);
288}
289
290void
291DateFormatSymbols::assignArray(UnicodeString*& dstArray,
292 int32_t& dstCount,
293 const UnicodeString* srcArray,
294 int32_t srcCount)
295{
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
303 //
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()).
308 dstCount = srcCount;
309 dstArray = newUnicodeStringArray(srcCount);
310 if(dstArray != NULL) {
311 int32_t i;
312 for(i=0; i<srcCount; ++i) {
313 dstArray[i].fastCopyFrom(srcArray[i]);
314 }
315 }
316}
317
318/**
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.
322 */
323void
324DateFormatSymbols::createZoneStrings(const UnicodeString *const * otherStrings)
325{
326 int32_t row, col;
327 UBool failed = FALSE;
328
329 fZoneStrings = (UnicodeString **)uprv_malloc(fZoneStringsRowCount * sizeof(UnicodeString *));
330 if (fZoneStrings != NULL) {
331 for (row=0; row<fZoneStringsRowCount; ++row)
332 {
333 fZoneStrings[row] = newUnicodeStringArray(fZoneStringsColCount);
334 if (fZoneStrings[row] == NULL) {
335 failed = TRUE;
336 break;
337 }
338 for (col=0; col<fZoneStringsColCount; ++col) {
339 // fastCopyFrom() - see assignArray comments
340 fZoneStrings[row][col].fastCopyFrom(otherStrings[row][col]);
341 }
342 }
343 }
344 // If memory allocation failed, roll back and delete fZoneStrings
345 if (failed) {
346 for (int i = row; i >= 0; i--) {
347 delete[] fZoneStrings[i];
348 }
349 uprv_free(fZoneStrings);
350 fZoneStrings = NULL;
351 }
352}
353
354/**
355 * Copy all of the other's data to this.
356 */
357void
358DateFormatSymbols::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);
402 } else {
403 fLeapMonthPatterns = NULL;
404 fLeapMonthPatternsCount = 0;
405 }
406 if (other.fShortYearNames != NULL) {
407 assignArray(fShortYearNames, fShortYearNamesCount, other.fShortYearNames, other.fShortYearNamesCount);
408 } else {
409 fShortYearNames = NULL;
410 fShortYearNamesCount = 0;
411 }
412 if (other.fShortZodiacNames != NULL) {
413 assignArray(fShortZodiacNames, fShortZodiacNamesCount, other.fShortZodiacNames, other.fShortZodiacNamesCount);
414 } else {
415 fShortZodiacNames = NULL;
416 fShortZodiacNamesCount = 0;
417 }
418
419 if (other.fZoneStrings != NULL) {
420 fZoneStringsColCount = other.fZoneStringsColCount;
421 fZoneStringsRowCount = other.fZoneStringsRowCount;
422 createZoneStrings((const UnicodeString**)other.fZoneStrings);
423
424 } else {
425 fZoneStrings = NULL;
426 fZoneStringsColCount = 0;
427 fZoneStringsRowCount = 0;
428 }
429 fZSFLocale = other.fZSFLocale;
430 // Other zone strings data is created on demand
431 fLocaleZoneStrings = NULL;
432
433 // fastCopyFrom() - see assignArray comments
434 fLocalPatternChars.fastCopyFrom(other.fLocalPatternChars);
435
436 uprv_memcpy(fCapitalization, other.fCapitalization, sizeof(fCapitalization));
437}
438
439/**
440 * Assignment operator.
441 */
442DateFormatSymbols& DateFormatSymbols::operator=(const DateFormatSymbols& other)
443{
444 dispose();
445 copyData(other);
446
447 return *this;
448}
449
450DateFormatSymbols::~DateFormatSymbols()
451{
452 dispose();
453}
454
455void DateFormatSymbols::dispose()
456{
457 delete[] fEras;
458 delete[] fEraNames;
459 delete[] fNarrowEras;
460 delete[] fMonths;
461 delete[] fShortMonths;
462 delete[] fNarrowMonths;
463 delete[] fStandaloneMonths;
464 delete[] fStandaloneShortMonths;
465 delete[] fStandaloneNarrowMonths;
466 delete[] fWeekdays;
467 delete[] fShortWeekdays;
468 delete[] fShorterWeekdays;
469 delete[] fNarrowWeekdays;
470 delete[] fStandaloneWeekdays;
471 delete[] fStandaloneShortWeekdays;
472 delete[] fStandaloneShorterWeekdays;
473 delete[] fStandaloneNarrowWeekdays;
474 delete[] fAmPms;
475 delete[] fNarrowAmPms;
476 delete[] fQuarters;
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;
489
490 disposeZoneStrings();
491}
492
493void DateFormatSymbols::disposeZoneStrings()
494{
495 if (fZoneStrings) {
496 for (int32_t row = 0; row < fZoneStringsRowCount; ++row) {
497 delete[] fZoneStrings[row];
498 }
499 uprv_free(fZoneStrings);
500 }
501 if (fLocaleZoneStrings) {
502 for (int32_t row = 0; row < fZoneStringsRowCount; ++row) {
503 delete[] fLocaleZoneStrings[row];
504 }
505 uprv_free(fLocaleZoneStrings);
506 }
507
508 fZoneStrings = NULL;
509 fLocaleZoneStrings = NULL;
510 fZoneStringsRowCount = 0;
511 fZoneStringsColCount = 0;
512}
513
514UBool
515DateFormatSymbols::arrayCompare(const UnicodeString* array1,
516 const UnicodeString* array2,
517 int32_t count)
518{
519 if (array1 == array2) return TRUE;
520 while (count>0)
521 {
522 --count;
523 if (array1[count] != array2[count]) return FALSE;
524 }
525 return TRUE;
526}
527
528UBool
529DateFormatSymbols::operator==(const DateFormatSymbols& other) const
530{
531 // First do cheap comparisons
532 if (this == &other) {
533 return TRUE;
534 }
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))
568 {
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))
606 {
607 // Compare the contents of fZoneStrings
608 if (fZoneStrings == NULL && other.fZoneStrings == NULL) {
609 if (fZSFLocale == other.fZSFLocale) {
610 return TRUE;
611 }
612 } else if (fZoneStrings != NULL && other.fZoneStrings != NULL) {
613 if (fZoneStringsRowCount == other.fZoneStringsRowCount
614 && fZoneStringsColCount == other.fZoneStringsColCount) {
615 UBool cmpres = TRUE;
616 for (int32_t i = 0; (i < fZoneStringsRowCount) && cmpres; i++) {
617 cmpres = arrayCompare(fZoneStrings[i], other.fZoneStrings[i], fZoneStringsColCount);
618 }
619 return cmpres;
620 }
621 }
622 return FALSE;
623 }
624 }
625 return FALSE;
626}
627
628//------------------------------------------------------
629
630const UnicodeString*
631DateFormatSymbols::getEras(int32_t &count) const
632{
633 count = fErasCount;
634 return fEras;
635}
636
637const UnicodeString*
638DateFormatSymbols::getEraNames(int32_t &count) const
639{
640 count = fEraNamesCount;
641 return fEraNames;
642}
643
644const UnicodeString*
645DateFormatSymbols::getNarrowEras(int32_t &count) const
646{
647 count = fNarrowErasCount;
648 return fNarrowEras;
649}
650
651const UnicodeString*
652DateFormatSymbols::getMonths(int32_t &count) const
653{
654 count = fMonthsCount;
655 return fMonths;
656}
657
658const UnicodeString*
659DateFormatSymbols::getShortMonths(int32_t &count) const
660{
661 count = fShortMonthsCount;
662 return fShortMonths;
663}
664
665const UnicodeString*
666DateFormatSymbols::getMonths(int32_t &count, DtContextType context, DtWidthType width ) const
667{
668 UnicodeString *returnValue = NULL;
669
670 switch (context) {
671 case FORMAT :
672 switch(width) {
673 case WIDE :
674 count = fMonthsCount;
675 returnValue = fMonths;
676 break;
677 case ABBREVIATED :
678 case SHORT : // no month data for this, defaults to ABBREVIATED
679 count = fShortMonthsCount;
680 returnValue = fShortMonths;
681 break;
682 case NARROW :
683 count = fNarrowMonthsCount;
684 returnValue = fNarrowMonths;
685 break;
686 case DT_WIDTH_COUNT :
687 break;
688 }
689 break;
690 case STANDALONE :
691 switch(width) {
692 case WIDE :
693 count = fStandaloneMonthsCount;
694 returnValue = fStandaloneMonths;
695 break;
696 case ABBREVIATED :
697 case SHORT : // no month data for this, defaults to ABBREVIATED
698 count = fStandaloneShortMonthsCount;
699 returnValue = fStandaloneShortMonths;
700 break;
701 case NARROW :
702 count = fStandaloneNarrowMonthsCount;
703 returnValue = fStandaloneNarrowMonths;
704 break;
705 case DT_WIDTH_COUNT :
706 break;
707 }
708 break;
709 case DT_CONTEXT_COUNT :
710 break;
711 }
712 return returnValue;
713}
714
715const UnicodeString*
716DateFormatSymbols::getWeekdays(int32_t &count) const
717{
718 count = fWeekdaysCount;
719 return fWeekdays;
720}
721
722const UnicodeString*
723DateFormatSymbols::getShortWeekdays(int32_t &count) const
724{
725 count = fShortWeekdaysCount;
726 return fShortWeekdays;
727}
728
729const UnicodeString*
730DateFormatSymbols::getWeekdays(int32_t &count, DtContextType context, DtWidthType width) const
731{
732 UnicodeString *returnValue = NULL;
733 switch (context) {
734 case FORMAT :
735 switch(width) {
736 case WIDE :
737 count = fWeekdaysCount;
738 returnValue = fWeekdays;
739 break;
740 case ABBREVIATED :
741 count = fShortWeekdaysCount;
742 returnValue = fShortWeekdays;
743 break;
744 case SHORT :
745 count = fShorterWeekdaysCount;
746 returnValue = fShorterWeekdays;
747 break;
748 case NARROW :
749 count = fNarrowWeekdaysCount;
750 returnValue = fNarrowWeekdays;
751 break;
752 case DT_WIDTH_COUNT :
753 break;
754 }
755 break;
756 case STANDALONE :
757 switch(width) {
758 case WIDE :
759 count = fStandaloneWeekdaysCount;
760 returnValue = fStandaloneWeekdays;
761 break;
762 case ABBREVIATED :
763 count = fStandaloneShortWeekdaysCount;
764 returnValue = fStandaloneShortWeekdays;
765 break;
766 case SHORT :
767 count = fStandaloneShorterWeekdaysCount;
768 returnValue = fStandaloneShorterWeekdays;
769 break;
770 case NARROW :
771 count = fStandaloneNarrowWeekdaysCount;
772 returnValue = fStandaloneNarrowWeekdays;
773 break;
774 case DT_WIDTH_COUNT :
775 break;
776 }
777 break;
778 case DT_CONTEXT_COUNT :
779 break;
780 }
781 return returnValue;
782}
783
784const UnicodeString*
785DateFormatSymbols::getQuarters(int32_t &count, DtContextType context, DtWidthType width ) const
786{
787 UnicodeString *returnValue = NULL;
788
789 switch (context) {
790 case FORMAT :
791 switch(width) {
792 case WIDE :
793 count = fQuartersCount;
794 returnValue = fQuarters;
795 break;
796 case ABBREVIATED :
797 case SHORT : // no quarter data for this, defaults to ABBREVIATED
798 count = fShortQuartersCount;
799 returnValue = fShortQuarters;
800 break;
801 case NARROW :
802 count = 0;
803 returnValue = NULL;
804 break;
805 case DT_WIDTH_COUNT :
806 break;
807 }
808 break;
809 case STANDALONE :
810 switch(width) {
811 case WIDE :
812 count = fStandaloneQuartersCount;
813 returnValue = fStandaloneQuarters;
814 break;
815 case ABBREVIATED :
816 case SHORT : // no quarter data for this, defaults to ABBREVIATED
817 count = fStandaloneShortQuartersCount;
818 returnValue = fStandaloneShortQuarters;
819 break;
820 case NARROW :
821 count = 0;
822 returnValue = NULL;
823 break;
824 case DT_WIDTH_COUNT :
825 break;
826 }
827 break;
828 case DT_CONTEXT_COUNT :
829 break;
830 }
831 return returnValue;
832}
833
834UnicodeString&
835DateFormatSymbols::getTimeSeparatorString(UnicodeString& result) const
836{
837 // fastCopyFrom() - see assignArray comments
838 return result.fastCopyFrom(fTimeSeparator);
839}
840
841const UnicodeString*
842DateFormatSymbols::getAmPmStrings(int32_t &count) const
843{
844 count = fAmPmsCount;
845 return fAmPms;
846}
847
848const UnicodeString*
849DateFormatSymbols::getLeapMonthPatterns(int32_t &count) const
850{
851 count = fLeapMonthPatternsCount;
852 return fLeapMonthPatterns;
853}
854
855const UnicodeString*
856DateFormatSymbols::getYearNames(int32_t& count,
857 DtContextType /*ignored*/, DtWidthType /*ignored*/) const
858{
859 count = fShortYearNamesCount;
860 return fShortYearNames;
861}
862
863void
864DateFormatSymbols::setYearNames(const UnicodeString* yearNames, int32_t count,
865 DtContextType context, DtWidthType width)
866{
867 if (context == FORMAT && width == ABBREVIATED) {
868 if (fShortYearNames) {
869 delete[] fShortYearNames;
870 }
871 fShortYearNames = newUnicodeStringArray(count);
872 uprv_arrayCopy(yearNames, fShortYearNames, count);
873 fShortYearNamesCount = count;
874 }
875}
876
877const UnicodeString*
878DateFormatSymbols::getZodiacNames(int32_t& count,
879 DtContextType /*ignored*/, DtWidthType /*ignored*/) const
880{
881 count = fShortZodiacNamesCount;
882 return fShortZodiacNames;
883}
884
885void
886DateFormatSymbols::setZodiacNames(const UnicodeString* zodiacNames, int32_t count,
887 DtContextType context, DtWidthType width)
888{
889 if (context == FORMAT && width == ABBREVIATED) {
890 if (fShortZodiacNames) {
891 delete[] fShortZodiacNames;
892 }
893 fShortZodiacNames = newUnicodeStringArray(count);
894 uprv_arrayCopy(zodiacNames, fShortZodiacNames, count);
895 fShortZodiacNamesCount = count;
896 }
897}
898
899//------------------------------------------------------
900
901void
902DateFormatSymbols::setEras(const UnicodeString* erasArray, int32_t count)
903{
904 // delete the old list if we own it
905 if (fEras)
906 delete[] fEras;
907
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);
912 fErasCount = count;
913}
914
915void
916DateFormatSymbols::setEraNames(const UnicodeString* eraNamesArray, int32_t count)
917{
918 // delete the old list if we own it
919 if (fEraNames)
920 delete[] fEraNames;
921
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;
927}
928
929void
930DateFormatSymbols::setNarrowEras(const UnicodeString* narrowErasArray, int32_t count)
931{
932 // delete the old list if we own it
933 if (fNarrowEras)
934 delete[] fNarrowEras;
935
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;
941}
942
943void
944DateFormatSymbols::setMonths(const UnicodeString* monthsArray, int32_t count)
945{
946 // delete the old list if we own it
947 if (fMonths)
948 delete[] fMonths;
949
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;
955}
956
957void
958DateFormatSymbols::setShortMonths(const UnicodeString* shortMonthsArray, int32_t count)
959{
960 // delete the old list if we own it
961 if (fShortMonths)
962 delete[] fShortMonths;
963
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;
969}
970
971void
972DateFormatSymbols::setMonths(const UnicodeString* monthsArray, int32_t count, DtContextType context, DtWidthType width)
973{
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)
977
978 switch (context) {
979 case FORMAT :
980 switch (width) {
981 case WIDE :
982 if (fMonths)
983 delete[] fMonths;
984 fMonths = newUnicodeStringArray(count);
985 uprv_arrayCopy( monthsArray,fMonths,count);
986 fMonthsCount = count;
987 break;
988 case ABBREVIATED :
989 if (fShortMonths)
990 delete[] fShortMonths;
991 fShortMonths = newUnicodeStringArray(count);
992 uprv_arrayCopy( monthsArray,fShortMonths,count);
993 fShortMonthsCount = count;
994 break;
995 case NARROW :
996 if (fNarrowMonths)
997 delete[] fNarrowMonths;
998 fNarrowMonths = newUnicodeStringArray(count);
999 uprv_arrayCopy( monthsArray,fNarrowMonths,count);
1000 fNarrowMonthsCount = count;
1001 break;
1002 default :
1003 break;
1004 }
1005 break;
1006 case STANDALONE :
1007 switch (width) {
1008 case WIDE :
1009 if (fStandaloneMonths)
1010 delete[] fStandaloneMonths;
1011 fStandaloneMonths = newUnicodeStringArray(count);
1012 uprv_arrayCopy( monthsArray,fStandaloneMonths,count);
1013 fStandaloneMonthsCount = count;
1014 break;
1015 case ABBREVIATED :
1016 if (fStandaloneShortMonths)
1017 delete[] fStandaloneShortMonths;
1018 fStandaloneShortMonths = newUnicodeStringArray(count);
1019 uprv_arrayCopy( monthsArray,fStandaloneShortMonths,count);
1020 fStandaloneShortMonthsCount = count;
1021 break;
1022 case NARROW :
1023 if (fStandaloneNarrowMonths)
1024 delete[] fStandaloneNarrowMonths;
1025 fStandaloneNarrowMonths = newUnicodeStringArray(count);
1026 uprv_arrayCopy( monthsArray,fStandaloneNarrowMonths,count);
1027 fStandaloneNarrowMonthsCount = count;
1028 break;
1029 default :
1030 break;
1031 }
1032 break;
1033 case DT_CONTEXT_COUNT :
1034 break;
1035 }
1036}
1037
1038void DateFormatSymbols::setWeekdays(const UnicodeString* weekdaysArray, int32_t count)
1039{
1040 // delete the old list if we own it
1041 if (fWeekdays)
1042 delete[] fWeekdays;
1043
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;
1049}
1050
1051void
1052DateFormatSymbols::setShortWeekdays(const UnicodeString* shortWeekdaysArray, int32_t count)
1053{
1054 // delete the old list if we own it
1055 if (fShortWeekdays)
1056 delete[] fShortWeekdays;
1057
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;
1063}
1064
1065void
1066DateFormatSymbols::setWeekdays(const UnicodeString* weekdaysArray, int32_t count, DtContextType context, DtWidthType width)
1067{
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)
1071
1072 switch (context) {
1073 case FORMAT :
1074 switch (width) {
1075 case WIDE :
1076 if (fWeekdays)
1077 delete[] fWeekdays;
1078 fWeekdays = newUnicodeStringArray(count);
1079 uprv_arrayCopy(weekdaysArray, fWeekdays, count);
1080 fWeekdaysCount = count;
1081 break;
1082 case ABBREVIATED :
1083 if (fShortWeekdays)
1084 delete[] fShortWeekdays;
1085 fShortWeekdays = newUnicodeStringArray(count);
1086 uprv_arrayCopy(weekdaysArray, fShortWeekdays, count);
1087 fShortWeekdaysCount = count;
1088 break;
1089 case SHORT :
1090 if (fShorterWeekdays)
1091 delete[] fShorterWeekdays;
1092 fShorterWeekdays = newUnicodeStringArray(count);
1093 uprv_arrayCopy(weekdaysArray, fShorterWeekdays, count);
1094 fShorterWeekdaysCount = count;
1095 break;
1096 case NARROW :
1097 if (fNarrowWeekdays)
1098 delete[] fNarrowWeekdays;
1099 fNarrowWeekdays = newUnicodeStringArray(count);
1100 uprv_arrayCopy(weekdaysArray, fNarrowWeekdays, count);
1101 fNarrowWeekdaysCount = count;
1102 break;
1103 case DT_WIDTH_COUNT :
1104 break;
1105 }
1106 break;
1107 case STANDALONE :
1108 switch (width) {
1109 case WIDE :
1110 if (fStandaloneWeekdays)
1111 delete[] fStandaloneWeekdays;
1112 fStandaloneWeekdays = newUnicodeStringArray(count);
1113 uprv_arrayCopy(weekdaysArray, fStandaloneWeekdays, count);
1114 fStandaloneWeekdaysCount = count;
1115 break;
1116 case ABBREVIATED :
1117 if (fStandaloneShortWeekdays)
1118 delete[] fStandaloneShortWeekdays;
1119 fStandaloneShortWeekdays = newUnicodeStringArray(count);
1120 uprv_arrayCopy(weekdaysArray, fStandaloneShortWeekdays, count);
1121 fStandaloneShortWeekdaysCount = count;
1122 break;
1123 case SHORT :
1124 if (fStandaloneShorterWeekdays)
1125 delete[] fStandaloneShorterWeekdays;
1126 fStandaloneShorterWeekdays = newUnicodeStringArray(count);
1127 uprv_arrayCopy(weekdaysArray, fStandaloneShorterWeekdays, count);
1128 fStandaloneShorterWeekdaysCount = count;
1129 break;
1130 case NARROW :
1131 if (fStandaloneNarrowWeekdays)
1132 delete[] fStandaloneNarrowWeekdays;
1133 fStandaloneNarrowWeekdays = newUnicodeStringArray(count);
1134 uprv_arrayCopy(weekdaysArray, fStandaloneNarrowWeekdays, count);
1135 fStandaloneNarrowWeekdaysCount = count;
1136 break;
1137 case DT_WIDTH_COUNT :
1138 break;
1139 }
1140 break;
1141 case DT_CONTEXT_COUNT :
1142 break;
1143 }
1144}
1145
1146void
1147DateFormatSymbols::setQuarters(const UnicodeString* quartersArray, int32_t count, DtContextType context, DtWidthType width)
1148{
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)
1152
1153 switch (context) {
1154 case FORMAT :
1155 switch (width) {
1156 case WIDE :
1157 if (fQuarters)
1158 delete[] fQuarters;
1159 fQuarters = newUnicodeStringArray(count);
1160 uprv_arrayCopy( quartersArray,fQuarters,count);
1161 fQuartersCount = count;
1162 break;
1163 case ABBREVIATED :
1164 if (fShortQuarters)
1165 delete[] fShortQuarters;
1166 fShortQuarters = newUnicodeStringArray(count);
1167 uprv_arrayCopy( quartersArray,fShortQuarters,count);
1168 fShortQuartersCount = count;
1169 break;
1170 case NARROW :
1171 /*
1172 if (fNarrowQuarters)
1173 delete[] fNarrowQuarters;
1174 fNarrowQuarters = newUnicodeStringArray(count);
1175 uprv_arrayCopy( quartersArray,fNarrowQuarters,count);
1176 fNarrowQuartersCount = count;
1177 */
1178 break;
1179 default :
1180 break;
1181 }
1182 break;
1183 case STANDALONE :
1184 switch (width) {
1185 case WIDE :
1186 if (fStandaloneQuarters)
1187 delete[] fStandaloneQuarters;
1188 fStandaloneQuarters = newUnicodeStringArray(count);
1189 uprv_arrayCopy( quartersArray,fStandaloneQuarters,count);
1190 fStandaloneQuartersCount = count;
1191 break;
1192 case ABBREVIATED :
1193 if (fStandaloneShortQuarters)
1194 delete[] fStandaloneShortQuarters;
1195 fStandaloneShortQuarters = newUnicodeStringArray(count);
1196 uprv_arrayCopy( quartersArray,fStandaloneShortQuarters,count);
1197 fStandaloneShortQuartersCount = count;
1198 break;
1199 case NARROW :
1200 /*
1201 if (fStandaloneNarrowQuarters)
1202 delete[] fStandaloneNarrowQuarters;
1203 fStandaloneNarrowQuarters = newUnicodeStringArray(count);
1204 uprv_arrayCopy( quartersArray,fStandaloneNarrowQuarters,count);
1205 fStandaloneNarrowQuartersCount = count;
1206 */
1207 break;
1208 default :
1209 break;
1210 }
1211 break;
1212 case DT_CONTEXT_COUNT :
1213 break;
1214 }
1215}
1216
1217void
1218DateFormatSymbols::setAmPmStrings(const UnicodeString* amPmsArray, int32_t count)
1219{
1220 // delete the old list if we own it
1221 if (fAmPms) delete[] fAmPms;
1222
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;
1228}
1229
1230void
1231DateFormatSymbols::setTimeSeparatorString(const UnicodeString& newTimeSeparator)
1232{
1233 fTimeSeparator = newTimeSeparator;
1234}
1235
1236const UnicodeString**
1237DateFormatSymbols::getZoneStrings(int32_t& rowCount, int32_t& columnCount) const
1238{
1239 const UnicodeString **result = NULL;
1240
1241 umtx_lock(&LOCK);
1242 if (fZoneStrings == NULL) {
1243 if (fLocaleZoneStrings == NULL) {
1244 ((DateFormatSymbols*)this)->initZoneStringsArray();
1245 }
1246 result = (const UnicodeString**)fLocaleZoneStrings;
1247 } else {
1248 result = (const UnicodeString**)fZoneStrings;
1249 }
1250 rowCount = fZoneStringsRowCount;
1251 columnCount = fZoneStringsColCount;
1252 umtx_unlock(&LOCK);
1253
1254 return result;
1255}
1256
1257// For now, we include all zones
1258#define ZONE_SET UCAL_ZONE_TYPE_ANY
1259
1260// This code must be called within a synchronized block
1261void
1262DateFormatSymbols::initZoneStringsArray(void) {
1263 if (fZoneStrings != NULL || fLocaleZoneStrings != NULL) {
1264 return;
1265 }
1266
1267 UErrorCode status = U_ZERO_ERROR;
1268
1269 StringEnumeration *tzids = NULL;
1270 UnicodeString ** zarray = NULL;
1271 TimeZoneNames *tzNames = NULL;
1272 int32_t rows = 0;
1273
1274 do { // dummy do-while
1275
1276 tzids = TimeZone::createTimeZoneIDEnumeration(ZONE_SET, NULL, NULL, status);
1277 rows = tzids->count(status);
1278 if (U_FAILURE(status)) {
1279 break;
1280 }
1281
1282 // Allocate array
1283 int32_t size = rows * sizeof(UnicodeString*);
1284 zarray = (UnicodeString**)uprv_malloc(size);
1285 if (zarray == NULL) {
1286 status = U_MEMORY_ALLOCATION_ERROR;
1287 break;
1288 }
1289 uprv_memset(zarray, 0, size);
1290
1291 tzNames = TimeZoneNames::createInstance(fZSFLocale, status);
1292
1293 const UnicodeString *tzid;
1294 int32_t i = 0;
1295 UDate now = Calendar::getNow();
1296 UnicodeString tzDispName;
1297
1298 while ((tzid = tzids->snext(status))) {
1299 if (U_FAILURE(status)) {
1300 break;
1301 }
1302
1303 zarray[i] = new UnicodeString[5];
1304 if (zarray[i] == NULL) {
1305 status = U_MEMORY_ALLOCATION_ERROR;
1306 break;
1307 }
1308
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));
1314 i++;
1315 }
1316
1317 } while (FALSE);
1318
1319 if (U_FAILURE(status)) {
1320 if (zarray) {
1321 for (int32_t i = 0; i < rows; i++) {
1322 if (zarray[i]) {
1323 delete[] zarray[i];
1324 }
1325 }
1326 uprv_free(zarray);
1327 }
1328 }
1329
1330 if (tzNames) {
1331 delete tzNames;
1332 }
1333 if (tzids) {
1334 delete tzids;
1335 }
1336
1337 fLocaleZoneStrings = zarray;
1338 fZoneStringsRowCount = rows;
1339 fZoneStringsColCount = 5;
1340}
1341
1342void
1343DateFormatSymbols::setZoneStrings(const UnicodeString* const *strings, int32_t rowCount, int32_t columnCount)
1344{
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);
1353}
1354
1355//------------------------------------------------------
1356
1357const UChar * U_EXPORT2
1358DateFormatSymbols::getPatternUChars(void)
1359{
1360 return gPatternChars;
1361}
1362
1363UDateFormatField U_EXPORT2
1364DateFormatSymbols::getPatternCharIndex(UChar c) {
1365 const UChar *p = u_strchr(gPatternChars, c);
1366 if (p == NULL) {
1367 return UDAT_FIELD_COUNT;
1368 } else {
1369 return static_cast<UDateFormatField>(p - gPatternChars);
1370 }
1371}
1372
1373static 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
1392
1393static 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
1400
1401UBool U_EXPORT2
1402DateFormatSymbols::isNumericField(UDateFormatField f, int32_t count) {
1403 if (f == UDAT_FIELD_COUNT) {
1404 return FALSE;
1405 }
1406 uint64_t flag = ((uint64_t)1 << f);
1407 return ((kNumericFieldsAlways & flag) != 0 || ((kNumericFieldsForCount12 & flag) != 0 && count < 3));
1408}
1409
1410UBool U_EXPORT2
1411DateFormatSymbols::isNumericPatternChar(UChar c, int32_t count) {
1412 return isNumericField(getPatternCharIndex(c), count);
1413}
1414
1415//------------------------------------------------------
1416
1417UnicodeString&
1418DateFormatSymbols::getLocalPatternChars(UnicodeString& result) const
1419{
1420 // fastCopyFrom() - see assignArray comments
1421 return result.fastCopyFrom(fLocalPatternChars);
1422}
1423
1424//------------------------------------------------------
1425
1426void
1427DateFormatSymbols::setLocalPatternChars(const UnicodeString& newLocalPatternChars)
1428{
1429 fLocalPatternChars = newLocalPatternChars;
1430}
1431
1432//------------------------------------------------------
1433
1434static void
1435initField(UnicodeString **field, int32_t& length, const UResourceBundle *data, UErrorCode &status) {
1436 if (U_SUCCESS(status)) {
1437 int32_t strLen = 0;
1438 length = ures_getSize(data);
1439 *field = newUnicodeStringArray(length);
1440 if (*field) {
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);
1445 }
1446 }
1447 else {
1448 length = 0;
1449 status = U_MEMORY_ALLOCATION_ERROR;
1450 }
1451 }
1452}
1453
1454static void
1455initField(UnicodeString **field, int32_t& length, const UChar *data, LastResortSize numStr, LastResortSize strLen, UErrorCode &status) {
1456 if (U_SUCCESS(status)) {
1457 length = numStr;
1458 *field = newUnicodeStringArray((size_t)numStr);
1459 if (*field) {
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);
1464 }
1465 }
1466 else {
1467 length = 0;
1468 status = U_MEMORY_ALLOCATION_ERROR;
1469 }
1470 }
1471}
1472
1473static void
1474initLeapMonthPattern(UnicodeString *field, int32_t index, const UResourceBundle *data, UErrorCode &status) {
1475 field[index].remove();
1476 if (U_SUCCESS(status)) {
1477 int32_t strLen = 0;
1478 const UChar *resStr = ures_getStringByKey(data, gNamesLeapTag, &strLen, &status);
1479 if (U_SUCCESS(status)) {
1480 field[index].setTo(TRUE, resStr, strLen);
1481 }
1482 }
1483 status = U_ZERO_ERROR;
1484}
1485
1486typedef struct {
1487 const char * usageTypeName;
1488 DateFormatSymbols::ECapitalizationContextUsageType usageTypeEnumValue;
1489} ContextUsageTypeNameToEnumValue;
1490
1491static 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 },
1507};
1508
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.
1512static const char *dayPeriodKeys[] = {"midnight", "noon",
1513 "morning1", "afternoon1", "evening1", "night1",
1514 "morning2", "afternoon2", "evening2", "night2"};
1515
1516UnicodeString* loadDayPeriodStrings(CalendarData &calData, const char *tag, UBool standalone,
1517 int32_t &stringCount, UErrorCode &status) {
1518 if (U_FAILURE(status)) {
1519 return NULL;
1520 }
1521
1522 UResourceBundle *dayPeriodData;
1523
1524 if (standalone) {
1525 dayPeriodData = calData.getByKey3(gDayPeriodTag, gNamesStandaloneTag, tag, status);
1526 } else {
1527 dayPeriodData = calData.getByKey2(gDayPeriodTag, tag, status);
1528 }
1529
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;
1540 }
1541 }
1542 return strings;
1543}
1544
1545void
1546DateFormatSymbols::initializeData(const Locale& locale, const char *type, UErrorCode& status, UBool useLastResortData)
1547{
1548 int32_t i;
1549 int32_t len = 0;
1550 const UChar *resStr;
1551 /* In case something goes wrong, initialize all of the data to NULL. */
1552 fEras = NULL;
1553 fErasCount = 0;
1554 fEraNames = NULL;
1555 fEraNamesCount = 0;
1556 fNarrowEras = NULL;
1557 fNarrowErasCount = 0;
1558 fMonths = NULL;
1559 fMonthsCount=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;
1570 fWeekdays = NULL;
1571 fWeekdaysCount=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;
1586 fAmPms = NULL;
1587 fAmPmsCount=0;
1588 fNarrowAmPms = NULL;
1589 fNarrowAmPmsCount=0;
1590 fTimeSeparator.setToBogus();
1591 fQuarters = NULL;
1592 fQuartersCount = 0;
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));
1622
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;
1628
1629 if (U_FAILURE(status)) return;
1630
1631 /**
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
1634 * these.
1635 */
1636 CalendarData calData(locale, type, status);
1637
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
1644 status = oldStatus;
1645 eraNames = ures_getByKeyWithFallback(erasMain, gNamesAbbrTag, NULL, &status);
1646 }
1647 // current ICU4J falls back to abbreviated if narrow eras are missing, so we will too
1648 oldStatus = status;
1649 UResourceBundle *narrowEras = ures_getByKeyWithFallback(erasMain, gNamesNarrowTag, NULL, &status);
1650 if ( status == U_MISSING_RESOURCE_ERROR ) {
1651 status = oldStatus;
1652 narrowEras = ures_getByKeyWithFallback(erasMain, gNamesAbbrTag, NULL, &status);
1653 }
1654
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]);
1672 };
1673 if (fLeapMonthPatterns[kLeapMonthPatternFormatNarrow].isEmpty()) {
1674 fLeapMonthPatterns[kLeapMonthPatternFormatNarrow].setTo(fLeapMonthPatterns[kLeapMonthPatternStandaloneNarrow]);
1675 };
1676 if (fLeapMonthPatterns[kLeapMonthPatternStandaloneWide].isEmpty()) {
1677 fLeapMonthPatterns[kLeapMonthPatternStandaloneWide].setTo(fLeapMonthPatterns[kLeapMonthPatternFormatWide]);
1678 };
1679 if (fLeapMonthPatterns[kLeapMonthPatternStandaloneAbbrev].isEmpty()) {
1680 fLeapMonthPatterns[kLeapMonthPatternStandaloneAbbrev].setTo(fLeapMonthPatterns[kLeapMonthPatternFormatAbbrev]);
1681 };
1682 // end of hack
1683 fLeapMonthPatternsCount = kMonthPatternsCount;
1684 } else {
1685 delete[] fLeapMonthPatterns;
1686 fLeapMonthPatterns = NULL;
1687 }
1688 }
1689 }
1690
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);
1702 }
1703 ures_close(nameSetYearsFmt);
1704 }
1705 ures_close(nameSetYears);
1706 }
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);
1715 }
1716 ures_close(nameSetZodiacsFmt);
1717 }
1718 ures_close(nameSetZodiacs);
1719 }
1720 }
1721
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 ) {
1737 ++typeMapPtr;
1738 }
1739 if (typeMapPtr->usageTypeName != NULL && compResult == 0) {
1740 fCapitalization[typeMapPtr->usageTypeEnumValue][0] = intVector[0];
1741 fCapitalization[typeMapPtr->usageTypeEnumValue][1] = intVector[1];
1742 }
1743 }
1744 }
1745 tempStatus = U_ZERO_ERROR;
1746 ures_close(contextTransformUsage);
1747 }
1748 ures_close(contextTransforms);
1749 }
1750
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();
1768 }
1769 }
1770
1771 ures_close(localeBundle);
1772 }
1773
1774 if (fTimeSeparator.isBogus()) {
1775 fTimeSeparator.setTo(DateFormatSymbols::DEFAULT_TIME_SEPARATOR);
1776 }
1777
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);
1790
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
1799
1800 U_LOCALE_BASED(locBased, *this);
1801 if (U_FAILURE(status))
1802 {
1803 if (useLastResortData)
1804 {
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
1808 // in most locales.
1809
1810 status = U_USING_FALLBACK_WARNING;
1811
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);
1836 }
1837 goto cleanup;
1838 }
1839
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));
1845
1846 initField(&fEras, fErasCount, eras, status);
1847 initField(&fEraNames, fEraNamesCount, eraNames, status);
1848 initField(&fNarrowEras, fNarrowErasCount, narrowEras, status);
1849
1850 initField(&fMonths, fMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesWideTag, status), status);
1851 initField(&fShortMonths, fShortMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesAbbrTag, status), status);
1852
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);
1857 }
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);
1861 }
1862
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);
1867 }
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);
1872 }
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);
1880 }
1881 }
1882 initField(&fAmPms, fAmPmsCount, calData.getByKey(gAmPmMarkersTag, status), status);
1883 initField(&fNarrowAmPms, fNarrowAmPmsCount, calData.getByKey(gAmPmMarkersNarrowTag, status), status);
1884
1885 initField(&fQuarters, fQuartersCount, calData.getByKey2(gQuartersTag, gNamesWideTag, status), status);
1886 initField(&fShortQuarters, fShortQuartersCount, calData.getByKey2(gQuartersTag, gNamesAbbrTag, status), status);
1887
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);
1892 }
1893
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);
1898 }
1899
1900 // ICU 3.8 or later version no longer uses localized date-time pattern characters by default (ticket#5597)
1901 /*
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));
1909 }
1910 */
1911 fLocalPatternChars.setTo(TRUE, gPatternChars, PATTERN_CHARS_LEN);
1912
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;
1921 goto cleanup;
1922 }
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);
1928 }
1929 fWeekdaysCount++;
1930
1931 // Format abbreviated weekdays -> fShortWeekdays
1932 abbrWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status);
1933 fShortWeekdaysCount = ures_getSize(abbrWeekdaysData);
1934 fShortWeekdays = new UnicodeString[fShortWeekdaysCount+1];
1935 /* test for NULL */
1936 if (fShortWeekdays == 0) {
1937 status = U_MEMORY_ALLOCATION_ERROR;
1938 goto cleanup;
1939 }
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);
1945 }
1946 fShortWeekdaysCount++;
1947
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);
1953 }
1954 fShorterWeekdaysCount = ures_getSize(shorterWeekdaysData);
1955 fShorterWeekdays = new UnicodeString[fShorterWeekdaysCount+1];
1956 /* test for NULL */
1957 if (fShorterWeekdays == 0) {
1958 status = U_MEMORY_ALLOCATION_ERROR;
1959 goto cleanup;
1960 }
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);
1966 }
1967 fShorterWeekdaysCount++;
1968
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);
1974 }
1975 if ( status == U_MISSING_RESOURCE_ERROR ) {
1976 status = U_ZERO_ERROR;
1977 narrowWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status);
1978 }
1979 fNarrowWeekdaysCount = ures_getSize(narrowWeekdaysData);
1980 fNarrowWeekdays = new UnicodeString[fNarrowWeekdaysCount+1];
1981 /* test for NULL */
1982 if (fNarrowWeekdays == 0) {
1983 status = U_MEMORY_ALLOCATION_ERROR;
1984 goto cleanup;
1985 }
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);
1991 }
1992 fNarrowWeekdaysCount++;
1993
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);
1999 }
2000 fStandaloneWeekdaysCount = ures_getSize(standaloneWeekdaysData);
2001 fStandaloneWeekdays = new UnicodeString[fStandaloneWeekdaysCount+1];
2002 /* test for NULL */
2003 if (fStandaloneWeekdays == 0) {
2004 status = U_MEMORY_ALLOCATION_ERROR;
2005 goto cleanup;
2006 }
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);
2012 }
2013 fStandaloneWeekdaysCount++;
2014
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);
2020 }
2021 fStandaloneShortWeekdaysCount = ures_getSize(standaloneAbbrWeekdaysData);
2022 fStandaloneShortWeekdays = new UnicodeString[fStandaloneShortWeekdaysCount+1];
2023 /* test for NULL */
2024 if (fStandaloneShortWeekdays == 0) {
2025 status = U_MEMORY_ALLOCATION_ERROR;
2026 goto cleanup;
2027 }
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);
2033 }
2034 fStandaloneShortWeekdaysCount++;
2035
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);
2041 }
2042 fStandaloneShorterWeekdaysCount = ures_getSize(standaloneShorterWeekdaysData);
2043 fStandaloneShorterWeekdays = new UnicodeString[fStandaloneShorterWeekdaysCount+1];
2044 /* test for NULL */
2045 if (fStandaloneShorterWeekdays == 0) {
2046 status = U_MEMORY_ALLOCATION_ERROR;
2047 goto cleanup;
2048 }
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);
2054 }
2055 fStandaloneShorterWeekdaysCount++;
2056
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);
2065 }
2066 }
2067 fStandaloneNarrowWeekdaysCount = ures_getSize(standaloneNarrowWeekdaysData);
2068 fStandaloneNarrowWeekdays = new UnicodeString[fStandaloneNarrowWeekdaysCount+1];
2069 /* test for NULL */
2070 if (fStandaloneNarrowWeekdays == 0) {
2071 status = U_MEMORY_ALLOCATION_ERROR;
2072 goto cleanup;
2073 }
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);
2079 }
2080 fStandaloneNarrowWeekdaysCount++;
2081
2082cleanup:
2083 ures_close(eras);
2084 ures_close(eraNames);
2085 ures_close(narrowEras);
2086}
2087
2088Locale
2089DateFormatSymbols::getLocale(ULocDataLocaleType type, UErrorCode& status) const {
2090 U_LOCALE_BASED(locBased, *this);
2091 return locBased.getLocale(type, status);
2092}
2093
2094U_NAMESPACE_END
2095
2096#endif /* #if !UCONFIG_NO_FORMATTING */
2097
2098//eof