]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | ******************************************************************************* | |
3 | * Copyright (C) 1997-2012, 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/dtfmtsym.h" | |
27 | #include "unicode/smpdtfmt.h" | |
28 | #include "unicode/msgfmt.h" | |
29 | #include "unicode/tznames.h" | |
30 | #include "cpputils.h" | |
31 | #include "ucln_in.h" | |
32 | #include "umutex.h" | |
33 | #include "cmemory.h" | |
34 | #include "cstring.h" | |
35 | #include "locbased.h" | |
36 | #include "gregoimp.h" | |
37 | #include "hash.h" | |
38 | #include "uresimp.h" | |
39 | #include "ureslocs.h" | |
40 | ||
41 | // ***************************************************************************** | |
42 | // class DateFormatSymbols | |
43 | // ***************************************************************************** | |
44 | ||
45 | /** | |
46 | * These are static arrays we use only in the case where we have no | |
47 | * resource data. | |
48 | */ | |
49 | ||
50 | #define PATTERN_CHARS_LEN 31 | |
51 | ||
52 | /** | |
53 | * Unlocalized date-time pattern characters. For example: 'y', 'd', etc. All | |
54 | * locales use the same these unlocalized pattern characters. | |
55 | */ | |
56 | static const UChar gPatternChars[] = { | |
57 | // GyMdkHmsSEDFwWahKzYeugAZvcLQqVU | |
58 | 0x47, 0x79, 0x4D, 0x64, 0x6B, 0x48, 0x6D, 0x73, 0x53, 0x45, | |
59 | 0x44, 0x46, 0x77, 0x57, 0x61, 0x68, 0x4B, 0x7A, 0x59, 0x65, | |
60 | 0x75, 0x67, 0x41, 0x5A, 0x76, 0x63, 0x4c, 0x51, 0x71, 0x56, 0x55, 0 | |
61 | }; | |
62 | ||
63 | /* length of an array */ | |
64 | #define ARRAY_LENGTH(array) (sizeof(array)/sizeof(array[0])) | |
65 | ||
66 | //------------------------------------------------------ | |
67 | // Strings of last resort. These are only used if we have no resource | |
68 | // files. They aren't designed for actual use, just for backup. | |
69 | ||
70 | // These are the month names and abbreviations of last resort. | |
71 | static const UChar gLastResortMonthNames[13][3] = | |
72 | { | |
73 | {0x0030, 0x0031, 0x0000}, /* "01" */ | |
74 | {0x0030, 0x0032, 0x0000}, /* "02" */ | |
75 | {0x0030, 0x0033, 0x0000}, /* "03" */ | |
76 | {0x0030, 0x0034, 0x0000}, /* "04" */ | |
77 | {0x0030, 0x0035, 0x0000}, /* "05" */ | |
78 | {0x0030, 0x0036, 0x0000}, /* "06" */ | |
79 | {0x0030, 0x0037, 0x0000}, /* "07" */ | |
80 | {0x0030, 0x0038, 0x0000}, /* "08" */ | |
81 | {0x0030, 0x0039, 0x0000}, /* "09" */ | |
82 | {0x0031, 0x0030, 0x0000}, /* "10" */ | |
83 | {0x0031, 0x0031, 0x0000}, /* "11" */ | |
84 | {0x0031, 0x0032, 0x0000}, /* "12" */ | |
85 | {0x0031, 0x0033, 0x0000} /* "13" */ | |
86 | }; | |
87 | ||
88 | // These are the weekday names and abbreviations of last resort. | |
89 | static const UChar gLastResortDayNames[8][2] = | |
90 | { | |
91 | {0x0030, 0x0000}, /* "0" */ | |
92 | {0x0031, 0x0000}, /* "1" */ | |
93 | {0x0032, 0x0000}, /* "2" */ | |
94 | {0x0033, 0x0000}, /* "3" */ | |
95 | {0x0034, 0x0000}, /* "4" */ | |
96 | {0x0035, 0x0000}, /* "5" */ | |
97 | {0x0036, 0x0000}, /* "6" */ | |
98 | {0x0037, 0x0000} /* "7" */ | |
99 | }; | |
100 | ||
101 | // These are the quarter names and abbreviations of last resort. | |
102 | static const UChar gLastResortQuarters[4][2] = | |
103 | { | |
104 | {0x0031, 0x0000}, /* "1" */ | |
105 | {0x0032, 0x0000}, /* "2" */ | |
106 | {0x0033, 0x0000}, /* "3" */ | |
107 | {0x0034, 0x0000}, /* "4" */ | |
108 | }; | |
109 | ||
110 | // These are the am/pm and BC/AD markers of last resort. | |
111 | static const UChar gLastResortAmPmMarkers[2][3] = | |
112 | { | |
113 | {0x0041, 0x004D, 0x0000}, /* "AM" */ | |
114 | {0x0050, 0x004D, 0x0000} /* "PM" */ | |
115 | }; | |
116 | ||
117 | static const UChar gLastResortEras[2][3] = | |
118 | { | |
119 | {0x0042, 0x0043, 0x0000}, /* "BC" */ | |
120 | {0x0041, 0x0044, 0x0000} /* "AD" */ | |
121 | }; | |
122 | ||
123 | /* Sizes for the last resort string arrays */ | |
124 | typedef enum LastResortSize { | |
125 | kMonthNum = 13, | |
126 | kMonthLen = 3, | |
127 | ||
128 | kDayNum = 8, | |
129 | kDayLen = 2, | |
130 | ||
131 | kAmPmNum = 2, | |
132 | kAmPmLen = 3, | |
133 | ||
134 | kQuarterNum = 4, | |
135 | kQuarterLen = 2, | |
136 | ||
137 | kEraNum = 2, | |
138 | kEraLen = 3, | |
139 | ||
140 | kZoneNum = 5, | |
141 | kZoneLen = 4, | |
142 | ||
143 | kGmtHourNum = 4, | |
144 | kGmtHourLen = 10 | |
145 | } LastResortSize; | |
146 | ||
147 | U_NAMESPACE_BEGIN | |
148 | ||
149 | UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateFormatSymbols) | |
150 | ||
151 | #define kSUPPLEMENTAL "supplementalData" | |
152 | ||
153 | /** | |
154 | * These are the tags we expect to see in normal resource bundle files associated | |
155 | * with a locale and calendar | |
156 | */ | |
157 | static const char gErasTag[]="eras"; | |
158 | static const char gCyclicNameSetsTag[]="cyclicNameSets"; | |
159 | static const char gNameSetYearsTag[]="years"; | |
160 | static const char gMonthNamesTag[]="monthNames"; | |
161 | static const char gMonthPatternsTag[]="monthPatterns"; | |
162 | static const char gDayNamesTag[]="dayNames"; | |
163 | static const char gNamesWideTag[]="wide"; | |
164 | static const char gNamesAbbrTag[]="abbreviated"; | |
165 | static const char gNamesNarrowTag[]="narrow"; | |
166 | static const char gNamesAllTag[]="all"; | |
167 | static const char gNamesLeapTag[]="leap"; | |
168 | static const char gNamesFormatTag[]="format"; | |
169 | static const char gNamesStandaloneTag[]="stand-alone"; | |
170 | static const char gNamesNumericTag[]="numeric"; | |
171 | static const char gAmPmMarkersTag[]="AmPmMarkers"; | |
172 | static const char gQuartersTag[]="quarters"; | |
173 | ||
174 | static const char gZoneStringsTag[]="zoneStrings"; | |
175 | ||
176 | static const char gLocalPatternCharsTag[]="localPatternChars"; | |
177 | ||
178 | static const char gContextTransformsTag[]="contextTransforms"; | |
179 | ||
180 | static UMTX LOCK; | |
181 | ||
182 | /** | |
183 | * Jitterbug 2974: MSVC has a bug whereby new X[0] behaves badly. | |
184 | * Work around this. | |
185 | */ | |
186 | static inline UnicodeString* newUnicodeStringArray(size_t count) { | |
187 | return new UnicodeString[count ? count : 1]; | |
188 | } | |
189 | ||
190 | //------------------------------------------------------ | |
191 | ||
192 | DateFormatSymbols::DateFormatSymbols(const Locale& locale, | |
193 | UErrorCode& status) | |
194 | : UObject() | |
195 | { | |
196 | initializeData(locale, NULL, status); | |
197 | } | |
198 | ||
199 | DateFormatSymbols::DateFormatSymbols(UErrorCode& status) | |
200 | : UObject() | |
201 | { | |
202 | initializeData(Locale::getDefault(), NULL, status, TRUE); | |
203 | } | |
204 | ||
205 | ||
206 | DateFormatSymbols::DateFormatSymbols(const Locale& locale, | |
207 | const char *type, | |
208 | UErrorCode& status) | |
209 | : UObject() | |
210 | { | |
211 | initializeData(locale, type, status); | |
212 | } | |
213 | ||
214 | DateFormatSymbols::DateFormatSymbols(const char *type, UErrorCode& status) | |
215 | : UObject() | |
216 | { | |
217 | initializeData(Locale::getDefault(), type, status, TRUE); | |
218 | } | |
219 | ||
220 | DateFormatSymbols::DateFormatSymbols(const DateFormatSymbols& other) | |
221 | : UObject(other) | |
222 | { | |
223 | copyData(other); | |
224 | } | |
225 | ||
226 | void | |
227 | DateFormatSymbols::assignArray(UnicodeString*& dstArray, | |
228 | int32_t& dstCount, | |
229 | const UnicodeString* srcArray, | |
230 | int32_t srcCount) | |
231 | { | |
232 | // assignArray() is only called by copyData(), which in turn implements the | |
233 | // copy constructor and the assignment operator. | |
234 | // All strings in a DateFormatSymbols object are created in one of the following | |
235 | // three ways that all allow to safely use UnicodeString::fastCopyFrom(): | |
236 | // - readonly-aliases from resource bundles | |
237 | // - readonly-aliases or allocated strings from constants | |
238 | // - safely cloned strings (with owned buffers) from setXYZ() functions | |
239 | // | |
240 | // Note that this is true for as long as DateFormatSymbols can be constructed | |
241 | // only from a locale bundle or set via the cloning API, | |
242 | // *and* for as long as all the strings are in *private* fields, preventing | |
243 | // a subclass from creating these strings in an "unsafe" way (with respect to fastCopyFrom()). | |
244 | dstCount = srcCount; | |
245 | dstArray = newUnicodeStringArray(srcCount); | |
246 | if(dstArray != NULL) { | |
247 | int32_t i; | |
248 | for(i=0; i<srcCount; ++i) { | |
249 | dstArray[i].fastCopyFrom(srcArray[i]); | |
250 | } | |
251 | } | |
252 | } | |
253 | ||
254 | /** | |
255 | * Create a copy, in fZoneStrings, of the given zone strings array. The | |
256 | * member variables fZoneStringsRowCount and fZoneStringsColCount should | |
257 | * be set already by the caller. | |
258 | */ | |
259 | void | |
260 | DateFormatSymbols::createZoneStrings(const UnicodeString *const * otherStrings) | |
261 | { | |
262 | int32_t row, col; | |
263 | UBool failed = FALSE; | |
264 | ||
265 | fZoneStrings = (UnicodeString **)uprv_malloc(fZoneStringsRowCount * sizeof(UnicodeString *)); | |
266 | if (fZoneStrings != NULL) { | |
267 | for (row=0; row<fZoneStringsRowCount; ++row) | |
268 | { | |
269 | fZoneStrings[row] = newUnicodeStringArray(fZoneStringsColCount); | |
270 | if (fZoneStrings[row] == NULL) { | |
271 | failed = TRUE; | |
272 | break; | |
273 | } | |
274 | for (col=0; col<fZoneStringsColCount; ++col) { | |
275 | // fastCopyFrom() - see assignArray comments | |
276 | fZoneStrings[row][col].fastCopyFrom(otherStrings[row][col]); | |
277 | } | |
278 | } | |
279 | } | |
280 | // If memory allocation failed, roll back and delete fZoneStrings | |
281 | if (failed) { | |
282 | for (int i = row; i >= 0; i--) { | |
283 | delete[] fZoneStrings[i]; | |
284 | } | |
285 | uprv_free(fZoneStrings); | |
286 | fZoneStrings = NULL; | |
287 | } | |
288 | } | |
289 | ||
290 | /** | |
291 | * Copy all of the other's data to this. | |
292 | */ | |
293 | void | |
294 | DateFormatSymbols::copyData(const DateFormatSymbols& other) { | |
295 | assignArray(fEras, fErasCount, other.fEras, other.fErasCount); | |
296 | assignArray(fEraNames, fEraNamesCount, other.fEraNames, other.fEraNamesCount); | |
297 | assignArray(fNarrowEras, fNarrowErasCount, other.fNarrowEras, other.fNarrowErasCount); | |
298 | assignArray(fMonths, fMonthsCount, other.fMonths, other.fMonthsCount); | |
299 | assignArray(fShortMonths, fShortMonthsCount, other.fShortMonths, other.fShortMonthsCount); | |
300 | assignArray(fNarrowMonths, fNarrowMonthsCount, other.fNarrowMonths, other.fNarrowMonthsCount); | |
301 | assignArray(fStandaloneMonths, fStandaloneMonthsCount, other.fStandaloneMonths, other.fStandaloneMonthsCount); | |
302 | assignArray(fStandaloneShortMonths, fStandaloneShortMonthsCount, other.fStandaloneShortMonths, other.fStandaloneShortMonthsCount); | |
303 | assignArray(fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, other.fStandaloneNarrowMonths, other.fStandaloneNarrowMonthsCount); | |
304 | assignArray(fWeekdays, fWeekdaysCount, other.fWeekdays, other.fWeekdaysCount); | |
305 | assignArray(fShortWeekdays, fShortWeekdaysCount, other.fShortWeekdays, other.fShortWeekdaysCount); | |
306 | assignArray(fNarrowWeekdays, fNarrowWeekdaysCount, other.fNarrowWeekdays, other.fNarrowWeekdaysCount); | |
307 | assignArray(fStandaloneWeekdays, fStandaloneWeekdaysCount, other.fStandaloneWeekdays, other.fStandaloneWeekdaysCount); | |
308 | assignArray(fStandaloneShortWeekdays, fStandaloneShortWeekdaysCount, other.fStandaloneShortWeekdays, other.fStandaloneShortWeekdaysCount); | |
309 | assignArray(fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount, other.fStandaloneNarrowWeekdays, other.fStandaloneNarrowWeekdaysCount); | |
310 | assignArray(fAmPms, fAmPmsCount, other.fAmPms, other.fAmPmsCount); | |
311 | assignArray(fQuarters, fQuartersCount, other.fQuarters, other.fQuartersCount); | |
312 | assignArray(fShortQuarters, fShortQuartersCount, other.fShortQuarters, other.fShortQuartersCount); | |
313 | assignArray(fStandaloneQuarters, fStandaloneQuartersCount, other.fStandaloneQuarters, other.fStandaloneQuartersCount); | |
314 | assignArray(fStandaloneShortQuarters, fStandaloneShortQuartersCount, other.fStandaloneShortQuarters, other.fStandaloneShortQuartersCount); | |
315 | if (other.fLeapMonthPatterns != NULL) { | |
316 | assignArray(fLeapMonthPatterns, fLeapMonthPatternsCount, other.fLeapMonthPatterns, other.fLeapMonthPatternsCount); | |
317 | } else { | |
318 | fLeapMonthPatterns = NULL; | |
319 | fLeapMonthPatternsCount = 0; | |
320 | } | |
321 | if (other.fShortYearNames != NULL) { | |
322 | assignArray(fShortYearNames, fShortYearNamesCount, other.fShortYearNames, other.fShortYearNamesCount); | |
323 | } else { | |
324 | fShortYearNames = NULL; | |
325 | fShortYearNamesCount = 0; | |
326 | } | |
327 | ||
328 | if (other.fZoneStrings != NULL) { | |
329 | fZoneStringsColCount = other.fZoneStringsColCount; | |
330 | fZoneStringsRowCount = other.fZoneStringsRowCount; | |
331 | createZoneStrings((const UnicodeString**)other.fZoneStrings); | |
332 | ||
333 | } else { | |
334 | fZoneStrings = NULL; | |
335 | fZoneStringsColCount = 0; | |
336 | fZoneStringsRowCount = 0; | |
337 | } | |
338 | fZSFLocale = other.fZSFLocale; | |
339 | // Other zone strings data is created on demand | |
340 | fLocaleZoneStrings = NULL; | |
341 | ||
342 | // fastCopyFrom() - see assignArray comments | |
343 | fLocalPatternChars.fastCopyFrom(other.fLocalPatternChars); | |
344 | ||
345 | uprv_memcpy(fCapitalization, other.fCapitalization, sizeof(fCapitalization)); | |
346 | } | |
347 | ||
348 | /** | |
349 | * Assignment operator. | |
350 | */ | |
351 | DateFormatSymbols& DateFormatSymbols::operator=(const DateFormatSymbols& other) | |
352 | { | |
353 | dispose(); | |
354 | copyData(other); | |
355 | ||
356 | return *this; | |
357 | } | |
358 | ||
359 | DateFormatSymbols::~DateFormatSymbols() | |
360 | { | |
361 | dispose(); | |
362 | } | |
363 | ||
364 | void DateFormatSymbols::dispose() | |
365 | { | |
366 | if (fEras) delete[] fEras; | |
367 | if (fEraNames) delete[] fEraNames; | |
368 | if (fNarrowEras) delete[] fNarrowEras; | |
369 | if (fMonths) delete[] fMonths; | |
370 | if (fShortMonths) delete[] fShortMonths; | |
371 | if (fNarrowMonths) delete[] fNarrowMonths; | |
372 | if (fStandaloneMonths) delete[] fStandaloneMonths; | |
373 | if (fStandaloneShortMonths) delete[] fStandaloneShortMonths; | |
374 | if (fStandaloneNarrowMonths) delete[] fStandaloneNarrowMonths; | |
375 | if (fWeekdays) delete[] fWeekdays; | |
376 | if (fShortWeekdays) delete[] fShortWeekdays; | |
377 | if (fNarrowWeekdays) delete[] fNarrowWeekdays; | |
378 | if (fStandaloneWeekdays) delete[] fStandaloneWeekdays; | |
379 | if (fStandaloneShortWeekdays) delete[] fStandaloneShortWeekdays; | |
380 | if (fStandaloneNarrowWeekdays) delete[] fStandaloneNarrowWeekdays; | |
381 | if (fAmPms) delete[] fAmPms; | |
382 | if (fQuarters) delete[] fQuarters; | |
383 | if (fShortQuarters) delete[] fShortQuarters; | |
384 | if (fStandaloneQuarters) delete[] fStandaloneQuarters; | |
385 | if (fStandaloneShortQuarters) delete[] fStandaloneShortQuarters; | |
386 | if (fLeapMonthPatterns) delete[] fLeapMonthPatterns; | |
387 | if (fShortYearNames) delete[] fShortYearNames; | |
388 | ||
389 | disposeZoneStrings(); | |
390 | } | |
391 | ||
392 | void DateFormatSymbols::disposeZoneStrings() | |
393 | { | |
394 | if (fZoneStrings) { | |
395 | for (int32_t row = 0; row < fZoneStringsRowCount; ++row) { | |
396 | delete[] fZoneStrings[row]; | |
397 | } | |
398 | uprv_free(fZoneStrings); | |
399 | } | |
400 | if (fLocaleZoneStrings) { | |
401 | for (int32_t row = 0; row < fZoneStringsRowCount; ++row) { | |
402 | delete[] fLocaleZoneStrings[row]; | |
403 | } | |
404 | uprv_free(fLocaleZoneStrings); | |
405 | } | |
406 | ||
407 | fZoneStrings = NULL; | |
408 | fLocaleZoneStrings = NULL; | |
409 | fZoneStringsRowCount = 0; | |
410 | fZoneStringsColCount = 0; | |
411 | } | |
412 | ||
413 | UBool | |
414 | DateFormatSymbols::arrayCompare(const UnicodeString* array1, | |
415 | const UnicodeString* array2, | |
416 | int32_t count) | |
417 | { | |
418 | if (array1 == array2) return TRUE; | |
419 | while (count>0) | |
420 | { | |
421 | --count; | |
422 | if (array1[count] != array2[count]) return FALSE; | |
423 | } | |
424 | return TRUE; | |
425 | } | |
426 | ||
427 | UBool | |
428 | DateFormatSymbols::operator==(const DateFormatSymbols& other) const | |
429 | { | |
430 | // First do cheap comparisons | |
431 | if (this == &other) { | |
432 | return TRUE; | |
433 | } | |
434 | if (fErasCount == other.fErasCount && | |
435 | fEraNamesCount == other.fEraNamesCount && | |
436 | fNarrowErasCount == other.fNarrowErasCount && | |
437 | fMonthsCount == other.fMonthsCount && | |
438 | fShortMonthsCount == other.fShortMonthsCount && | |
439 | fNarrowMonthsCount == other.fNarrowMonthsCount && | |
440 | fStandaloneMonthsCount == other.fStandaloneMonthsCount && | |
441 | fStandaloneShortMonthsCount == other.fStandaloneShortMonthsCount && | |
442 | fStandaloneNarrowMonthsCount == other.fStandaloneNarrowMonthsCount && | |
443 | fWeekdaysCount == other.fWeekdaysCount && | |
444 | fShortWeekdaysCount == other.fShortWeekdaysCount && | |
445 | fNarrowWeekdaysCount == other.fNarrowWeekdaysCount && | |
446 | fStandaloneWeekdaysCount == other.fStandaloneWeekdaysCount && | |
447 | fStandaloneShortWeekdaysCount == other.fStandaloneShortWeekdaysCount && | |
448 | fStandaloneNarrowWeekdaysCount == other.fStandaloneNarrowWeekdaysCount && | |
449 | fAmPmsCount == other.fAmPmsCount && | |
450 | fQuartersCount == other.fQuartersCount && | |
451 | fShortQuartersCount == other.fShortQuartersCount && | |
452 | fStandaloneQuartersCount == other.fStandaloneQuartersCount && | |
453 | fStandaloneShortQuartersCount == other.fStandaloneShortQuartersCount && | |
454 | fLeapMonthPatternsCount == other.fLeapMonthPatternsCount && | |
455 | fShortYearNamesCount == other.fShortYearNamesCount && | |
456 | (uprv_memcmp(fCapitalization, other.fCapitalization, sizeof(fCapitalization))==0)) | |
457 | { | |
458 | // Now compare the arrays themselves | |
459 | if (arrayCompare(fEras, other.fEras, fErasCount) && | |
460 | arrayCompare(fEraNames, other.fEraNames, fEraNamesCount) && | |
461 | arrayCompare(fNarrowEras, other.fNarrowEras, fNarrowErasCount) && | |
462 | arrayCompare(fMonths, other.fMonths, fMonthsCount) && | |
463 | arrayCompare(fShortMonths, other.fShortMonths, fShortMonthsCount) && | |
464 | arrayCompare(fNarrowMonths, other.fNarrowMonths, fNarrowMonthsCount) && | |
465 | arrayCompare(fStandaloneMonths, other.fStandaloneMonths, fStandaloneMonthsCount) && | |
466 | arrayCompare(fStandaloneShortMonths, other.fStandaloneShortMonths, fStandaloneShortMonthsCount) && | |
467 | arrayCompare(fStandaloneNarrowMonths, other.fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount) && | |
468 | arrayCompare(fWeekdays, other.fWeekdays, fWeekdaysCount) && | |
469 | arrayCompare(fShortWeekdays, other.fShortWeekdays, fShortWeekdaysCount) && | |
470 | arrayCompare(fNarrowWeekdays, other.fNarrowWeekdays, fNarrowWeekdaysCount) && | |
471 | arrayCompare(fStandaloneWeekdays, other.fStandaloneWeekdays, fStandaloneWeekdaysCount) && | |
472 | arrayCompare(fStandaloneShortWeekdays, other.fStandaloneShortWeekdays, fStandaloneShortWeekdaysCount) && | |
473 | arrayCompare(fStandaloneNarrowWeekdays, other.fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount) && | |
474 | arrayCompare(fAmPms, other.fAmPms, fAmPmsCount) && | |
475 | arrayCompare(fQuarters, other.fQuarters, fQuartersCount) && | |
476 | arrayCompare(fShortQuarters, other.fShortQuarters, fShortQuartersCount) && | |
477 | arrayCompare(fStandaloneQuarters, other.fStandaloneQuarters, fStandaloneQuartersCount) && | |
478 | arrayCompare(fStandaloneShortQuarters, other.fStandaloneShortQuarters, fStandaloneShortQuartersCount) && | |
479 | arrayCompare(fLeapMonthPatterns, other.fLeapMonthPatterns, fLeapMonthPatternsCount) && | |
480 | arrayCompare(fShortYearNames, other.fShortYearNames, fShortYearNamesCount)) | |
481 | { | |
482 | // Compare the contents of fZoneStrings | |
483 | if (fZoneStrings == NULL && other.fZoneStrings == NULL) { | |
484 | if (fZSFLocale == other.fZSFLocale) { | |
485 | return TRUE; | |
486 | } | |
487 | } else if (fZoneStrings != NULL && other.fZoneStrings != NULL) { | |
488 | if (fZoneStringsRowCount == other.fZoneStringsRowCount | |
489 | && fZoneStringsColCount == other.fZoneStringsColCount) { | |
490 | UBool cmpres = TRUE; | |
491 | for (int32_t i = 0; (i < fZoneStringsRowCount) && cmpres; i++) { | |
492 | cmpres = arrayCompare(fZoneStrings[i], other.fZoneStrings[i], fZoneStringsColCount); | |
493 | } | |
494 | return cmpres; | |
495 | } | |
496 | } | |
497 | return FALSE; | |
498 | } | |
499 | } | |
500 | return FALSE; | |
501 | } | |
502 | ||
503 | //------------------------------------------------------ | |
504 | ||
505 | const UnicodeString* | |
506 | DateFormatSymbols::getEras(int32_t &count) const | |
507 | { | |
508 | count = fErasCount; | |
509 | return fEras; | |
510 | } | |
511 | ||
512 | const UnicodeString* | |
513 | DateFormatSymbols::getEraNames(int32_t &count) const | |
514 | { | |
515 | count = fEraNamesCount; | |
516 | return fEraNames; | |
517 | } | |
518 | ||
519 | const UnicodeString* | |
520 | DateFormatSymbols::getNarrowEras(int32_t &count) const | |
521 | { | |
522 | count = fNarrowErasCount; | |
523 | return fNarrowEras; | |
524 | } | |
525 | ||
526 | const UnicodeString* | |
527 | DateFormatSymbols::getMonths(int32_t &count) const | |
528 | { | |
529 | count = fMonthsCount; | |
530 | return fMonths; | |
531 | } | |
532 | ||
533 | const UnicodeString* | |
534 | DateFormatSymbols::getShortMonths(int32_t &count) const | |
535 | { | |
536 | count = fShortMonthsCount; | |
537 | return fShortMonths; | |
538 | } | |
539 | ||
540 | const UnicodeString* | |
541 | DateFormatSymbols::getMonths(int32_t &count, DtContextType context, DtWidthType width ) const | |
542 | { | |
543 | UnicodeString *returnValue = NULL; | |
544 | ||
545 | switch (context) { | |
546 | case FORMAT : | |
547 | switch(width) { | |
548 | case WIDE : | |
549 | count = fMonthsCount; | |
550 | returnValue = fMonths; | |
551 | break; | |
552 | case ABBREVIATED : | |
553 | count = fShortMonthsCount; | |
554 | returnValue = fShortMonths; | |
555 | break; | |
556 | case NARROW : | |
557 | count = fNarrowMonthsCount; | |
558 | returnValue = fNarrowMonths; | |
559 | break; | |
560 | case DT_WIDTH_COUNT : | |
561 | break; | |
562 | } | |
563 | break; | |
564 | case STANDALONE : | |
565 | switch(width) { | |
566 | case WIDE : | |
567 | count = fStandaloneMonthsCount; | |
568 | returnValue = fStandaloneMonths; | |
569 | break; | |
570 | case ABBREVIATED : | |
571 | count = fStandaloneShortMonthsCount; | |
572 | returnValue = fStandaloneShortMonths; | |
573 | break; | |
574 | case NARROW : | |
575 | count = fStandaloneNarrowMonthsCount; | |
576 | returnValue = fStandaloneNarrowMonths; | |
577 | break; | |
578 | case DT_WIDTH_COUNT : | |
579 | break; | |
580 | } | |
581 | break; | |
582 | case DT_CONTEXT_COUNT : | |
583 | break; | |
584 | } | |
585 | return returnValue; | |
586 | } | |
587 | ||
588 | const UnicodeString* | |
589 | DateFormatSymbols::getWeekdays(int32_t &count) const | |
590 | { | |
591 | count = fWeekdaysCount; | |
592 | return fWeekdays; | |
593 | } | |
594 | ||
595 | const UnicodeString* | |
596 | DateFormatSymbols::getShortWeekdays(int32_t &count) const | |
597 | { | |
598 | count = fShortWeekdaysCount; | |
599 | return fShortWeekdays; | |
600 | } | |
601 | ||
602 | const UnicodeString* | |
603 | DateFormatSymbols::getWeekdays(int32_t &count, DtContextType context, DtWidthType width) const | |
604 | { | |
605 | UnicodeString *returnValue = NULL; | |
606 | switch (context) { | |
607 | case FORMAT : | |
608 | switch(width) { | |
609 | case WIDE : | |
610 | count = fWeekdaysCount; | |
611 | returnValue = fWeekdays; | |
612 | break; | |
613 | case ABBREVIATED : | |
614 | count = fShortWeekdaysCount; | |
615 | returnValue = fShortWeekdays; | |
616 | break; | |
617 | case NARROW : | |
618 | count = fNarrowWeekdaysCount; | |
619 | returnValue = fNarrowWeekdays; | |
620 | break; | |
621 | case DT_WIDTH_COUNT : | |
622 | break; | |
623 | } | |
624 | break; | |
625 | case STANDALONE : | |
626 | switch(width) { | |
627 | case WIDE : | |
628 | count = fStandaloneWeekdaysCount; | |
629 | returnValue = fStandaloneWeekdays; | |
630 | break; | |
631 | case ABBREVIATED : | |
632 | count = fStandaloneShortWeekdaysCount; | |
633 | returnValue = fStandaloneShortWeekdays; | |
634 | break; | |
635 | case NARROW : | |
636 | count = fStandaloneNarrowWeekdaysCount; | |
637 | returnValue = fStandaloneNarrowWeekdays; | |
638 | break; | |
639 | case DT_WIDTH_COUNT : | |
640 | break; | |
641 | } | |
642 | break; | |
643 | case DT_CONTEXT_COUNT : | |
644 | break; | |
645 | } | |
646 | return returnValue; | |
647 | } | |
648 | ||
649 | const UnicodeString* | |
650 | DateFormatSymbols::getQuarters(int32_t &count, DtContextType context, DtWidthType width ) const | |
651 | { | |
652 | UnicodeString *returnValue = NULL; | |
653 | ||
654 | switch (context) { | |
655 | case FORMAT : | |
656 | switch(width) { | |
657 | case WIDE : | |
658 | count = fQuartersCount; | |
659 | returnValue = fQuarters; | |
660 | break; | |
661 | case ABBREVIATED : | |
662 | count = fShortQuartersCount; | |
663 | returnValue = fShortQuarters; | |
664 | break; | |
665 | case NARROW : | |
666 | count = 0; | |
667 | returnValue = NULL; | |
668 | break; | |
669 | case DT_WIDTH_COUNT : | |
670 | break; | |
671 | } | |
672 | break; | |
673 | case STANDALONE : | |
674 | switch(width) { | |
675 | case WIDE : | |
676 | count = fStandaloneQuartersCount; | |
677 | returnValue = fStandaloneQuarters; | |
678 | break; | |
679 | case ABBREVIATED : | |
680 | count = fStandaloneShortQuartersCount; | |
681 | returnValue = fStandaloneShortQuarters; | |
682 | break; | |
683 | case NARROW : | |
684 | count = 0; | |
685 | returnValue = NULL; | |
686 | break; | |
687 | case DT_WIDTH_COUNT : | |
688 | break; | |
689 | } | |
690 | break; | |
691 | case DT_CONTEXT_COUNT : | |
692 | break; | |
693 | } | |
694 | return returnValue; | |
695 | } | |
696 | ||
697 | const UnicodeString* | |
698 | DateFormatSymbols::getAmPmStrings(int32_t &count) const | |
699 | { | |
700 | count = fAmPmsCount; | |
701 | return fAmPms; | |
702 | } | |
703 | ||
704 | const UnicodeString* | |
705 | DateFormatSymbols::getLeapMonthPatterns(int32_t &count) const | |
706 | { | |
707 | count = fLeapMonthPatternsCount; | |
708 | return fLeapMonthPatterns; | |
709 | } | |
710 | ||
711 | //------------------------------------------------------ | |
712 | ||
713 | void | |
714 | DateFormatSymbols::setEras(const UnicodeString* erasArray, int32_t count) | |
715 | { | |
716 | // delete the old list if we own it | |
717 | if (fEras) | |
718 | delete[] fEras; | |
719 | ||
720 | // we always own the new list, which we create here (we duplicate rather | |
721 | // than adopting the list passed in) | |
722 | fEras = newUnicodeStringArray(count); | |
723 | uprv_arrayCopy(erasArray,fEras, count); | |
724 | fErasCount = count; | |
725 | } | |
726 | ||
727 | void | |
728 | DateFormatSymbols::setEraNames(const UnicodeString* eraNamesArray, int32_t count) | |
729 | { | |
730 | // delete the old list if we own it | |
731 | if (fEraNames) | |
732 | delete[] fEraNames; | |
733 | ||
734 | // we always own the new list, which we create here (we duplicate rather | |
735 | // than adopting the list passed in) | |
736 | fEraNames = newUnicodeStringArray(count); | |
737 | uprv_arrayCopy(eraNamesArray,fEraNames, count); | |
738 | fEraNamesCount = count; | |
739 | } | |
740 | ||
741 | void | |
742 | DateFormatSymbols::setNarrowEras(const UnicodeString* narrowErasArray, int32_t count) | |
743 | { | |
744 | // delete the old list if we own it | |
745 | if (fNarrowEras) | |
746 | delete[] fNarrowEras; | |
747 | ||
748 | // we always own the new list, which we create here (we duplicate rather | |
749 | // than adopting the list passed in) | |
750 | fNarrowEras = newUnicodeStringArray(count); | |
751 | uprv_arrayCopy(narrowErasArray,fNarrowEras, count); | |
752 | fNarrowErasCount = count; | |
753 | } | |
754 | ||
755 | void | |
756 | DateFormatSymbols::setMonths(const UnicodeString* monthsArray, int32_t count) | |
757 | { | |
758 | // delete the old list if we own it | |
759 | if (fMonths) | |
760 | delete[] fMonths; | |
761 | ||
762 | // we always own the new list, which we create here (we duplicate rather | |
763 | // than adopting the list passed in) | |
764 | fMonths = newUnicodeStringArray(count); | |
765 | uprv_arrayCopy( monthsArray,fMonths,count); | |
766 | fMonthsCount = count; | |
767 | } | |
768 | ||
769 | void | |
770 | DateFormatSymbols::setShortMonths(const UnicodeString* shortMonthsArray, int32_t count) | |
771 | { | |
772 | // delete the old list if we own it | |
773 | if (fShortMonths) | |
774 | delete[] fShortMonths; | |
775 | ||
776 | // we always own the new list, which we create here (we duplicate rather | |
777 | // than adopting the list passed in) | |
778 | fShortMonths = newUnicodeStringArray(count); | |
779 | uprv_arrayCopy(shortMonthsArray,fShortMonths, count); | |
780 | fShortMonthsCount = count; | |
781 | } | |
782 | ||
783 | void | |
784 | DateFormatSymbols::setMonths(const UnicodeString* monthsArray, int32_t count, DtContextType context, DtWidthType width) | |
785 | { | |
786 | // delete the old list if we own it | |
787 | // we always own the new list, which we create here (we duplicate rather | |
788 | // than adopting the list passed in) | |
789 | ||
790 | switch (context) { | |
791 | case FORMAT : | |
792 | switch (width) { | |
793 | case WIDE : | |
794 | if (fMonths) | |
795 | delete[] fMonths; | |
796 | fMonths = newUnicodeStringArray(count); | |
797 | uprv_arrayCopy( monthsArray,fMonths,count); | |
798 | fMonthsCount = count; | |
799 | break; | |
800 | case ABBREVIATED : | |
801 | if (fShortMonths) | |
802 | delete[] fShortMonths; | |
803 | fShortMonths = newUnicodeStringArray(count); | |
804 | uprv_arrayCopy( monthsArray,fShortMonths,count); | |
805 | fShortMonthsCount = count; | |
806 | break; | |
807 | case NARROW : | |
808 | if (fNarrowMonths) | |
809 | delete[] fNarrowMonths; | |
810 | fNarrowMonths = newUnicodeStringArray(count); | |
811 | uprv_arrayCopy( monthsArray,fNarrowMonths,count); | |
812 | fNarrowMonthsCount = count; | |
813 | break; | |
814 | case DT_WIDTH_COUNT : | |
815 | break; | |
816 | } | |
817 | break; | |
818 | case STANDALONE : | |
819 | switch (width) { | |
820 | case WIDE : | |
821 | if (fStandaloneMonths) | |
822 | delete[] fStandaloneMonths; | |
823 | fStandaloneMonths = newUnicodeStringArray(count); | |
824 | uprv_arrayCopy( monthsArray,fStandaloneMonths,count); | |
825 | fStandaloneMonthsCount = count; | |
826 | break; | |
827 | case ABBREVIATED : | |
828 | if (fStandaloneShortMonths) | |
829 | delete[] fStandaloneShortMonths; | |
830 | fStandaloneShortMonths = newUnicodeStringArray(count); | |
831 | uprv_arrayCopy( monthsArray,fStandaloneShortMonths,count); | |
832 | fStandaloneShortMonthsCount = count; | |
833 | break; | |
834 | case NARROW : | |
835 | if (fStandaloneNarrowMonths) | |
836 | delete[] fStandaloneNarrowMonths; | |
837 | fStandaloneNarrowMonths = newUnicodeStringArray(count); | |
838 | uprv_arrayCopy( monthsArray,fStandaloneNarrowMonths,count); | |
839 | fStandaloneNarrowMonthsCount = count; | |
840 | break; | |
841 | case DT_WIDTH_COUNT : | |
842 | break; | |
843 | } | |
844 | break; | |
845 | case DT_CONTEXT_COUNT : | |
846 | break; | |
847 | } | |
848 | } | |
849 | ||
850 | void DateFormatSymbols::setWeekdays(const UnicodeString* weekdaysArray, int32_t count) | |
851 | { | |
852 | // delete the old list if we own it | |
853 | if (fWeekdays) | |
854 | delete[] fWeekdays; | |
855 | ||
856 | // we always own the new list, which we create here (we duplicate rather | |
857 | // than adopting the list passed in) | |
858 | fWeekdays = newUnicodeStringArray(count); | |
859 | uprv_arrayCopy(weekdaysArray,fWeekdays,count); | |
860 | fWeekdaysCount = count; | |
861 | } | |
862 | ||
863 | void | |
864 | DateFormatSymbols::setShortWeekdays(const UnicodeString* shortWeekdaysArray, int32_t count) | |
865 | { | |
866 | // delete the old list if we own it | |
867 | if (fShortWeekdays) | |
868 | delete[] fShortWeekdays; | |
869 | ||
870 | // we always own the new list, which we create here (we duplicate rather | |
871 | // than adopting the list passed in) | |
872 | fShortWeekdays = newUnicodeStringArray(count); | |
873 | uprv_arrayCopy(shortWeekdaysArray, fShortWeekdays, count); | |
874 | fShortWeekdaysCount = count; | |
875 | } | |
876 | ||
877 | void | |
878 | DateFormatSymbols::setWeekdays(const UnicodeString* weekdaysArray, int32_t count, DtContextType context, DtWidthType width) | |
879 | { | |
880 | // delete the old list if we own it | |
881 | // we always own the new list, which we create here (we duplicate rather | |
882 | // than adopting the list passed in) | |
883 | ||
884 | switch (context) { | |
885 | case FORMAT : | |
886 | switch (width) { | |
887 | case WIDE : | |
888 | if (fWeekdays) | |
889 | delete[] fWeekdays; | |
890 | fWeekdays = newUnicodeStringArray(count); | |
891 | uprv_arrayCopy(weekdaysArray, fWeekdays, count); | |
892 | fWeekdaysCount = count; | |
893 | break; | |
894 | case ABBREVIATED : | |
895 | if (fShortWeekdays) | |
896 | delete[] fShortWeekdays; | |
897 | fShortWeekdays = newUnicodeStringArray(count); | |
898 | uprv_arrayCopy(weekdaysArray, fShortWeekdays, count); | |
899 | fShortWeekdaysCount = count; | |
900 | break; | |
901 | case NARROW : | |
902 | if (fNarrowWeekdays) | |
903 | delete[] fNarrowWeekdays; | |
904 | fNarrowWeekdays = newUnicodeStringArray(count); | |
905 | uprv_arrayCopy(weekdaysArray, fNarrowWeekdays, count); | |
906 | fNarrowWeekdaysCount = count; | |
907 | break; | |
908 | case DT_WIDTH_COUNT : | |
909 | break; | |
910 | } | |
911 | break; | |
912 | case STANDALONE : | |
913 | switch (width) { | |
914 | case WIDE : | |
915 | if (fStandaloneWeekdays) | |
916 | delete[] fStandaloneWeekdays; | |
917 | fStandaloneWeekdays = newUnicodeStringArray(count); | |
918 | uprv_arrayCopy(weekdaysArray, fStandaloneWeekdays, count); | |
919 | fStandaloneWeekdaysCount = count; | |
920 | break; | |
921 | case ABBREVIATED : | |
922 | if (fStandaloneShortWeekdays) | |
923 | delete[] fStandaloneShortWeekdays; | |
924 | fStandaloneShortWeekdays = newUnicodeStringArray(count); | |
925 | uprv_arrayCopy(weekdaysArray, fStandaloneShortWeekdays, count); | |
926 | fStandaloneShortWeekdaysCount = count; | |
927 | break; | |
928 | case NARROW : | |
929 | if (fStandaloneNarrowWeekdays) | |
930 | delete[] fStandaloneNarrowWeekdays; | |
931 | fStandaloneNarrowWeekdays = newUnicodeStringArray(count); | |
932 | uprv_arrayCopy(weekdaysArray, fStandaloneNarrowWeekdays, count); | |
933 | fStandaloneNarrowWeekdaysCount = count; | |
934 | break; | |
935 | case DT_WIDTH_COUNT : | |
936 | break; | |
937 | } | |
938 | break; | |
939 | case DT_CONTEXT_COUNT : | |
940 | break; | |
941 | } | |
942 | } | |
943 | ||
944 | void | |
945 | DateFormatSymbols::setQuarters(const UnicodeString* quartersArray, int32_t count, DtContextType context, DtWidthType width) | |
946 | { | |
947 | // delete the old list if we own it | |
948 | // we always own the new list, which we create here (we duplicate rather | |
949 | // than adopting the list passed in) | |
950 | ||
951 | switch (context) { | |
952 | case FORMAT : | |
953 | switch (width) { | |
954 | case WIDE : | |
955 | if (fQuarters) | |
956 | delete[] fQuarters; | |
957 | fQuarters = newUnicodeStringArray(count); | |
958 | uprv_arrayCopy( quartersArray,fQuarters,count); | |
959 | fQuartersCount = count; | |
960 | break; | |
961 | case ABBREVIATED : | |
962 | if (fShortQuarters) | |
963 | delete[] fShortQuarters; | |
964 | fShortQuarters = newUnicodeStringArray(count); | |
965 | uprv_arrayCopy( quartersArray,fShortQuarters,count); | |
966 | fShortQuartersCount = count; | |
967 | break; | |
968 | case NARROW : | |
969 | /* | |
970 | if (fNarrowQuarters) | |
971 | delete[] fNarrowQuarters; | |
972 | fNarrowQuarters = newUnicodeStringArray(count); | |
973 | uprv_arrayCopy( quartersArray,fNarrowQuarters,count); | |
974 | fNarrowQuartersCount = count; | |
975 | */ | |
976 | break; | |
977 | case DT_WIDTH_COUNT : | |
978 | break; | |
979 | } | |
980 | break; | |
981 | case STANDALONE : | |
982 | switch (width) { | |
983 | case WIDE : | |
984 | if (fStandaloneQuarters) | |
985 | delete[] fStandaloneQuarters; | |
986 | fStandaloneQuarters = newUnicodeStringArray(count); | |
987 | uprv_arrayCopy( quartersArray,fStandaloneQuarters,count); | |
988 | fStandaloneQuartersCount = count; | |
989 | break; | |
990 | case ABBREVIATED : | |
991 | if (fStandaloneShortQuarters) | |
992 | delete[] fStandaloneShortQuarters; | |
993 | fStandaloneShortQuarters = newUnicodeStringArray(count); | |
994 | uprv_arrayCopy( quartersArray,fStandaloneShortQuarters,count); | |
995 | fStandaloneShortQuartersCount = count; | |
996 | break; | |
997 | case NARROW : | |
998 | /* | |
999 | if (fStandaloneNarrowQuarters) | |
1000 | delete[] fStandaloneNarrowQuarters; | |
1001 | fStandaloneNarrowQuarters = newUnicodeStringArray(count); | |
1002 | uprv_arrayCopy( quartersArray,fStandaloneNarrowQuarters,count); | |
1003 | fStandaloneNarrowQuartersCount = count; | |
1004 | */ | |
1005 | break; | |
1006 | case DT_WIDTH_COUNT : | |
1007 | break; | |
1008 | } | |
1009 | break; | |
1010 | case DT_CONTEXT_COUNT : | |
1011 | break; | |
1012 | } | |
1013 | } | |
1014 | ||
1015 | void | |
1016 | DateFormatSymbols::setAmPmStrings(const UnicodeString* amPmsArray, int32_t count) | |
1017 | { | |
1018 | // delete the old list if we own it | |
1019 | if (fAmPms) delete[] fAmPms; | |
1020 | ||
1021 | // we always own the new list, which we create here (we duplicate rather | |
1022 | // than adopting the list passed in) | |
1023 | fAmPms = newUnicodeStringArray(count); | |
1024 | uprv_arrayCopy(amPmsArray,fAmPms,count); | |
1025 | fAmPmsCount = count; | |
1026 | } | |
1027 | ||
1028 | const UnicodeString** | |
1029 | DateFormatSymbols::getZoneStrings(int32_t& rowCount, int32_t& columnCount) const | |
1030 | { | |
1031 | const UnicodeString **result = NULL; | |
1032 | ||
1033 | umtx_lock(&LOCK); | |
1034 | if (fZoneStrings == NULL) { | |
1035 | if (fLocaleZoneStrings == NULL) { | |
1036 | ((DateFormatSymbols*)this)->initZoneStringsArray(); | |
1037 | } | |
1038 | result = (const UnicodeString**)fLocaleZoneStrings; | |
1039 | } else { | |
1040 | result = (const UnicodeString**)fZoneStrings; | |
1041 | } | |
1042 | rowCount = fZoneStringsRowCount; | |
1043 | columnCount = fZoneStringsColCount; | |
1044 | umtx_unlock(&LOCK); | |
1045 | ||
1046 | return result; | |
1047 | } | |
1048 | ||
1049 | // For now, we include all zones | |
1050 | #define ZONE_SET UCAL_ZONE_TYPE_ANY | |
1051 | ||
1052 | // This code must be called within a synchronized block | |
1053 | void | |
1054 | DateFormatSymbols::initZoneStringsArray(void) { | |
1055 | if (fZoneStrings != NULL || fLocaleZoneStrings != NULL) { | |
1056 | return; | |
1057 | } | |
1058 | ||
1059 | UErrorCode status = U_ZERO_ERROR; | |
1060 | ||
1061 | StringEnumeration *tzids = NULL; | |
1062 | UnicodeString ** zarray = NULL; | |
1063 | TimeZoneNames *tzNames = NULL; | |
1064 | int32_t rows = 0; | |
1065 | ||
1066 | do { // dummy do-while | |
1067 | ||
1068 | tzids = TimeZone::createTimeZoneIDEnumeration(ZONE_SET, NULL, NULL, status); | |
1069 | rows = tzids->count(status); | |
1070 | if (U_FAILURE(status)) { | |
1071 | break; | |
1072 | } | |
1073 | ||
1074 | // Allocate array | |
1075 | int32_t size = rows * sizeof(UnicodeString*); | |
1076 | zarray = (UnicodeString**)uprv_malloc(size); | |
1077 | if (zarray == NULL) { | |
1078 | status = U_MEMORY_ALLOCATION_ERROR; | |
1079 | break; | |
1080 | } | |
1081 | uprv_memset(zarray, 0, size); | |
1082 | ||
1083 | tzNames = TimeZoneNames::createInstance(fZSFLocale, status); | |
1084 | ||
1085 | const UnicodeString *tzid; | |
1086 | int32_t i = 0; | |
1087 | UDate now = Calendar::getNow(); | |
1088 | UnicodeString tzDispName; | |
1089 | ||
1090 | while ((tzid = tzids->snext(status))) { | |
1091 | if (U_FAILURE(status)) { | |
1092 | break; | |
1093 | } | |
1094 | ||
1095 | zarray[i] = new UnicodeString[5]; | |
1096 | if (zarray[i] == NULL) { | |
1097 | status = U_MEMORY_ALLOCATION_ERROR; | |
1098 | break; | |
1099 | } | |
1100 | ||
1101 | zarray[i][0].setTo(*tzid); | |
1102 | zarray[i][1].setTo(tzNames->getDisplayName(*tzid, UTZNM_LONG_STANDARD, now, tzDispName)); | |
1103 | zarray[i][2].setTo(tzNames->getDisplayName(*tzid, UTZNM_SHORT_STANDARD, now, tzDispName)); | |
1104 | zarray[i][3].setTo(tzNames->getDisplayName(*tzid, UTZNM_LONG_DAYLIGHT, now, tzDispName)); | |
1105 | zarray[i][4].setTo(tzNames->getDisplayName(*tzid, UTZNM_SHORT_DAYLIGHT, now, tzDispName)); | |
1106 | i++; | |
1107 | } | |
1108 | ||
1109 | } while (FALSE); | |
1110 | ||
1111 | if (U_FAILURE(status)) { | |
1112 | if (zarray) { | |
1113 | for (int32_t i = 0; i < rows; i++) { | |
1114 | if (zarray[i]) { | |
1115 | delete[] zarray[i]; | |
1116 | } | |
1117 | } | |
1118 | uprv_free(zarray); | |
1119 | } | |
1120 | } | |
1121 | ||
1122 | if (tzNames) { | |
1123 | delete tzNames; | |
1124 | } | |
1125 | if (tzids) { | |
1126 | delete tzids; | |
1127 | } | |
1128 | ||
1129 | fLocaleZoneStrings = zarray; | |
1130 | fZoneStringsRowCount = rows; | |
1131 | fZoneStringsColCount = 5; | |
1132 | } | |
1133 | ||
1134 | void | |
1135 | DateFormatSymbols::setZoneStrings(const UnicodeString* const *strings, int32_t rowCount, int32_t columnCount) | |
1136 | { | |
1137 | // since deleting a 2-d array is a pain in the butt, we offload that task to | |
1138 | // a separate function | |
1139 | disposeZoneStrings(); | |
1140 | // we always own the new list, which we create here (we duplicate rather | |
1141 | // than adopting the list passed in) | |
1142 | fZoneStringsRowCount = rowCount; | |
1143 | fZoneStringsColCount = columnCount; | |
1144 | createZoneStrings((const UnicodeString**)strings); | |
1145 | } | |
1146 | ||
1147 | //------------------------------------------------------ | |
1148 | ||
1149 | const UChar * U_EXPORT2 | |
1150 | DateFormatSymbols::getPatternUChars(void) | |
1151 | { | |
1152 | return gPatternChars; | |
1153 | } | |
1154 | ||
1155 | //------------------------------------------------------ | |
1156 | ||
1157 | UnicodeString& | |
1158 | DateFormatSymbols::getLocalPatternChars(UnicodeString& result) const | |
1159 | { | |
1160 | // fastCopyFrom() - see assignArray comments | |
1161 | return result.fastCopyFrom(fLocalPatternChars); | |
1162 | } | |
1163 | ||
1164 | //------------------------------------------------------ | |
1165 | ||
1166 | void | |
1167 | DateFormatSymbols::setLocalPatternChars(const UnicodeString& newLocalPatternChars) | |
1168 | { | |
1169 | fLocalPatternChars = newLocalPatternChars; | |
1170 | } | |
1171 | ||
1172 | //------------------------------------------------------ | |
1173 | ||
1174 | static void | |
1175 | initField(UnicodeString **field, int32_t& length, const UResourceBundle *data, UErrorCode &status) { | |
1176 | if (U_SUCCESS(status)) { | |
1177 | int32_t strLen = 0; | |
1178 | length = ures_getSize(data); | |
1179 | *field = newUnicodeStringArray(length); | |
1180 | if (*field) { | |
1181 | for(int32_t i = 0; i<length; i++) { | |
1182 | const UChar *resStr = ures_getStringByIndex(data, i, &strLen, &status); | |
1183 | // setTo() - see assignArray comments | |
1184 | (*(field)+i)->setTo(TRUE, resStr, strLen); | |
1185 | } | |
1186 | } | |
1187 | else { | |
1188 | length = 0; | |
1189 | status = U_MEMORY_ALLOCATION_ERROR; | |
1190 | } | |
1191 | } | |
1192 | } | |
1193 | ||
1194 | static void | |
1195 | initField(UnicodeString **field, int32_t& length, const UChar *data, LastResortSize numStr, LastResortSize strLen, UErrorCode &status) { | |
1196 | if (U_SUCCESS(status)) { | |
1197 | length = numStr; | |
1198 | *field = newUnicodeStringArray((size_t)numStr); | |
1199 | if (*field) { | |
1200 | for(int32_t i = 0; i<length; i++) { | |
1201 | // readonly aliases - all "data" strings are constant | |
1202 | // -1 as length for variable-length strings (gLastResortDayNames[0] is empty) | |
1203 | (*(field)+i)->setTo(TRUE, data+(i*((int32_t)strLen)), -1); | |
1204 | } | |
1205 | } | |
1206 | else { | |
1207 | length = 0; | |
1208 | status = U_MEMORY_ALLOCATION_ERROR; | |
1209 | } | |
1210 | } | |
1211 | } | |
1212 | ||
1213 | static void | |
1214 | initLeapMonthPattern(UnicodeString *field, int32_t index, const UResourceBundle *data, UErrorCode &status) { | |
1215 | field[index].remove(); | |
1216 | if (U_SUCCESS(status)) { | |
1217 | int32_t strLen = 0; | |
1218 | const UChar *resStr = ures_getStringByKey(data, gNamesLeapTag, &strLen, &status); | |
1219 | if (U_SUCCESS(status)) { | |
1220 | field[index].setTo(TRUE, resStr, strLen); | |
1221 | } | |
1222 | } | |
1223 | status = U_ZERO_ERROR; | |
1224 | } | |
1225 | ||
1226 | typedef struct { | |
1227 | const char * usageTypeName; | |
1228 | DateFormatSymbols::ECapitalizationContextUsageType usageTypeEnumValue; | |
1229 | } ContextUsageTypeNameToEnumValue; | |
1230 | ||
1231 | static const ContextUsageTypeNameToEnumValue contextUsageTypeMap[] = { | |
1232 | // Entries must be sorted by usageTypeName; entry with NULL name terminates list. | |
1233 | { "day-format-except-narrow", DateFormatSymbols::kCapContextUsageDayFormat }, | |
1234 | { "day-narrow", DateFormatSymbols::kCapContextUsageDayNarrow }, | |
1235 | { "day-standalone-except-narrow", DateFormatSymbols::kCapContextUsageDayStandalone }, | |
1236 | { "era-abbr", DateFormatSymbols::kCapContextUsageEraAbbrev }, | |
1237 | { "era-name", DateFormatSymbols::kCapContextUsageEraWide }, | |
1238 | { "era-narrow", DateFormatSymbols::kCapContextUsageEraNarrow }, | |
1239 | { "metazone-long", DateFormatSymbols::kCapContextUsageMetazoneLong }, | |
1240 | { "metazone-short", DateFormatSymbols::kCapContextUsageMetazoneShort }, | |
1241 | { "month-format-except-narrow", DateFormatSymbols::kCapContextUsageMonthFormat }, | |
1242 | { "month-narrow", DateFormatSymbols::kCapContextUsageMonthNarrow }, | |
1243 | { "month-standalone-except-narrow", DateFormatSymbols::kCapContextUsageMonthStandalone }, | |
1244 | { "zone-long", DateFormatSymbols::kCapContextUsageZoneLong }, | |
1245 | { "zone-short", DateFormatSymbols::kCapContextUsageZoneShort }, | |
1246 | { NULL, (DateFormatSymbols::ECapitalizationContextUsageType)0 }, | |
1247 | }; | |
1248 | ||
1249 | void | |
1250 | DateFormatSymbols::initializeData(const Locale& locale, const char *type, UErrorCode& status, UBool useLastResortData) | |
1251 | { | |
1252 | int32_t i; | |
1253 | int32_t len = 0; | |
1254 | const UChar *resStr; | |
1255 | /* In case something goes wrong, initialize all of the data to NULL. */ | |
1256 | fEras = NULL; | |
1257 | fErasCount = 0; | |
1258 | fEraNames = NULL; | |
1259 | fEraNamesCount = 0; | |
1260 | fNarrowEras = NULL; | |
1261 | fNarrowErasCount = 0; | |
1262 | fMonths = NULL; | |
1263 | fMonthsCount=0; | |
1264 | fShortMonths = NULL; | |
1265 | fShortMonthsCount=0; | |
1266 | fNarrowMonths = NULL; | |
1267 | fNarrowMonthsCount=0; | |
1268 | fStandaloneMonths = NULL; | |
1269 | fStandaloneMonthsCount=0; | |
1270 | fStandaloneShortMonths = NULL; | |
1271 | fStandaloneShortMonthsCount=0; | |
1272 | fStandaloneNarrowMonths = NULL; | |
1273 | fStandaloneNarrowMonthsCount=0; | |
1274 | fWeekdays = NULL; | |
1275 | fWeekdaysCount=0; | |
1276 | fShortWeekdays = NULL; | |
1277 | fShortWeekdaysCount=0; | |
1278 | fNarrowWeekdays = NULL; | |
1279 | fNarrowWeekdaysCount=0; | |
1280 | fStandaloneWeekdays = NULL; | |
1281 | fStandaloneWeekdaysCount=0; | |
1282 | fStandaloneShortWeekdays = NULL; | |
1283 | fStandaloneShortWeekdaysCount=0; | |
1284 | fStandaloneNarrowWeekdays = NULL; | |
1285 | fStandaloneNarrowWeekdaysCount=0; | |
1286 | fAmPms = NULL; | |
1287 | fAmPmsCount=0; | |
1288 | fQuarters = NULL; | |
1289 | fQuartersCount = 0; | |
1290 | fShortQuarters = NULL; | |
1291 | fShortQuartersCount = 0; | |
1292 | fStandaloneQuarters = NULL; | |
1293 | fStandaloneQuartersCount = 0; | |
1294 | fStandaloneShortQuarters = NULL; | |
1295 | fStandaloneShortQuartersCount = 0; | |
1296 | fLeapMonthPatterns = NULL; | |
1297 | fLeapMonthPatternsCount = 0; | |
1298 | fShortYearNames = NULL; | |
1299 | fShortYearNamesCount = 0; | |
1300 | fZoneStringsRowCount = 0; | |
1301 | fZoneStringsColCount = 0; | |
1302 | fZoneStrings = NULL; | |
1303 | fLocaleZoneStrings = NULL; | |
1304 | uprv_memset(fCapitalization, 0, sizeof(fCapitalization)); | |
1305 | ||
1306 | // We need to preserve the requested locale for | |
1307 | // lazy ZoneStringFormat instantiation. ZoneStringFormat | |
1308 | // is region sensitive, thus, bundle locale bundle's locale | |
1309 | // is not sufficient. | |
1310 | fZSFLocale = locale; | |
1311 | ||
1312 | if (U_FAILURE(status)) return; | |
1313 | ||
1314 | /** | |
1315 | * Retrieve the string arrays we need from the resource bundle file. | |
1316 | * We cast away const here, but that's okay; we won't delete any of | |
1317 | * these. | |
1318 | */ | |
1319 | CalendarData calData(locale, type, status); | |
1320 | ||
1321 | // load the first data item | |
1322 | UResourceBundle *erasMain = calData.getByKey(gErasTag, status); | |
1323 | UResourceBundle *eras = ures_getByKeyWithFallback(erasMain, gNamesAbbrTag, NULL, &status); | |
1324 | UErrorCode oldStatus = status; | |
1325 | UResourceBundle *eraNames = ures_getByKeyWithFallback(erasMain, gNamesWideTag, NULL, &status); | |
1326 | if ( status == U_MISSING_RESOURCE_ERROR ) { // Workaround because eras/wide was omitted from CLDR 1.3 | |
1327 | status = oldStatus; | |
1328 | eraNames = ures_getByKeyWithFallback(erasMain, gNamesAbbrTag, NULL, &status); | |
1329 | } | |
1330 | // current ICU4J falls back to abbreviated if narrow eras are missing, so we will too | |
1331 | oldStatus = status; | |
1332 | UResourceBundle *narrowEras = ures_getByKeyWithFallback(erasMain, gNamesNarrowTag, NULL, &status); | |
1333 | if ( status == U_MISSING_RESOURCE_ERROR ) { | |
1334 | status = oldStatus; | |
1335 | narrowEras = ures_getByKeyWithFallback(erasMain, gNamesAbbrTag, NULL, &status); | |
1336 | } | |
1337 | ||
1338 | UErrorCode tempStatus = U_ZERO_ERROR; | |
1339 | UResourceBundle *monthPatterns = calData.getByKey(gMonthPatternsTag, tempStatus); | |
1340 | if (U_SUCCESS(tempStatus) && monthPatterns != NULL) { | |
1341 | fLeapMonthPatterns = newUnicodeStringArray(kMonthPatternsCount); | |
1342 | if (fLeapMonthPatterns) { | |
1343 | initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternFormatWide, calData.getByKey2(gMonthPatternsTag, gNamesWideTag, tempStatus), tempStatus); | |
1344 | initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternFormatAbbrev, calData.getByKey2(gMonthPatternsTag, gNamesAbbrTag, tempStatus), tempStatus); | |
1345 | initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternFormatNarrow, calData.getByKey2(gMonthPatternsTag, gNamesNarrowTag, tempStatus), tempStatus); | |
1346 | initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternStandaloneWide, calData.getByKey3(gMonthPatternsTag, gNamesStandaloneTag, gNamesWideTag, tempStatus), tempStatus); | |
1347 | initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternStandaloneAbbrev, calData.getByKey3(gMonthPatternsTag, gNamesStandaloneTag, gNamesAbbrTag, tempStatus), tempStatus); | |
1348 | initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternStandaloneNarrow, calData.getByKey3(gMonthPatternsTag, gNamesStandaloneTag, gNamesNarrowTag, tempStatus), tempStatus); | |
1349 | initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternNumeric, calData.getByKey3(gMonthPatternsTag, gNamesNumericTag, gNamesAllTag, tempStatus), tempStatus); | |
1350 | if (U_SUCCESS(tempStatus)) { | |
1351 | fLeapMonthPatternsCount = kMonthPatternsCount; | |
1352 | } else { | |
1353 | delete[] fLeapMonthPatterns; | |
1354 | fLeapMonthPatterns = NULL; | |
1355 | } | |
1356 | } | |
1357 | } | |
1358 | ||
1359 | tempStatus = U_ZERO_ERROR; | |
1360 | UResourceBundle *cyclicNameSets= calData.getByKey(gCyclicNameSetsTag, tempStatus); | |
1361 | if (U_SUCCESS(tempStatus) && cyclicNameSets != NULL) { | |
1362 | UResourceBundle *nameSetYears = ures_getByKeyWithFallback(cyclicNameSets, gNameSetYearsTag, NULL, &tempStatus); | |
1363 | if (U_SUCCESS(tempStatus)) { | |
1364 | UResourceBundle *nameSetYearsFmt = ures_getByKeyWithFallback(nameSetYears, gNamesFormatTag, NULL, &tempStatus); | |
1365 | if (U_SUCCESS(tempStatus)) { | |
1366 | UResourceBundle *nameSetYearsFmtAbbrev = ures_getByKeyWithFallback(nameSetYearsFmt, gNamesAbbrTag, NULL, &tempStatus); | |
1367 | if (U_SUCCESS(tempStatus)) { | |
1368 | initField(&fShortYearNames, fShortYearNamesCount, nameSetYearsFmtAbbrev, tempStatus); | |
1369 | ures_close(nameSetYearsFmtAbbrev); | |
1370 | } | |
1371 | ures_close(nameSetYearsFmt); | |
1372 | } | |
1373 | ures_close(nameSetYears); | |
1374 | } | |
1375 | } | |
1376 | ||
1377 | tempStatus = U_ZERO_ERROR; | |
1378 | UResourceBundle *localeBundle = ures_open(NULL, locale.getName(), &tempStatus); | |
1379 | if (U_SUCCESS(tempStatus)) { | |
1380 | UResourceBundle *contextTransforms = ures_getByKeyWithFallback(localeBundle, gContextTransformsTag, NULL, &tempStatus); | |
1381 | if (U_SUCCESS(tempStatus)) { | |
1382 | UResourceBundle *contextTransformUsage; | |
1383 | while ( (contextTransformUsage = ures_getNextResource(contextTransforms, NULL, &tempStatus)) != NULL ) { | |
1384 | const int32_t * intVector = ures_getIntVector(contextTransformUsage, &len, &status); | |
1385 | if (U_SUCCESS(tempStatus) && intVector != NULL && len >= 2) { | |
1386 | const char* usageType = ures_getKey(contextTransformUsage); | |
1387 | if (usageType != NULL) { | |
1388 | const ContextUsageTypeNameToEnumValue * typeMapPtr = contextUsageTypeMap; | |
1389 | int32_t compResult = 0; | |
1390 | // linear search; list is short and we cannot be sure that bsearch is available | |
1391 | while ( typeMapPtr->usageTypeName != NULL && (compResult = uprv_strcmp(usageType, typeMapPtr->usageTypeName)) > 0 ) { | |
1392 | ++typeMapPtr; | |
1393 | } | |
1394 | if (typeMapPtr->usageTypeName != NULL && compResult == 0) { | |
1395 | fCapitalization[typeMapPtr->usageTypeEnumValue][0] = intVector[0]; | |
1396 | fCapitalization[typeMapPtr->usageTypeEnumValue][1] = intVector[1]; | |
1397 | } | |
1398 | } | |
1399 | } | |
1400 | tempStatus = U_ZERO_ERROR; | |
1401 | ures_close(contextTransformUsage); | |
1402 | } | |
1403 | ures_close(contextTransforms); | |
1404 | } | |
1405 | ures_close(localeBundle); | |
1406 | } | |
1407 | ||
1408 | UResourceBundle *lsweekdaysData = NULL; // Data closed by calData | |
1409 | UResourceBundle *weekdaysData = NULL; // Data closed by calData | |
1410 | UResourceBundle *narrowWeekdaysData = NULL; // Data closed by calData | |
1411 | UResourceBundle *standaloneWeekdaysData = NULL; // Data closed by calData | |
1412 | UResourceBundle *standaloneShortWeekdaysData = NULL; // Data closed by calData | |
1413 | UResourceBundle *standaloneNarrowWeekdaysData = NULL; // Data closed by calData | |
1414 | ||
1415 | U_LOCALE_BASED(locBased, *this); | |
1416 | if (U_FAILURE(status)) | |
1417 | { | |
1418 | if (useLastResortData) | |
1419 | { | |
1420 | // Handle the case in which there is no resource data present. | |
1421 | // We don't have to generate usable patterns in this situation; | |
1422 | // we just need to produce something that will be semi-intelligible | |
1423 | // in most locales. | |
1424 | ||
1425 | status = U_USING_FALLBACK_WARNING; | |
1426 | ||
1427 | initField(&fEras, fErasCount, (const UChar *)gLastResortEras, kEraNum, kEraLen, status); | |
1428 | initField(&fEraNames, fEraNamesCount, (const UChar *)gLastResortEras, kEraNum, kEraLen, status); | |
1429 | initField(&fNarrowEras, fNarrowErasCount, (const UChar *)gLastResortEras, kEraNum, kEraLen, status); | |
1430 | initField(&fMonths, fMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status); | |
1431 | initField(&fShortMonths, fShortMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status); | |
1432 | initField(&fNarrowMonths, fNarrowMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status); | |
1433 | initField(&fStandaloneMonths, fStandaloneMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status); | |
1434 | initField(&fStandaloneShortMonths, fStandaloneShortMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status); | |
1435 | initField(&fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status); | |
1436 | initField(&fWeekdays, fWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); | |
1437 | initField(&fShortWeekdays, fShortWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); | |
1438 | initField(&fNarrowWeekdays, fNarrowWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); | |
1439 | initField(&fStandaloneWeekdays, fStandaloneWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); | |
1440 | initField(&fStandaloneShortWeekdays, fStandaloneShortWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); | |
1441 | initField(&fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); | |
1442 | initField(&fAmPms, fAmPmsCount, (const UChar *)gLastResortAmPmMarkers, kAmPmNum, kAmPmLen, status); | |
1443 | initField(&fQuarters, fQuartersCount, (const UChar *)gLastResortQuarters, kQuarterNum, kQuarterLen, status); | |
1444 | initField(&fShortQuarters, fShortQuartersCount, (const UChar *)gLastResortQuarters, kQuarterNum, kQuarterLen, status); | |
1445 | initField(&fStandaloneQuarters, fStandaloneQuartersCount, (const UChar *)gLastResortQuarters, kQuarterNum, kQuarterLen, status); | |
1446 | initField(&fStandaloneShortQuarters, fStandaloneShortQuartersCount, (const UChar *)gLastResortQuarters, kQuarterNum, kQuarterLen, status); | |
1447 | fLocalPatternChars.setTo(TRUE, gPatternChars, PATTERN_CHARS_LEN); | |
1448 | } | |
1449 | goto cleanup; | |
1450 | } | |
1451 | ||
1452 | // if we make it to here, the resource data is cool, and we can get everything out | |
1453 | // of it that we need except for the time-zone and localized-pattern data, which | |
1454 | // are stored in a separate file | |
1455 | locBased.setLocaleIDs(ures_getLocaleByType(eras, ULOC_VALID_LOCALE, &status), | |
1456 | ures_getLocaleByType(eras, ULOC_ACTUAL_LOCALE, &status)); | |
1457 | ||
1458 | initField(&fEras, fErasCount, eras, status); | |
1459 | initField(&fEraNames, fEraNamesCount, eraNames, status); | |
1460 | initField(&fNarrowEras, fNarrowErasCount, narrowEras, status); | |
1461 | ||
1462 | initField(&fMonths, fMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesWideTag, status), status); | |
1463 | initField(&fShortMonths, fShortMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesAbbrTag, status), status); | |
1464 | ||
1465 | initField(&fNarrowMonths, fNarrowMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesNarrowTag, status), status); | |
1466 | if(status == U_MISSING_RESOURCE_ERROR) { | |
1467 | status = U_ZERO_ERROR; | |
1468 | initField(&fNarrowMonths, fNarrowMonthsCount, calData.getByKey3(gMonthNamesTag, gNamesStandaloneTag, gNamesNarrowTag, status), status); | |
1469 | } | |
1470 | if ( status == U_MISSING_RESOURCE_ERROR ) { /* If format/narrow not available, use format/abbreviated */ | |
1471 | status = U_ZERO_ERROR; | |
1472 | initField(&fNarrowMonths, fNarrowMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesAbbrTag, status), status); | |
1473 | } | |
1474 | ||
1475 | initField(&fStandaloneMonths, fStandaloneMonthsCount, calData.getByKey3(gMonthNamesTag, gNamesStandaloneTag, gNamesWideTag, status), status); | |
1476 | if ( status == U_MISSING_RESOURCE_ERROR ) { /* If standalone/wide not available, use format/wide */ | |
1477 | status = U_ZERO_ERROR; | |
1478 | initField(&fStandaloneMonths, fStandaloneMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesWideTag, status), status); | |
1479 | } | |
1480 | initField(&fStandaloneShortMonths, fStandaloneShortMonthsCount, calData.getByKey3(gMonthNamesTag, gNamesStandaloneTag, gNamesAbbrTag, status), status); | |
1481 | if ( status == U_MISSING_RESOURCE_ERROR ) { /* If standalone/abbreviated not available, use format/abbreviated */ | |
1482 | status = U_ZERO_ERROR; | |
1483 | initField(&fStandaloneShortMonths, fStandaloneShortMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesAbbrTag, status), status); | |
1484 | } | |
1485 | initField(&fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, calData.getByKey3(gMonthNamesTag, gNamesStandaloneTag, gNamesNarrowTag, status), status); | |
1486 | if ( status == U_MISSING_RESOURCE_ERROR ) { /* if standalone/narrow not availabe, try format/narrow */ | |
1487 | status = U_ZERO_ERROR; | |
1488 | initField(&fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesNarrowTag, status), status); | |
1489 | if ( status == U_MISSING_RESOURCE_ERROR ) { /* if still not there, use format/abbreviated */ | |
1490 | status = U_ZERO_ERROR; | |
1491 | initField(&fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesAbbrTag, status), status); | |
1492 | } | |
1493 | } | |
1494 | initField(&fAmPms, fAmPmsCount, calData.getByKey(gAmPmMarkersTag, status), status); | |
1495 | ||
1496 | initField(&fQuarters, fQuartersCount, calData.getByKey2(gQuartersTag, gNamesWideTag, status), status); | |
1497 | initField(&fShortQuarters, fShortQuartersCount, calData.getByKey2(gQuartersTag, gNamesAbbrTag, status), status); | |
1498 | ||
1499 | initField(&fStandaloneQuarters, fStandaloneQuartersCount, calData.getByKey3(gQuartersTag, gNamesStandaloneTag, gNamesWideTag, status), status); | |
1500 | if(status == U_MISSING_RESOURCE_ERROR) { | |
1501 | status = U_ZERO_ERROR; | |
1502 | initField(&fStandaloneQuarters, fStandaloneQuartersCount, calData.getByKey2(gQuartersTag, gNamesWideTag, status), status); | |
1503 | } | |
1504 | ||
1505 | initField(&fStandaloneShortQuarters, fStandaloneShortQuartersCount, calData.getByKey3(gQuartersTag, gNamesStandaloneTag, gNamesAbbrTag, status), status); | |
1506 | if(status == U_MISSING_RESOURCE_ERROR) { | |
1507 | status = U_ZERO_ERROR; | |
1508 | initField(&fStandaloneShortQuarters, fStandaloneShortQuartersCount, calData.getByKey2(gQuartersTag, gNamesAbbrTag, status), status); | |
1509 | } | |
1510 | ||
1511 | // ICU 3.8 or later version no longer uses localized date-time pattern characters by default (ticket#5597) | |
1512 | /* | |
1513 | // fastCopyFrom()/setTo() - see assignArray comments | |
1514 | resStr = ures_getStringByKey(fResourceBundle, gLocalPatternCharsTag, &len, &status); | |
1515 | fLocalPatternChars.setTo(TRUE, resStr, len); | |
1516 | // If the locale data does not include new pattern chars, use the defaults | |
1517 | // TODO: Consider making this an error, since this may add conflicting characters. | |
1518 | if (len < PATTERN_CHARS_LEN) { | |
1519 | fLocalPatternChars.append(UnicodeString(TRUE, &gPatternChars[len], PATTERN_CHARS_LEN-len)); | |
1520 | } | |
1521 | */ | |
1522 | fLocalPatternChars.setTo(TRUE, gPatternChars, PATTERN_CHARS_LEN); | |
1523 | ||
1524 | // {sfb} fixed to handle 1-based weekdays | |
1525 | weekdaysData = calData.getByKey2(gDayNamesTag, gNamesWideTag, status); | |
1526 | fWeekdaysCount = ures_getSize(weekdaysData); | |
1527 | fWeekdays = new UnicodeString[fWeekdaysCount+1]; | |
1528 | /* pin the blame on system. If we cannot get a chunk of memory .. the system is dying!*/ | |
1529 | if (fWeekdays == NULL) { | |
1530 | status = U_MEMORY_ALLOCATION_ERROR; | |
1531 | goto cleanup; | |
1532 | } | |
1533 | // leave fWeekdays[0] empty | |
1534 | for(i = 0; i<fWeekdaysCount; i++) { | |
1535 | resStr = ures_getStringByIndex(weekdaysData, i, &len, &status); | |
1536 | // setTo() - see assignArray comments | |
1537 | fWeekdays[i+1].setTo(TRUE, resStr, len); | |
1538 | } | |
1539 | fWeekdaysCount++; | |
1540 | ||
1541 | lsweekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status); | |
1542 | fShortWeekdaysCount = ures_getSize(lsweekdaysData); | |
1543 | fShortWeekdays = new UnicodeString[fShortWeekdaysCount+1]; | |
1544 | /* test for NULL */ | |
1545 | if (fShortWeekdays == 0) { | |
1546 | status = U_MEMORY_ALLOCATION_ERROR; | |
1547 | goto cleanup; | |
1548 | } | |
1549 | // leave fShortWeekdays[0] empty | |
1550 | for(i = 0; i<fShortWeekdaysCount; i++) { | |
1551 | resStr = ures_getStringByIndex(lsweekdaysData, i, &len, &status); | |
1552 | // setTo() - see assignArray comments | |
1553 | fShortWeekdays[i+1].setTo(TRUE, resStr, len); | |
1554 | } | |
1555 | fShortWeekdaysCount++; | |
1556 | ||
1557 | narrowWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesNarrowTag, status); | |
1558 | if(status == U_MISSING_RESOURCE_ERROR) { | |
1559 | status = U_ZERO_ERROR; | |
1560 | narrowWeekdaysData = calData.getByKey3(gDayNamesTag, gNamesStandaloneTag, gNamesNarrowTag, status); | |
1561 | } | |
1562 | if ( status == U_MISSING_RESOURCE_ERROR ) { | |
1563 | status = U_ZERO_ERROR; | |
1564 | narrowWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status); | |
1565 | } | |
1566 | fNarrowWeekdaysCount = ures_getSize(narrowWeekdaysData); | |
1567 | fNarrowWeekdays = new UnicodeString[fNarrowWeekdaysCount+1]; | |
1568 | /* test for NULL */ | |
1569 | if (fNarrowWeekdays == 0) { | |
1570 | status = U_MEMORY_ALLOCATION_ERROR; | |
1571 | goto cleanup; | |
1572 | } | |
1573 | // leave fNarrowWeekdays[0] empty | |
1574 | for(i = 0; i<fNarrowWeekdaysCount; i++) { | |
1575 | resStr = ures_getStringByIndex(narrowWeekdaysData, i, &len, &status); | |
1576 | // setTo() - see assignArray comments | |
1577 | fNarrowWeekdays[i+1].setTo(TRUE, resStr, len); | |
1578 | } | |
1579 | fNarrowWeekdaysCount++; | |
1580 | ||
1581 | standaloneWeekdaysData = calData.getByKey3(gDayNamesTag, gNamesStandaloneTag, gNamesWideTag, status); | |
1582 | if ( status == U_MISSING_RESOURCE_ERROR ) { | |
1583 | status = U_ZERO_ERROR; | |
1584 | standaloneWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesWideTag, status); | |
1585 | } | |
1586 | fStandaloneWeekdaysCount = ures_getSize(standaloneWeekdaysData); | |
1587 | fStandaloneWeekdays = new UnicodeString[fStandaloneWeekdaysCount+1]; | |
1588 | /* test for NULL */ | |
1589 | if (fStandaloneWeekdays == 0) { | |
1590 | status = U_MEMORY_ALLOCATION_ERROR; | |
1591 | goto cleanup; | |
1592 | } | |
1593 | // leave fStandaloneWeekdays[0] empty | |
1594 | for(i = 0; i<fStandaloneWeekdaysCount; i++) { | |
1595 | resStr = ures_getStringByIndex(standaloneWeekdaysData, i, &len, &status); | |
1596 | // setTo() - see assignArray comments | |
1597 | fStandaloneWeekdays[i+1].setTo(TRUE, resStr, len); | |
1598 | } | |
1599 | fStandaloneWeekdaysCount++; | |
1600 | ||
1601 | standaloneShortWeekdaysData = calData.getByKey3(gDayNamesTag, gNamesStandaloneTag, gNamesAbbrTag, status); | |
1602 | if ( status == U_MISSING_RESOURCE_ERROR ) { | |
1603 | status = U_ZERO_ERROR; | |
1604 | standaloneShortWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status); | |
1605 | } | |
1606 | fStandaloneShortWeekdaysCount = ures_getSize(standaloneShortWeekdaysData); | |
1607 | fStandaloneShortWeekdays = new UnicodeString[fStandaloneShortWeekdaysCount+1]; | |
1608 | /* test for NULL */ | |
1609 | if (fStandaloneShortWeekdays == 0) { | |
1610 | status = U_MEMORY_ALLOCATION_ERROR; | |
1611 | goto cleanup; | |
1612 | } | |
1613 | // leave fStandaloneShortWeekdays[0] empty | |
1614 | for(i = 0; i<fStandaloneShortWeekdaysCount; i++) { | |
1615 | resStr = ures_getStringByIndex(standaloneShortWeekdaysData, i, &len, &status); | |
1616 | // setTo() - see assignArray comments | |
1617 | fStandaloneShortWeekdays[i+1].setTo(TRUE, resStr, len); | |
1618 | } | |
1619 | fStandaloneShortWeekdaysCount++; | |
1620 | ||
1621 | standaloneNarrowWeekdaysData = calData.getByKey3(gDayNamesTag, gNamesStandaloneTag, gNamesNarrowTag, status); | |
1622 | if ( status == U_MISSING_RESOURCE_ERROR ) { | |
1623 | status = U_ZERO_ERROR; | |
1624 | standaloneNarrowWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesNarrowTag, status); | |
1625 | if ( status == U_MISSING_RESOURCE_ERROR ) { | |
1626 | status = U_ZERO_ERROR; | |
1627 | standaloneNarrowWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status); | |
1628 | } | |
1629 | } | |
1630 | fStandaloneNarrowWeekdaysCount = ures_getSize(standaloneNarrowWeekdaysData); | |
1631 | fStandaloneNarrowWeekdays = new UnicodeString[fStandaloneNarrowWeekdaysCount+1]; | |
1632 | /* test for NULL */ | |
1633 | if (fStandaloneNarrowWeekdays == 0) { | |
1634 | status = U_MEMORY_ALLOCATION_ERROR; | |
1635 | goto cleanup; | |
1636 | } | |
1637 | // leave fStandaloneNarrowWeekdays[0] empty | |
1638 | for(i = 0; i<fStandaloneNarrowWeekdaysCount; i++) { | |
1639 | resStr = ures_getStringByIndex(standaloneNarrowWeekdaysData, i, &len, &status); | |
1640 | // setTo() - see assignArray comments | |
1641 | fStandaloneNarrowWeekdays[i+1].setTo(TRUE, resStr, len); | |
1642 | } | |
1643 | fStandaloneNarrowWeekdaysCount++; | |
1644 | ||
1645 | cleanup: | |
1646 | ures_close(eras); | |
1647 | ures_close(eraNames); | |
1648 | ures_close(narrowEras); | |
1649 | } | |
1650 | ||
1651 | Locale | |
1652 | DateFormatSymbols::getLocale(ULocDataLocaleType type, UErrorCode& status) const { | |
1653 | U_LOCALE_BASED(locBased, *this); | |
1654 | return locBased.getLocale(type, status); | |
1655 | } | |
1656 | ||
1657 | U_NAMESPACE_END | |
1658 | ||
1659 | #endif /* #if !UCONFIG_NO_FORMATTING */ | |
1660 | ||
1661 | //eof |