1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/i18n/dtfmtsym.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,1795 @@ 1.4 +/* 1.5 +******************************************************************************* 1.6 +* Copyright (C) 1997-2013, International Business Machines Corporation and * 1.7 +* others. All Rights Reserved. * 1.8 +******************************************************************************* 1.9 +* 1.10 +* File DTFMTSYM.CPP 1.11 +* 1.12 +* Modification History: 1.13 +* 1.14 +* Date Name Description 1.15 +* 02/19/97 aliu Converted from java. 1.16 +* 07/21/98 stephen Added getZoneIndex 1.17 +* Changed weekdays/short weekdays to be one-based 1.18 +* 06/14/99 stephen Removed SimpleDateFormat::fgTimeZoneDataSuffix 1.19 +* 11/16/99 weiv Added 'Y' and 'e' to fgPatternChars 1.20 +* 03/27/00 weiv Keeping resource bundle around! 1.21 +* 06/30/05 emmons Added eraNames, narrow month/day, standalone context 1.22 +* 10/12/05 emmons Added setters for eraNames, month/day by width/context 1.23 +******************************************************************************* 1.24 +*/ 1.25 +#include "unicode/utypes.h" 1.26 + 1.27 +#if !UCONFIG_NO_FORMATTING 1.28 +#include "unicode/ustring.h" 1.29 +#include "unicode/dtfmtsym.h" 1.30 +#include "unicode/smpdtfmt.h" 1.31 +#include "unicode/msgfmt.h" 1.32 +#include "unicode/tznames.h" 1.33 +#include "cpputils.h" 1.34 +#include "ucln_in.h" 1.35 +#include "umutex.h" 1.36 +#include "cmemory.h" 1.37 +#include "cstring.h" 1.38 +#include "locbased.h" 1.39 +#include "gregoimp.h" 1.40 +#include "hash.h" 1.41 +#include "uresimp.h" 1.42 +#include "ureslocs.h" 1.43 + 1.44 +// ***************************************************************************** 1.45 +// class DateFormatSymbols 1.46 +// ***************************************************************************** 1.47 + 1.48 +/** 1.49 + * These are static arrays we use only in the case where we have no 1.50 + * resource data. 1.51 + */ 1.52 + 1.53 +#define PATTERN_CHARS_LEN 34 1.54 + 1.55 +/** 1.56 + * Unlocalized date-time pattern characters. For example: 'y', 'd', etc. All 1.57 + * locales use the same these unlocalized pattern characters. 1.58 + */ 1.59 +static const UChar gPatternChars[] = { 1.60 + // GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXx 1.61 + 0x47, 0x79, 0x4D, 0x64, 0x6B, 0x48, 0x6D, 0x73, 0x53, 0x45, 1.62 + 0x44, 0x46, 0x77, 0x57, 0x61, 0x68, 0x4B, 0x7A, 0x59, 0x65, 1.63 + 0x75, 0x67, 0x41, 0x5A, 0x76, 0x63, 0x4c, 0x51, 0x71, 0x56, 1.64 + 0x55, 0x4F, 0x58, 0x78, 0 1.65 +}; 1.66 + 1.67 +/* length of an array */ 1.68 +#define ARRAY_LENGTH(array) (sizeof(array)/sizeof(array[0])) 1.69 + 1.70 +//------------------------------------------------------ 1.71 +// Strings of last resort. These are only used if we have no resource 1.72 +// files. They aren't designed for actual use, just for backup. 1.73 + 1.74 +// These are the month names and abbreviations of last resort. 1.75 +static const UChar gLastResortMonthNames[13][3] = 1.76 +{ 1.77 + {0x0030, 0x0031, 0x0000}, /* "01" */ 1.78 + {0x0030, 0x0032, 0x0000}, /* "02" */ 1.79 + {0x0030, 0x0033, 0x0000}, /* "03" */ 1.80 + {0x0030, 0x0034, 0x0000}, /* "04" */ 1.81 + {0x0030, 0x0035, 0x0000}, /* "05" */ 1.82 + {0x0030, 0x0036, 0x0000}, /* "06" */ 1.83 + {0x0030, 0x0037, 0x0000}, /* "07" */ 1.84 + {0x0030, 0x0038, 0x0000}, /* "08" */ 1.85 + {0x0030, 0x0039, 0x0000}, /* "09" */ 1.86 + {0x0031, 0x0030, 0x0000}, /* "10" */ 1.87 + {0x0031, 0x0031, 0x0000}, /* "11" */ 1.88 + {0x0031, 0x0032, 0x0000}, /* "12" */ 1.89 + {0x0031, 0x0033, 0x0000} /* "13" */ 1.90 +}; 1.91 + 1.92 +// These are the weekday names and abbreviations of last resort. 1.93 +static const UChar gLastResortDayNames[8][2] = 1.94 +{ 1.95 + {0x0030, 0x0000}, /* "0" */ 1.96 + {0x0031, 0x0000}, /* "1" */ 1.97 + {0x0032, 0x0000}, /* "2" */ 1.98 + {0x0033, 0x0000}, /* "3" */ 1.99 + {0x0034, 0x0000}, /* "4" */ 1.100 + {0x0035, 0x0000}, /* "5" */ 1.101 + {0x0036, 0x0000}, /* "6" */ 1.102 + {0x0037, 0x0000} /* "7" */ 1.103 +}; 1.104 + 1.105 +// These are the quarter names and abbreviations of last resort. 1.106 +static const UChar gLastResortQuarters[4][2] = 1.107 +{ 1.108 + {0x0031, 0x0000}, /* "1" */ 1.109 + {0x0032, 0x0000}, /* "2" */ 1.110 + {0x0033, 0x0000}, /* "3" */ 1.111 + {0x0034, 0x0000}, /* "4" */ 1.112 +}; 1.113 + 1.114 +// These are the am/pm and BC/AD markers of last resort. 1.115 +static const UChar gLastResortAmPmMarkers[2][3] = 1.116 +{ 1.117 + {0x0041, 0x004D, 0x0000}, /* "AM" */ 1.118 + {0x0050, 0x004D, 0x0000} /* "PM" */ 1.119 +}; 1.120 + 1.121 +static const UChar gLastResortEras[2][3] = 1.122 +{ 1.123 + {0x0042, 0x0043, 0x0000}, /* "BC" */ 1.124 + {0x0041, 0x0044, 0x0000} /* "AD" */ 1.125 +}; 1.126 + 1.127 +/* Sizes for the last resort string arrays */ 1.128 +typedef enum LastResortSize { 1.129 + kMonthNum = 13, 1.130 + kMonthLen = 3, 1.131 + 1.132 + kDayNum = 8, 1.133 + kDayLen = 2, 1.134 + 1.135 + kAmPmNum = 2, 1.136 + kAmPmLen = 3, 1.137 + 1.138 + kQuarterNum = 4, 1.139 + kQuarterLen = 2, 1.140 + 1.141 + kEraNum = 2, 1.142 + kEraLen = 3, 1.143 + 1.144 + kZoneNum = 5, 1.145 + kZoneLen = 4, 1.146 + 1.147 + kGmtHourNum = 4, 1.148 + kGmtHourLen = 10 1.149 +} LastResortSize; 1.150 + 1.151 +U_NAMESPACE_BEGIN 1.152 + 1.153 +UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateFormatSymbols) 1.154 + 1.155 +#define kSUPPLEMENTAL "supplementalData" 1.156 + 1.157 +/** 1.158 + * These are the tags we expect to see in normal resource bundle files associated 1.159 + * with a locale and calendar 1.160 + */ 1.161 +static const char gErasTag[]="eras"; 1.162 +static const char gCyclicNameSetsTag[]="cyclicNameSets"; 1.163 +static const char gNameSetYearsTag[]="years"; 1.164 +static const char gMonthNamesTag[]="monthNames"; 1.165 +static const char gMonthPatternsTag[]="monthPatterns"; 1.166 +static const char gDayNamesTag[]="dayNames"; 1.167 +static const char gNamesWideTag[]="wide"; 1.168 +static const char gNamesAbbrTag[]="abbreviated"; 1.169 +static const char gNamesShortTag[]="short"; 1.170 +static const char gNamesNarrowTag[]="narrow"; 1.171 +static const char gNamesAllTag[]="all"; 1.172 +static const char gNamesLeapTag[]="leap"; 1.173 +static const char gNamesFormatTag[]="format"; 1.174 +static const char gNamesStandaloneTag[]="stand-alone"; 1.175 +static const char gNamesNumericTag[]="numeric"; 1.176 +static const char gAmPmMarkersTag[]="AmPmMarkers"; 1.177 +static const char gQuartersTag[]="quarters"; 1.178 + 1.179 +// static const char gZoneStringsTag[]="zoneStrings"; 1.180 + 1.181 +// static const char gLocalPatternCharsTag[]="localPatternChars"; 1.182 + 1.183 +static const char gContextTransformsTag[]="contextTransforms"; 1.184 + 1.185 +static UMutex LOCK = U_MUTEX_INITIALIZER; 1.186 + 1.187 +/** 1.188 + * Jitterbug 2974: MSVC has a bug whereby new X[0] behaves badly. 1.189 + * Work around this. 1.190 + */ 1.191 +static inline UnicodeString* newUnicodeStringArray(size_t count) { 1.192 + return new UnicodeString[count ? count : 1]; 1.193 +} 1.194 + 1.195 +//------------------------------------------------------ 1.196 + 1.197 +DateFormatSymbols::DateFormatSymbols(const Locale& locale, 1.198 + UErrorCode& status) 1.199 + : UObject() 1.200 +{ 1.201 + initializeData(locale, NULL, status); 1.202 +} 1.203 + 1.204 +DateFormatSymbols::DateFormatSymbols(UErrorCode& status) 1.205 + : UObject() 1.206 +{ 1.207 + initializeData(Locale::getDefault(), NULL, status, TRUE); 1.208 +} 1.209 + 1.210 + 1.211 +DateFormatSymbols::DateFormatSymbols(const Locale& locale, 1.212 + const char *type, 1.213 + UErrorCode& status) 1.214 + : UObject() 1.215 +{ 1.216 + initializeData(locale, type, status); 1.217 +} 1.218 + 1.219 +DateFormatSymbols::DateFormatSymbols(const char *type, UErrorCode& status) 1.220 + : UObject() 1.221 +{ 1.222 + initializeData(Locale::getDefault(), type, status, TRUE); 1.223 +} 1.224 + 1.225 +DateFormatSymbols::DateFormatSymbols(const DateFormatSymbols& other) 1.226 + : UObject(other) 1.227 +{ 1.228 + copyData(other); 1.229 +} 1.230 + 1.231 +void 1.232 +DateFormatSymbols::assignArray(UnicodeString*& dstArray, 1.233 + int32_t& dstCount, 1.234 + const UnicodeString* srcArray, 1.235 + int32_t srcCount) 1.236 +{ 1.237 + // assignArray() is only called by copyData(), which in turn implements the 1.238 + // copy constructor and the assignment operator. 1.239 + // All strings in a DateFormatSymbols object are created in one of the following 1.240 + // three ways that all allow to safely use UnicodeString::fastCopyFrom(): 1.241 + // - readonly-aliases from resource bundles 1.242 + // - readonly-aliases or allocated strings from constants 1.243 + // - safely cloned strings (with owned buffers) from setXYZ() functions 1.244 + // 1.245 + // Note that this is true for as long as DateFormatSymbols can be constructed 1.246 + // only from a locale bundle or set via the cloning API, 1.247 + // *and* for as long as all the strings are in *private* fields, preventing 1.248 + // a subclass from creating these strings in an "unsafe" way (with respect to fastCopyFrom()). 1.249 + dstCount = srcCount; 1.250 + dstArray = newUnicodeStringArray(srcCount); 1.251 + if(dstArray != NULL) { 1.252 + int32_t i; 1.253 + for(i=0; i<srcCount; ++i) { 1.254 + dstArray[i].fastCopyFrom(srcArray[i]); 1.255 + } 1.256 + } 1.257 +} 1.258 + 1.259 +/** 1.260 + * Create a copy, in fZoneStrings, of the given zone strings array. The 1.261 + * member variables fZoneStringsRowCount and fZoneStringsColCount should 1.262 + * be set already by the caller. 1.263 + */ 1.264 +void 1.265 +DateFormatSymbols::createZoneStrings(const UnicodeString *const * otherStrings) 1.266 +{ 1.267 + int32_t row, col; 1.268 + UBool failed = FALSE; 1.269 + 1.270 + fZoneStrings = (UnicodeString **)uprv_malloc(fZoneStringsRowCount * sizeof(UnicodeString *)); 1.271 + if (fZoneStrings != NULL) { 1.272 + for (row=0; row<fZoneStringsRowCount; ++row) 1.273 + { 1.274 + fZoneStrings[row] = newUnicodeStringArray(fZoneStringsColCount); 1.275 + if (fZoneStrings[row] == NULL) { 1.276 + failed = TRUE; 1.277 + break; 1.278 + } 1.279 + for (col=0; col<fZoneStringsColCount; ++col) { 1.280 + // fastCopyFrom() - see assignArray comments 1.281 + fZoneStrings[row][col].fastCopyFrom(otherStrings[row][col]); 1.282 + } 1.283 + } 1.284 + } 1.285 + // If memory allocation failed, roll back and delete fZoneStrings 1.286 + if (failed) { 1.287 + for (int i = row; i >= 0; i--) { 1.288 + delete[] fZoneStrings[i]; 1.289 + } 1.290 + uprv_free(fZoneStrings); 1.291 + fZoneStrings = NULL; 1.292 + } 1.293 +} 1.294 + 1.295 +/** 1.296 + * Copy all of the other's data to this. 1.297 + */ 1.298 +void 1.299 +DateFormatSymbols::copyData(const DateFormatSymbols& other) { 1.300 + assignArray(fEras, fErasCount, other.fEras, other.fErasCount); 1.301 + assignArray(fEraNames, fEraNamesCount, other.fEraNames, other.fEraNamesCount); 1.302 + assignArray(fNarrowEras, fNarrowErasCount, other.fNarrowEras, other.fNarrowErasCount); 1.303 + assignArray(fMonths, fMonthsCount, other.fMonths, other.fMonthsCount); 1.304 + assignArray(fShortMonths, fShortMonthsCount, other.fShortMonths, other.fShortMonthsCount); 1.305 + assignArray(fNarrowMonths, fNarrowMonthsCount, other.fNarrowMonths, other.fNarrowMonthsCount); 1.306 + assignArray(fStandaloneMonths, fStandaloneMonthsCount, other.fStandaloneMonths, other.fStandaloneMonthsCount); 1.307 + assignArray(fStandaloneShortMonths, fStandaloneShortMonthsCount, other.fStandaloneShortMonths, other.fStandaloneShortMonthsCount); 1.308 + assignArray(fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, other.fStandaloneNarrowMonths, other.fStandaloneNarrowMonthsCount); 1.309 + assignArray(fWeekdays, fWeekdaysCount, other.fWeekdays, other.fWeekdaysCount); 1.310 + assignArray(fShortWeekdays, fShortWeekdaysCount, other.fShortWeekdays, other.fShortWeekdaysCount); 1.311 + assignArray(fShorterWeekdays, fShorterWeekdaysCount, other.fShorterWeekdays, other.fShorterWeekdaysCount); 1.312 + assignArray(fNarrowWeekdays, fNarrowWeekdaysCount, other.fNarrowWeekdays, other.fNarrowWeekdaysCount); 1.313 + assignArray(fStandaloneWeekdays, fStandaloneWeekdaysCount, other.fStandaloneWeekdays, other.fStandaloneWeekdaysCount); 1.314 + assignArray(fStandaloneShortWeekdays, fStandaloneShortWeekdaysCount, other.fStandaloneShortWeekdays, other.fStandaloneShortWeekdaysCount); 1.315 + assignArray(fStandaloneShorterWeekdays, fStandaloneShorterWeekdaysCount, other.fStandaloneShorterWeekdays, other.fStandaloneShorterWeekdaysCount); 1.316 + assignArray(fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount, other.fStandaloneNarrowWeekdays, other.fStandaloneNarrowWeekdaysCount); 1.317 + assignArray(fAmPms, fAmPmsCount, other.fAmPms, other.fAmPmsCount); 1.318 + assignArray(fQuarters, fQuartersCount, other.fQuarters, other.fQuartersCount); 1.319 + assignArray(fShortQuarters, fShortQuartersCount, other.fShortQuarters, other.fShortQuartersCount); 1.320 + assignArray(fStandaloneQuarters, fStandaloneQuartersCount, other.fStandaloneQuarters, other.fStandaloneQuartersCount); 1.321 + assignArray(fStandaloneShortQuarters, fStandaloneShortQuartersCount, other.fStandaloneShortQuarters, other.fStandaloneShortQuartersCount); 1.322 + if (other.fLeapMonthPatterns != NULL) { 1.323 + assignArray(fLeapMonthPatterns, fLeapMonthPatternsCount, other.fLeapMonthPatterns, other.fLeapMonthPatternsCount); 1.324 + } else { 1.325 + fLeapMonthPatterns = NULL; 1.326 + fLeapMonthPatternsCount = 0; 1.327 + } 1.328 + if (other.fShortYearNames != NULL) { 1.329 + assignArray(fShortYearNames, fShortYearNamesCount, other.fShortYearNames, other.fShortYearNamesCount); 1.330 + } else { 1.331 + fShortYearNames = NULL; 1.332 + fShortYearNamesCount = 0; 1.333 + } 1.334 + 1.335 + if (other.fZoneStrings != NULL) { 1.336 + fZoneStringsColCount = other.fZoneStringsColCount; 1.337 + fZoneStringsRowCount = other.fZoneStringsRowCount; 1.338 + createZoneStrings((const UnicodeString**)other.fZoneStrings); 1.339 + 1.340 + } else { 1.341 + fZoneStrings = NULL; 1.342 + fZoneStringsColCount = 0; 1.343 + fZoneStringsRowCount = 0; 1.344 + } 1.345 + fZSFLocale = other.fZSFLocale; 1.346 + // Other zone strings data is created on demand 1.347 + fLocaleZoneStrings = NULL; 1.348 + 1.349 + // fastCopyFrom() - see assignArray comments 1.350 + fLocalPatternChars.fastCopyFrom(other.fLocalPatternChars); 1.351 + 1.352 + uprv_memcpy(fCapitalization, other.fCapitalization, sizeof(fCapitalization)); 1.353 +} 1.354 + 1.355 +/** 1.356 + * Assignment operator. 1.357 + */ 1.358 +DateFormatSymbols& DateFormatSymbols::operator=(const DateFormatSymbols& other) 1.359 +{ 1.360 + dispose(); 1.361 + copyData(other); 1.362 + 1.363 + return *this; 1.364 +} 1.365 + 1.366 +DateFormatSymbols::~DateFormatSymbols() 1.367 +{ 1.368 + dispose(); 1.369 +} 1.370 + 1.371 +void DateFormatSymbols::dispose() 1.372 +{ 1.373 + if (fEras) delete[] fEras; 1.374 + if (fEraNames) delete[] fEraNames; 1.375 + if (fNarrowEras) delete[] fNarrowEras; 1.376 + if (fMonths) delete[] fMonths; 1.377 + if (fShortMonths) delete[] fShortMonths; 1.378 + if (fNarrowMonths) delete[] fNarrowMonths; 1.379 + if (fStandaloneMonths) delete[] fStandaloneMonths; 1.380 + if (fStandaloneShortMonths) delete[] fStandaloneShortMonths; 1.381 + if (fStandaloneNarrowMonths) delete[] fStandaloneNarrowMonths; 1.382 + if (fWeekdays) delete[] fWeekdays; 1.383 + if (fShortWeekdays) delete[] fShortWeekdays; 1.384 + if (fShorterWeekdays) delete[] fShorterWeekdays; 1.385 + if (fNarrowWeekdays) delete[] fNarrowWeekdays; 1.386 + if (fStandaloneWeekdays) delete[] fStandaloneWeekdays; 1.387 + if (fStandaloneShortWeekdays) delete[] fStandaloneShortWeekdays; 1.388 + if (fStandaloneShorterWeekdays) delete[] fStandaloneShorterWeekdays; 1.389 + if (fStandaloneNarrowWeekdays) delete[] fStandaloneNarrowWeekdays; 1.390 + if (fAmPms) delete[] fAmPms; 1.391 + if (fQuarters) delete[] fQuarters; 1.392 + if (fShortQuarters) delete[] fShortQuarters; 1.393 + if (fStandaloneQuarters) delete[] fStandaloneQuarters; 1.394 + if (fStandaloneShortQuarters) delete[] fStandaloneShortQuarters; 1.395 + if (fLeapMonthPatterns) delete[] fLeapMonthPatterns; 1.396 + if (fShortYearNames) delete[] fShortYearNames; 1.397 + 1.398 + disposeZoneStrings(); 1.399 +} 1.400 + 1.401 +void DateFormatSymbols::disposeZoneStrings() 1.402 +{ 1.403 + if (fZoneStrings) { 1.404 + for (int32_t row = 0; row < fZoneStringsRowCount; ++row) { 1.405 + delete[] fZoneStrings[row]; 1.406 + } 1.407 + uprv_free(fZoneStrings); 1.408 + } 1.409 + if (fLocaleZoneStrings) { 1.410 + for (int32_t row = 0; row < fZoneStringsRowCount; ++row) { 1.411 + delete[] fLocaleZoneStrings[row]; 1.412 + } 1.413 + uprv_free(fLocaleZoneStrings); 1.414 + } 1.415 + 1.416 + fZoneStrings = NULL; 1.417 + fLocaleZoneStrings = NULL; 1.418 + fZoneStringsRowCount = 0; 1.419 + fZoneStringsColCount = 0; 1.420 +} 1.421 + 1.422 +UBool 1.423 +DateFormatSymbols::arrayCompare(const UnicodeString* array1, 1.424 + const UnicodeString* array2, 1.425 + int32_t count) 1.426 +{ 1.427 + if (array1 == array2) return TRUE; 1.428 + while (count>0) 1.429 + { 1.430 + --count; 1.431 + if (array1[count] != array2[count]) return FALSE; 1.432 + } 1.433 + return TRUE; 1.434 +} 1.435 + 1.436 +UBool 1.437 +DateFormatSymbols::operator==(const DateFormatSymbols& other) const 1.438 +{ 1.439 + // First do cheap comparisons 1.440 + if (this == &other) { 1.441 + return TRUE; 1.442 + } 1.443 + if (fErasCount == other.fErasCount && 1.444 + fEraNamesCount == other.fEraNamesCount && 1.445 + fNarrowErasCount == other.fNarrowErasCount && 1.446 + fMonthsCount == other.fMonthsCount && 1.447 + fShortMonthsCount == other.fShortMonthsCount && 1.448 + fNarrowMonthsCount == other.fNarrowMonthsCount && 1.449 + fStandaloneMonthsCount == other.fStandaloneMonthsCount && 1.450 + fStandaloneShortMonthsCount == other.fStandaloneShortMonthsCount && 1.451 + fStandaloneNarrowMonthsCount == other.fStandaloneNarrowMonthsCount && 1.452 + fWeekdaysCount == other.fWeekdaysCount && 1.453 + fShortWeekdaysCount == other.fShortWeekdaysCount && 1.454 + fShorterWeekdaysCount == other.fShorterWeekdaysCount && 1.455 + fNarrowWeekdaysCount == other.fNarrowWeekdaysCount && 1.456 + fStandaloneWeekdaysCount == other.fStandaloneWeekdaysCount && 1.457 + fStandaloneShortWeekdaysCount == other.fStandaloneShortWeekdaysCount && 1.458 + fStandaloneShorterWeekdaysCount == other.fStandaloneShorterWeekdaysCount && 1.459 + fStandaloneNarrowWeekdaysCount == other.fStandaloneNarrowWeekdaysCount && 1.460 + fAmPmsCount == other.fAmPmsCount && 1.461 + fQuartersCount == other.fQuartersCount && 1.462 + fShortQuartersCount == other.fShortQuartersCount && 1.463 + fStandaloneQuartersCount == other.fStandaloneQuartersCount && 1.464 + fStandaloneShortQuartersCount == other.fStandaloneShortQuartersCount && 1.465 + fLeapMonthPatternsCount == other.fLeapMonthPatternsCount && 1.466 + fShortYearNamesCount == other.fShortYearNamesCount && 1.467 + (uprv_memcmp(fCapitalization, other.fCapitalization, sizeof(fCapitalization))==0)) 1.468 + { 1.469 + // Now compare the arrays themselves 1.470 + if (arrayCompare(fEras, other.fEras, fErasCount) && 1.471 + arrayCompare(fEraNames, other.fEraNames, fEraNamesCount) && 1.472 + arrayCompare(fNarrowEras, other.fNarrowEras, fNarrowErasCount) && 1.473 + arrayCompare(fMonths, other.fMonths, fMonthsCount) && 1.474 + arrayCompare(fShortMonths, other.fShortMonths, fShortMonthsCount) && 1.475 + arrayCompare(fNarrowMonths, other.fNarrowMonths, fNarrowMonthsCount) && 1.476 + arrayCompare(fStandaloneMonths, other.fStandaloneMonths, fStandaloneMonthsCount) && 1.477 + arrayCompare(fStandaloneShortMonths, other.fStandaloneShortMonths, fStandaloneShortMonthsCount) && 1.478 + arrayCompare(fStandaloneNarrowMonths, other.fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount) && 1.479 + arrayCompare(fWeekdays, other.fWeekdays, fWeekdaysCount) && 1.480 + arrayCompare(fShortWeekdays, other.fShortWeekdays, fShortWeekdaysCount) && 1.481 + arrayCompare(fShorterWeekdays, other.fShorterWeekdays, fShorterWeekdaysCount) && 1.482 + arrayCompare(fNarrowWeekdays, other.fNarrowWeekdays, fNarrowWeekdaysCount) && 1.483 + arrayCompare(fStandaloneWeekdays, other.fStandaloneWeekdays, fStandaloneWeekdaysCount) && 1.484 + arrayCompare(fStandaloneShortWeekdays, other.fStandaloneShortWeekdays, fStandaloneShortWeekdaysCount) && 1.485 + arrayCompare(fStandaloneShorterWeekdays, other.fStandaloneShorterWeekdays, fStandaloneShorterWeekdaysCount) && 1.486 + arrayCompare(fStandaloneNarrowWeekdays, other.fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount) && 1.487 + arrayCompare(fAmPms, other.fAmPms, fAmPmsCount) && 1.488 + arrayCompare(fQuarters, other.fQuarters, fQuartersCount) && 1.489 + arrayCompare(fShortQuarters, other.fShortQuarters, fShortQuartersCount) && 1.490 + arrayCompare(fStandaloneQuarters, other.fStandaloneQuarters, fStandaloneQuartersCount) && 1.491 + arrayCompare(fStandaloneShortQuarters, other.fStandaloneShortQuarters, fStandaloneShortQuartersCount) && 1.492 + arrayCompare(fLeapMonthPatterns, other.fLeapMonthPatterns, fLeapMonthPatternsCount) && 1.493 + arrayCompare(fShortYearNames, other.fShortYearNames, fShortYearNamesCount)) 1.494 + { 1.495 + // Compare the contents of fZoneStrings 1.496 + if (fZoneStrings == NULL && other.fZoneStrings == NULL) { 1.497 + if (fZSFLocale == other.fZSFLocale) { 1.498 + return TRUE; 1.499 + } 1.500 + } else if (fZoneStrings != NULL && other.fZoneStrings != NULL) { 1.501 + if (fZoneStringsRowCount == other.fZoneStringsRowCount 1.502 + && fZoneStringsColCount == other.fZoneStringsColCount) { 1.503 + UBool cmpres = TRUE; 1.504 + for (int32_t i = 0; (i < fZoneStringsRowCount) && cmpres; i++) { 1.505 + cmpres = arrayCompare(fZoneStrings[i], other.fZoneStrings[i], fZoneStringsColCount); 1.506 + } 1.507 + return cmpres; 1.508 + } 1.509 + } 1.510 + return FALSE; 1.511 + } 1.512 + } 1.513 + return FALSE; 1.514 +} 1.515 + 1.516 +//------------------------------------------------------ 1.517 + 1.518 +const UnicodeString* 1.519 +DateFormatSymbols::getEras(int32_t &count) const 1.520 +{ 1.521 + count = fErasCount; 1.522 + return fEras; 1.523 +} 1.524 + 1.525 +const UnicodeString* 1.526 +DateFormatSymbols::getEraNames(int32_t &count) const 1.527 +{ 1.528 + count = fEraNamesCount; 1.529 + return fEraNames; 1.530 +} 1.531 + 1.532 +const UnicodeString* 1.533 +DateFormatSymbols::getNarrowEras(int32_t &count) const 1.534 +{ 1.535 + count = fNarrowErasCount; 1.536 + return fNarrowEras; 1.537 +} 1.538 + 1.539 +const UnicodeString* 1.540 +DateFormatSymbols::getMonths(int32_t &count) const 1.541 +{ 1.542 + count = fMonthsCount; 1.543 + return fMonths; 1.544 +} 1.545 + 1.546 +const UnicodeString* 1.547 +DateFormatSymbols::getShortMonths(int32_t &count) const 1.548 +{ 1.549 + count = fShortMonthsCount; 1.550 + return fShortMonths; 1.551 +} 1.552 + 1.553 +const UnicodeString* 1.554 +DateFormatSymbols::getMonths(int32_t &count, DtContextType context, DtWidthType width ) const 1.555 +{ 1.556 + UnicodeString *returnValue = NULL; 1.557 + 1.558 + switch (context) { 1.559 + case FORMAT : 1.560 + switch(width) { 1.561 + case WIDE : 1.562 + count = fMonthsCount; 1.563 + returnValue = fMonths; 1.564 + break; 1.565 + case ABBREVIATED : 1.566 + case SHORT : // no month data for this, defaults to ABBREVIATED 1.567 + count = fShortMonthsCount; 1.568 + returnValue = fShortMonths; 1.569 + break; 1.570 + case NARROW : 1.571 + count = fNarrowMonthsCount; 1.572 + returnValue = fNarrowMonths; 1.573 + break; 1.574 + case DT_WIDTH_COUNT : 1.575 + break; 1.576 + } 1.577 + break; 1.578 + case STANDALONE : 1.579 + switch(width) { 1.580 + case WIDE : 1.581 + count = fStandaloneMonthsCount; 1.582 + returnValue = fStandaloneMonths; 1.583 + break; 1.584 + case ABBREVIATED : 1.585 + case SHORT : // no month data for this, defaults to ABBREVIATED 1.586 + count = fStandaloneShortMonthsCount; 1.587 + returnValue = fStandaloneShortMonths; 1.588 + break; 1.589 + case NARROW : 1.590 + count = fStandaloneNarrowMonthsCount; 1.591 + returnValue = fStandaloneNarrowMonths; 1.592 + break; 1.593 + case DT_WIDTH_COUNT : 1.594 + break; 1.595 + } 1.596 + break; 1.597 + case DT_CONTEXT_COUNT : 1.598 + break; 1.599 + } 1.600 + return returnValue; 1.601 +} 1.602 + 1.603 +const UnicodeString* 1.604 +DateFormatSymbols::getWeekdays(int32_t &count) const 1.605 +{ 1.606 + count = fWeekdaysCount; 1.607 + return fWeekdays; 1.608 +} 1.609 + 1.610 +const UnicodeString* 1.611 +DateFormatSymbols::getShortWeekdays(int32_t &count) const 1.612 +{ 1.613 + count = fShortWeekdaysCount; 1.614 + return fShortWeekdays; 1.615 +} 1.616 + 1.617 +const UnicodeString* 1.618 +DateFormatSymbols::getWeekdays(int32_t &count, DtContextType context, DtWidthType width) const 1.619 +{ 1.620 + UnicodeString *returnValue = NULL; 1.621 + switch (context) { 1.622 + case FORMAT : 1.623 + switch(width) { 1.624 + case WIDE : 1.625 + count = fWeekdaysCount; 1.626 + returnValue = fWeekdays; 1.627 + break; 1.628 + case ABBREVIATED : 1.629 + count = fShortWeekdaysCount; 1.630 + returnValue = fShortWeekdays; 1.631 + break; 1.632 + case SHORT : 1.633 + count = fShorterWeekdaysCount; 1.634 + returnValue = fShorterWeekdays; 1.635 + break; 1.636 + case NARROW : 1.637 + count = fNarrowWeekdaysCount; 1.638 + returnValue = fNarrowWeekdays; 1.639 + break; 1.640 + case DT_WIDTH_COUNT : 1.641 + break; 1.642 + } 1.643 + break; 1.644 + case STANDALONE : 1.645 + switch(width) { 1.646 + case WIDE : 1.647 + count = fStandaloneWeekdaysCount; 1.648 + returnValue = fStandaloneWeekdays; 1.649 + break; 1.650 + case ABBREVIATED : 1.651 + count = fStandaloneShortWeekdaysCount; 1.652 + returnValue = fStandaloneShortWeekdays; 1.653 + break; 1.654 + case SHORT : 1.655 + count = fStandaloneShorterWeekdaysCount; 1.656 + returnValue = fStandaloneShorterWeekdays; 1.657 + break; 1.658 + case NARROW : 1.659 + count = fStandaloneNarrowWeekdaysCount; 1.660 + returnValue = fStandaloneNarrowWeekdays; 1.661 + break; 1.662 + case DT_WIDTH_COUNT : 1.663 + break; 1.664 + } 1.665 + break; 1.666 + case DT_CONTEXT_COUNT : 1.667 + break; 1.668 + } 1.669 + return returnValue; 1.670 +} 1.671 + 1.672 +const UnicodeString* 1.673 +DateFormatSymbols::getQuarters(int32_t &count, DtContextType context, DtWidthType width ) const 1.674 +{ 1.675 + UnicodeString *returnValue = NULL; 1.676 + 1.677 + switch (context) { 1.678 + case FORMAT : 1.679 + switch(width) { 1.680 + case WIDE : 1.681 + count = fQuartersCount; 1.682 + returnValue = fQuarters; 1.683 + break; 1.684 + case ABBREVIATED : 1.685 + case SHORT : // no quarter data for this, defaults to ABBREVIATED 1.686 + count = fShortQuartersCount; 1.687 + returnValue = fShortQuarters; 1.688 + break; 1.689 + case NARROW : 1.690 + count = 0; 1.691 + returnValue = NULL; 1.692 + break; 1.693 + case DT_WIDTH_COUNT : 1.694 + break; 1.695 + } 1.696 + break; 1.697 + case STANDALONE : 1.698 + switch(width) { 1.699 + case WIDE : 1.700 + count = fStandaloneQuartersCount; 1.701 + returnValue = fStandaloneQuarters; 1.702 + break; 1.703 + case ABBREVIATED : 1.704 + case SHORT : // no quarter data for this, defaults to ABBREVIATED 1.705 + count = fStandaloneShortQuartersCount; 1.706 + returnValue = fStandaloneShortQuarters; 1.707 + break; 1.708 + case NARROW : 1.709 + count = 0; 1.710 + returnValue = NULL; 1.711 + break; 1.712 + case DT_WIDTH_COUNT : 1.713 + break; 1.714 + } 1.715 + break; 1.716 + case DT_CONTEXT_COUNT : 1.717 + break; 1.718 + } 1.719 + return returnValue; 1.720 +} 1.721 + 1.722 +const UnicodeString* 1.723 +DateFormatSymbols::getAmPmStrings(int32_t &count) const 1.724 +{ 1.725 + count = fAmPmsCount; 1.726 + return fAmPms; 1.727 +} 1.728 + 1.729 +const UnicodeString* 1.730 +DateFormatSymbols::getLeapMonthPatterns(int32_t &count) const 1.731 +{ 1.732 + count = fLeapMonthPatternsCount; 1.733 + return fLeapMonthPatterns; 1.734 +} 1.735 + 1.736 +//------------------------------------------------------ 1.737 + 1.738 +void 1.739 +DateFormatSymbols::setEras(const UnicodeString* erasArray, int32_t count) 1.740 +{ 1.741 + // delete the old list if we own it 1.742 + if (fEras) 1.743 + delete[] fEras; 1.744 + 1.745 + // we always own the new list, which we create here (we duplicate rather 1.746 + // than adopting the list passed in) 1.747 + fEras = newUnicodeStringArray(count); 1.748 + uprv_arrayCopy(erasArray,fEras, count); 1.749 + fErasCount = count; 1.750 +} 1.751 + 1.752 +void 1.753 +DateFormatSymbols::setEraNames(const UnicodeString* eraNamesArray, int32_t count) 1.754 +{ 1.755 + // delete the old list if we own it 1.756 + if (fEraNames) 1.757 + delete[] fEraNames; 1.758 + 1.759 + // we always own the new list, which we create here (we duplicate rather 1.760 + // than adopting the list passed in) 1.761 + fEraNames = newUnicodeStringArray(count); 1.762 + uprv_arrayCopy(eraNamesArray,fEraNames, count); 1.763 + fEraNamesCount = count; 1.764 +} 1.765 + 1.766 +void 1.767 +DateFormatSymbols::setNarrowEras(const UnicodeString* narrowErasArray, int32_t count) 1.768 +{ 1.769 + // delete the old list if we own it 1.770 + if (fNarrowEras) 1.771 + delete[] fNarrowEras; 1.772 + 1.773 + // we always own the new list, which we create here (we duplicate rather 1.774 + // than adopting the list passed in) 1.775 + fNarrowEras = newUnicodeStringArray(count); 1.776 + uprv_arrayCopy(narrowErasArray,fNarrowEras, count); 1.777 + fNarrowErasCount = count; 1.778 +} 1.779 + 1.780 +void 1.781 +DateFormatSymbols::setMonths(const UnicodeString* monthsArray, int32_t count) 1.782 +{ 1.783 + // delete the old list if we own it 1.784 + if (fMonths) 1.785 + delete[] fMonths; 1.786 + 1.787 + // we always own the new list, which we create here (we duplicate rather 1.788 + // than adopting the list passed in) 1.789 + fMonths = newUnicodeStringArray(count); 1.790 + uprv_arrayCopy( monthsArray,fMonths,count); 1.791 + fMonthsCount = count; 1.792 +} 1.793 + 1.794 +void 1.795 +DateFormatSymbols::setShortMonths(const UnicodeString* shortMonthsArray, int32_t count) 1.796 +{ 1.797 + // delete the old list if we own it 1.798 + if (fShortMonths) 1.799 + delete[] fShortMonths; 1.800 + 1.801 + // we always own the new list, which we create here (we duplicate rather 1.802 + // than adopting the list passed in) 1.803 + fShortMonths = newUnicodeStringArray(count); 1.804 + uprv_arrayCopy(shortMonthsArray,fShortMonths, count); 1.805 + fShortMonthsCount = count; 1.806 +} 1.807 + 1.808 +void 1.809 +DateFormatSymbols::setMonths(const UnicodeString* monthsArray, int32_t count, DtContextType context, DtWidthType width) 1.810 +{ 1.811 + // delete the old list if we own it 1.812 + // we always own the new list, which we create here (we duplicate rather 1.813 + // than adopting the list passed in) 1.814 + 1.815 + switch (context) { 1.816 + case FORMAT : 1.817 + switch (width) { 1.818 + case WIDE : 1.819 + if (fMonths) 1.820 + delete[] fMonths; 1.821 + fMonths = newUnicodeStringArray(count); 1.822 + uprv_arrayCopy( monthsArray,fMonths,count); 1.823 + fMonthsCount = count; 1.824 + break; 1.825 + case ABBREVIATED : 1.826 + if (fShortMonths) 1.827 + delete[] fShortMonths; 1.828 + fShortMonths = newUnicodeStringArray(count); 1.829 + uprv_arrayCopy( monthsArray,fShortMonths,count); 1.830 + fShortMonthsCount = count; 1.831 + break; 1.832 + case NARROW : 1.833 + if (fNarrowMonths) 1.834 + delete[] fNarrowMonths; 1.835 + fNarrowMonths = newUnicodeStringArray(count); 1.836 + uprv_arrayCopy( monthsArray,fNarrowMonths,count); 1.837 + fNarrowMonthsCount = count; 1.838 + break; 1.839 + default : 1.840 + break; 1.841 + } 1.842 + break; 1.843 + case STANDALONE : 1.844 + switch (width) { 1.845 + case WIDE : 1.846 + if (fStandaloneMonths) 1.847 + delete[] fStandaloneMonths; 1.848 + fStandaloneMonths = newUnicodeStringArray(count); 1.849 + uprv_arrayCopy( monthsArray,fStandaloneMonths,count); 1.850 + fStandaloneMonthsCount = count; 1.851 + break; 1.852 + case ABBREVIATED : 1.853 + if (fStandaloneShortMonths) 1.854 + delete[] fStandaloneShortMonths; 1.855 + fStandaloneShortMonths = newUnicodeStringArray(count); 1.856 + uprv_arrayCopy( monthsArray,fStandaloneShortMonths,count); 1.857 + fStandaloneShortMonthsCount = count; 1.858 + break; 1.859 + case NARROW : 1.860 + if (fStandaloneNarrowMonths) 1.861 + delete[] fStandaloneNarrowMonths; 1.862 + fStandaloneNarrowMonths = newUnicodeStringArray(count); 1.863 + uprv_arrayCopy( monthsArray,fStandaloneNarrowMonths,count); 1.864 + fStandaloneNarrowMonthsCount = count; 1.865 + break; 1.866 + default : 1.867 + break; 1.868 + } 1.869 + break; 1.870 + case DT_CONTEXT_COUNT : 1.871 + break; 1.872 + } 1.873 +} 1.874 + 1.875 +void DateFormatSymbols::setWeekdays(const UnicodeString* weekdaysArray, int32_t count) 1.876 +{ 1.877 + // delete the old list if we own it 1.878 + if (fWeekdays) 1.879 + delete[] fWeekdays; 1.880 + 1.881 + // we always own the new list, which we create here (we duplicate rather 1.882 + // than adopting the list passed in) 1.883 + fWeekdays = newUnicodeStringArray(count); 1.884 + uprv_arrayCopy(weekdaysArray,fWeekdays,count); 1.885 + fWeekdaysCount = count; 1.886 +} 1.887 + 1.888 +void 1.889 +DateFormatSymbols::setShortWeekdays(const UnicodeString* shortWeekdaysArray, int32_t count) 1.890 +{ 1.891 + // delete the old list if we own it 1.892 + if (fShortWeekdays) 1.893 + delete[] fShortWeekdays; 1.894 + 1.895 + // we always own the new list, which we create here (we duplicate rather 1.896 + // than adopting the list passed in) 1.897 + fShortWeekdays = newUnicodeStringArray(count); 1.898 + uprv_arrayCopy(shortWeekdaysArray, fShortWeekdays, count); 1.899 + fShortWeekdaysCount = count; 1.900 +} 1.901 + 1.902 +void 1.903 +DateFormatSymbols::setWeekdays(const UnicodeString* weekdaysArray, int32_t count, DtContextType context, DtWidthType width) 1.904 +{ 1.905 + // delete the old list if we own it 1.906 + // we always own the new list, which we create here (we duplicate rather 1.907 + // than adopting the list passed in) 1.908 + 1.909 + switch (context) { 1.910 + case FORMAT : 1.911 + switch (width) { 1.912 + case WIDE : 1.913 + if (fWeekdays) 1.914 + delete[] fWeekdays; 1.915 + fWeekdays = newUnicodeStringArray(count); 1.916 + uprv_arrayCopy(weekdaysArray, fWeekdays, count); 1.917 + fWeekdaysCount = count; 1.918 + break; 1.919 + case ABBREVIATED : 1.920 + if (fShortWeekdays) 1.921 + delete[] fShortWeekdays; 1.922 + fShortWeekdays = newUnicodeStringArray(count); 1.923 + uprv_arrayCopy(weekdaysArray, fShortWeekdays, count); 1.924 + fShortWeekdaysCount = count; 1.925 + break; 1.926 + case SHORT : 1.927 + if (fShorterWeekdays) 1.928 + delete[] fShorterWeekdays; 1.929 + fShorterWeekdays = newUnicodeStringArray(count); 1.930 + uprv_arrayCopy(weekdaysArray, fShorterWeekdays, count); 1.931 + fShorterWeekdaysCount = count; 1.932 + break; 1.933 + case NARROW : 1.934 + if (fNarrowWeekdays) 1.935 + delete[] fNarrowWeekdays; 1.936 + fNarrowWeekdays = newUnicodeStringArray(count); 1.937 + uprv_arrayCopy(weekdaysArray, fNarrowWeekdays, count); 1.938 + fNarrowWeekdaysCount = count; 1.939 + break; 1.940 + case DT_WIDTH_COUNT : 1.941 + break; 1.942 + } 1.943 + break; 1.944 + case STANDALONE : 1.945 + switch (width) { 1.946 + case WIDE : 1.947 + if (fStandaloneWeekdays) 1.948 + delete[] fStandaloneWeekdays; 1.949 + fStandaloneWeekdays = newUnicodeStringArray(count); 1.950 + uprv_arrayCopy(weekdaysArray, fStandaloneWeekdays, count); 1.951 + fStandaloneWeekdaysCount = count; 1.952 + break; 1.953 + case ABBREVIATED : 1.954 + if (fStandaloneShortWeekdays) 1.955 + delete[] fStandaloneShortWeekdays; 1.956 + fStandaloneShortWeekdays = newUnicodeStringArray(count); 1.957 + uprv_arrayCopy(weekdaysArray, fStandaloneShortWeekdays, count); 1.958 + fStandaloneShortWeekdaysCount = count; 1.959 + break; 1.960 + case SHORT : 1.961 + if (fStandaloneShorterWeekdays) 1.962 + delete[] fStandaloneShorterWeekdays; 1.963 + fStandaloneShorterWeekdays = newUnicodeStringArray(count); 1.964 + uprv_arrayCopy(weekdaysArray, fStandaloneShorterWeekdays, count); 1.965 + fStandaloneShorterWeekdaysCount = count; 1.966 + break; 1.967 + case NARROW : 1.968 + if (fStandaloneNarrowWeekdays) 1.969 + delete[] fStandaloneNarrowWeekdays; 1.970 + fStandaloneNarrowWeekdays = newUnicodeStringArray(count); 1.971 + uprv_arrayCopy(weekdaysArray, fStandaloneNarrowWeekdays, count); 1.972 + fStandaloneNarrowWeekdaysCount = count; 1.973 + break; 1.974 + case DT_WIDTH_COUNT : 1.975 + break; 1.976 + } 1.977 + break; 1.978 + case DT_CONTEXT_COUNT : 1.979 + break; 1.980 + } 1.981 +} 1.982 + 1.983 +void 1.984 +DateFormatSymbols::setQuarters(const UnicodeString* quartersArray, int32_t count, DtContextType context, DtWidthType width) 1.985 +{ 1.986 + // delete the old list if we own it 1.987 + // we always own the new list, which we create here (we duplicate rather 1.988 + // than adopting the list passed in) 1.989 + 1.990 + switch (context) { 1.991 + case FORMAT : 1.992 + switch (width) { 1.993 + case WIDE : 1.994 + if (fQuarters) 1.995 + delete[] fQuarters; 1.996 + fQuarters = newUnicodeStringArray(count); 1.997 + uprv_arrayCopy( quartersArray,fQuarters,count); 1.998 + fQuartersCount = count; 1.999 + break; 1.1000 + case ABBREVIATED : 1.1001 + if (fShortQuarters) 1.1002 + delete[] fShortQuarters; 1.1003 + fShortQuarters = newUnicodeStringArray(count); 1.1004 + uprv_arrayCopy( quartersArray,fShortQuarters,count); 1.1005 + fShortQuartersCount = count; 1.1006 + break; 1.1007 + case NARROW : 1.1008 + /* 1.1009 + if (fNarrowQuarters) 1.1010 + delete[] fNarrowQuarters; 1.1011 + fNarrowQuarters = newUnicodeStringArray(count); 1.1012 + uprv_arrayCopy( quartersArray,fNarrowQuarters,count); 1.1013 + fNarrowQuartersCount = count; 1.1014 + */ 1.1015 + break; 1.1016 + default : 1.1017 + break; 1.1018 + } 1.1019 + break; 1.1020 + case STANDALONE : 1.1021 + switch (width) { 1.1022 + case WIDE : 1.1023 + if (fStandaloneQuarters) 1.1024 + delete[] fStandaloneQuarters; 1.1025 + fStandaloneQuarters = newUnicodeStringArray(count); 1.1026 + uprv_arrayCopy( quartersArray,fStandaloneQuarters,count); 1.1027 + fStandaloneQuartersCount = count; 1.1028 + break; 1.1029 + case ABBREVIATED : 1.1030 + if (fStandaloneShortQuarters) 1.1031 + delete[] fStandaloneShortQuarters; 1.1032 + fStandaloneShortQuarters = newUnicodeStringArray(count); 1.1033 + uprv_arrayCopy( quartersArray,fStandaloneShortQuarters,count); 1.1034 + fStandaloneShortQuartersCount = count; 1.1035 + break; 1.1036 + case NARROW : 1.1037 + /* 1.1038 + if (fStandaloneNarrowQuarters) 1.1039 + delete[] fStandaloneNarrowQuarters; 1.1040 + fStandaloneNarrowQuarters = newUnicodeStringArray(count); 1.1041 + uprv_arrayCopy( quartersArray,fStandaloneNarrowQuarters,count); 1.1042 + fStandaloneNarrowQuartersCount = count; 1.1043 + */ 1.1044 + break; 1.1045 + default : 1.1046 + break; 1.1047 + } 1.1048 + break; 1.1049 + case DT_CONTEXT_COUNT : 1.1050 + break; 1.1051 + } 1.1052 +} 1.1053 + 1.1054 +void 1.1055 +DateFormatSymbols::setAmPmStrings(const UnicodeString* amPmsArray, int32_t count) 1.1056 +{ 1.1057 + // delete the old list if we own it 1.1058 + if (fAmPms) delete[] fAmPms; 1.1059 + 1.1060 + // we always own the new list, which we create here (we duplicate rather 1.1061 + // than adopting the list passed in) 1.1062 + fAmPms = newUnicodeStringArray(count); 1.1063 + uprv_arrayCopy(amPmsArray,fAmPms,count); 1.1064 + fAmPmsCount = count; 1.1065 +} 1.1066 + 1.1067 +const UnicodeString** 1.1068 +DateFormatSymbols::getZoneStrings(int32_t& rowCount, int32_t& columnCount) const 1.1069 +{ 1.1070 + const UnicodeString **result = NULL; 1.1071 + 1.1072 + umtx_lock(&LOCK); 1.1073 + if (fZoneStrings == NULL) { 1.1074 + if (fLocaleZoneStrings == NULL) { 1.1075 + ((DateFormatSymbols*)this)->initZoneStringsArray(); 1.1076 + } 1.1077 + result = (const UnicodeString**)fLocaleZoneStrings; 1.1078 + } else { 1.1079 + result = (const UnicodeString**)fZoneStrings; 1.1080 + } 1.1081 + rowCount = fZoneStringsRowCount; 1.1082 + columnCount = fZoneStringsColCount; 1.1083 + umtx_unlock(&LOCK); 1.1084 + 1.1085 + return result; 1.1086 +} 1.1087 + 1.1088 +// For now, we include all zones 1.1089 +#define ZONE_SET UCAL_ZONE_TYPE_ANY 1.1090 + 1.1091 +// This code must be called within a synchronized block 1.1092 +void 1.1093 +DateFormatSymbols::initZoneStringsArray(void) { 1.1094 + if (fZoneStrings != NULL || fLocaleZoneStrings != NULL) { 1.1095 + return; 1.1096 + } 1.1097 + 1.1098 + UErrorCode status = U_ZERO_ERROR; 1.1099 + 1.1100 + StringEnumeration *tzids = NULL; 1.1101 + UnicodeString ** zarray = NULL; 1.1102 + TimeZoneNames *tzNames = NULL; 1.1103 + int32_t rows = 0; 1.1104 + 1.1105 + do { // dummy do-while 1.1106 + 1.1107 + tzids = TimeZone::createTimeZoneIDEnumeration(ZONE_SET, NULL, NULL, status); 1.1108 + rows = tzids->count(status); 1.1109 + if (U_FAILURE(status)) { 1.1110 + break; 1.1111 + } 1.1112 + 1.1113 + // Allocate array 1.1114 + int32_t size = rows * sizeof(UnicodeString*); 1.1115 + zarray = (UnicodeString**)uprv_malloc(size); 1.1116 + if (zarray == NULL) { 1.1117 + status = U_MEMORY_ALLOCATION_ERROR; 1.1118 + break; 1.1119 + } 1.1120 + uprv_memset(zarray, 0, size); 1.1121 + 1.1122 + tzNames = TimeZoneNames::createInstance(fZSFLocale, status); 1.1123 + 1.1124 + const UnicodeString *tzid; 1.1125 + int32_t i = 0; 1.1126 + UDate now = Calendar::getNow(); 1.1127 + UnicodeString tzDispName; 1.1128 + 1.1129 + while ((tzid = tzids->snext(status))) { 1.1130 + if (U_FAILURE(status)) { 1.1131 + break; 1.1132 + } 1.1133 + 1.1134 + zarray[i] = new UnicodeString[5]; 1.1135 + if (zarray[i] == NULL) { 1.1136 + status = U_MEMORY_ALLOCATION_ERROR; 1.1137 + break; 1.1138 + } 1.1139 + 1.1140 + zarray[i][0].setTo(*tzid); 1.1141 + zarray[i][1].setTo(tzNames->getDisplayName(*tzid, UTZNM_LONG_STANDARD, now, tzDispName)); 1.1142 + zarray[i][2].setTo(tzNames->getDisplayName(*tzid, UTZNM_SHORT_STANDARD, now, tzDispName)); 1.1143 + zarray[i][3].setTo(tzNames->getDisplayName(*tzid, UTZNM_LONG_DAYLIGHT, now, tzDispName)); 1.1144 + zarray[i][4].setTo(tzNames->getDisplayName(*tzid, UTZNM_SHORT_DAYLIGHT, now, tzDispName)); 1.1145 + i++; 1.1146 + } 1.1147 + 1.1148 + } while (FALSE); 1.1149 + 1.1150 + if (U_FAILURE(status)) { 1.1151 + if (zarray) { 1.1152 + for (int32_t i = 0; i < rows; i++) { 1.1153 + if (zarray[i]) { 1.1154 + delete[] zarray[i]; 1.1155 + } 1.1156 + } 1.1157 + uprv_free(zarray); 1.1158 + } 1.1159 + } 1.1160 + 1.1161 + if (tzNames) { 1.1162 + delete tzNames; 1.1163 + } 1.1164 + if (tzids) { 1.1165 + delete tzids; 1.1166 + } 1.1167 + 1.1168 + fLocaleZoneStrings = zarray; 1.1169 + fZoneStringsRowCount = rows; 1.1170 + fZoneStringsColCount = 5; 1.1171 +} 1.1172 + 1.1173 +void 1.1174 +DateFormatSymbols::setZoneStrings(const UnicodeString* const *strings, int32_t rowCount, int32_t columnCount) 1.1175 +{ 1.1176 + // since deleting a 2-d array is a pain in the butt, we offload that task to 1.1177 + // a separate function 1.1178 + disposeZoneStrings(); 1.1179 + // we always own the new list, which we create here (we duplicate rather 1.1180 + // than adopting the list passed in) 1.1181 + fZoneStringsRowCount = rowCount; 1.1182 + fZoneStringsColCount = columnCount; 1.1183 + createZoneStrings((const UnicodeString**)strings); 1.1184 +} 1.1185 + 1.1186 +//------------------------------------------------------ 1.1187 + 1.1188 +const UChar * U_EXPORT2 1.1189 +DateFormatSymbols::getPatternUChars(void) 1.1190 +{ 1.1191 + return gPatternChars; 1.1192 +} 1.1193 + 1.1194 +UDateFormatField U_EXPORT2 1.1195 +DateFormatSymbols::getPatternCharIndex(UChar c) { 1.1196 + const UChar *p = u_strchr(gPatternChars, c); 1.1197 + if (p == NULL) { 1.1198 + return UDAT_FIELD_COUNT; 1.1199 + } else { 1.1200 + return static_cast<UDateFormatField>(p - gPatternChars); 1.1201 + } 1.1202 +} 1.1203 + 1.1204 +static const uint32_t kNumericFields = 1.1205 + ((uint32_t)1 << UDAT_YEAR_FIELD) | // y 1.1206 + ((uint32_t)1 << UDAT_MONTH_FIELD) | // M or MM 1.1207 + ((uint32_t)1 << UDAT_DATE_FIELD) | // d 1.1208 + ((uint32_t)1 << UDAT_HOUR_OF_DAY1_FIELD) | // k 1.1209 + ((uint32_t)1 << UDAT_HOUR_OF_DAY0_FIELD) | // H 1.1210 + ((uint32_t)1 << UDAT_MINUTE_FIELD) | // m 1.1211 + ((uint32_t)1 << UDAT_SECOND_FIELD) | // s 1.1212 + ((uint32_t)1 << UDAT_FRACTIONAL_SECOND_FIELD) | // S 1.1213 + ((uint32_t)1 << UDAT_DAY_OF_YEAR_FIELD) | // D 1.1214 + ((uint32_t)1 << UDAT_DAY_OF_WEEK_IN_MONTH_FIELD) | // F 1.1215 + ((uint32_t)1 << UDAT_WEEK_OF_YEAR_FIELD) | // w 1.1216 + ((uint32_t)1 << UDAT_WEEK_OF_MONTH_FIELD) | // W 1.1217 + ((uint32_t)1 << UDAT_HOUR1_FIELD) | // h 1.1218 + ((uint32_t)1 << UDAT_HOUR0_FIELD) | // K 1.1219 + ((uint32_t)1 << UDAT_YEAR_WOY_FIELD) | // Y 1.1220 + ((uint32_t)1 << UDAT_DOW_LOCAL_FIELD) | // e 1.1221 + ((uint32_t)1 << UDAT_EXTENDED_YEAR_FIELD); // u 1.1222 + 1.1223 +UBool U_EXPORT2 1.1224 +DateFormatSymbols::isNumericField(UDateFormatField f, int32_t count) { 1.1225 + return 1.1226 + f != UDAT_FIELD_COUNT && 1.1227 + (kNumericFields & ((uint32_t)1 << f)) != 0 && 1.1228 + (f != UDAT_MONTH_FIELD || count < 3); 1.1229 +} 1.1230 + 1.1231 +UBool U_EXPORT2 1.1232 +DateFormatSymbols::isNumericPatternChar(UChar c, int32_t count) { 1.1233 + return isNumericField(getPatternCharIndex(c), count); 1.1234 +} 1.1235 + 1.1236 +//------------------------------------------------------ 1.1237 + 1.1238 +UnicodeString& 1.1239 +DateFormatSymbols::getLocalPatternChars(UnicodeString& result) const 1.1240 +{ 1.1241 + // fastCopyFrom() - see assignArray comments 1.1242 + return result.fastCopyFrom(fLocalPatternChars); 1.1243 +} 1.1244 + 1.1245 +//------------------------------------------------------ 1.1246 + 1.1247 +void 1.1248 +DateFormatSymbols::setLocalPatternChars(const UnicodeString& newLocalPatternChars) 1.1249 +{ 1.1250 + fLocalPatternChars = newLocalPatternChars; 1.1251 +} 1.1252 + 1.1253 +//------------------------------------------------------ 1.1254 + 1.1255 +static void 1.1256 +initField(UnicodeString **field, int32_t& length, const UResourceBundle *data, UErrorCode &status) { 1.1257 + if (U_SUCCESS(status)) { 1.1258 + int32_t strLen = 0; 1.1259 + length = ures_getSize(data); 1.1260 + *field = newUnicodeStringArray(length); 1.1261 + if (*field) { 1.1262 + for(int32_t i = 0; i<length; i++) { 1.1263 + const UChar *resStr = ures_getStringByIndex(data, i, &strLen, &status); 1.1264 + // setTo() - see assignArray comments 1.1265 + (*(field)+i)->setTo(TRUE, resStr, strLen); 1.1266 + } 1.1267 + } 1.1268 + else { 1.1269 + length = 0; 1.1270 + status = U_MEMORY_ALLOCATION_ERROR; 1.1271 + } 1.1272 + } 1.1273 +} 1.1274 + 1.1275 +static void 1.1276 +initField(UnicodeString **field, int32_t& length, const UChar *data, LastResortSize numStr, LastResortSize strLen, UErrorCode &status) { 1.1277 + if (U_SUCCESS(status)) { 1.1278 + length = numStr; 1.1279 + *field = newUnicodeStringArray((size_t)numStr); 1.1280 + if (*field) { 1.1281 + for(int32_t i = 0; i<length; i++) { 1.1282 + // readonly aliases - all "data" strings are constant 1.1283 + // -1 as length for variable-length strings (gLastResortDayNames[0] is empty) 1.1284 + (*(field)+i)->setTo(TRUE, data+(i*((int32_t)strLen)), -1); 1.1285 + } 1.1286 + } 1.1287 + else { 1.1288 + length = 0; 1.1289 + status = U_MEMORY_ALLOCATION_ERROR; 1.1290 + } 1.1291 + } 1.1292 +} 1.1293 + 1.1294 +static void 1.1295 +initLeapMonthPattern(UnicodeString *field, int32_t index, const UResourceBundle *data, UErrorCode &status) { 1.1296 + field[index].remove(); 1.1297 + if (U_SUCCESS(status)) { 1.1298 + int32_t strLen = 0; 1.1299 + const UChar *resStr = ures_getStringByKey(data, gNamesLeapTag, &strLen, &status); 1.1300 + if (U_SUCCESS(status)) { 1.1301 + field[index].setTo(TRUE, resStr, strLen); 1.1302 + } 1.1303 + } 1.1304 + status = U_ZERO_ERROR; 1.1305 +} 1.1306 + 1.1307 +typedef struct { 1.1308 + const char * usageTypeName; 1.1309 + DateFormatSymbols::ECapitalizationContextUsageType usageTypeEnumValue; 1.1310 +} ContextUsageTypeNameToEnumValue; 1.1311 + 1.1312 +static const ContextUsageTypeNameToEnumValue contextUsageTypeMap[] = { 1.1313 + // Entries must be sorted by usageTypeName; entry with NULL name terminates list. 1.1314 + { "day-format-except-narrow", DateFormatSymbols::kCapContextUsageDayFormat }, 1.1315 + { "day-narrow", DateFormatSymbols::kCapContextUsageDayNarrow }, 1.1316 + { "day-standalone-except-narrow", DateFormatSymbols::kCapContextUsageDayStandalone }, 1.1317 + { "era-abbr", DateFormatSymbols::kCapContextUsageEraAbbrev }, 1.1318 + { "era-name", DateFormatSymbols::kCapContextUsageEraWide }, 1.1319 + { "era-narrow", DateFormatSymbols::kCapContextUsageEraNarrow }, 1.1320 + { "metazone-long", DateFormatSymbols::kCapContextUsageMetazoneLong }, 1.1321 + { "metazone-short", DateFormatSymbols::kCapContextUsageMetazoneShort }, 1.1322 + { "month-format-except-narrow", DateFormatSymbols::kCapContextUsageMonthFormat }, 1.1323 + { "month-narrow", DateFormatSymbols::kCapContextUsageMonthNarrow }, 1.1324 + { "month-standalone-except-narrow", DateFormatSymbols::kCapContextUsageMonthStandalone }, 1.1325 + { "zone-long", DateFormatSymbols::kCapContextUsageZoneLong }, 1.1326 + { "zone-short", DateFormatSymbols::kCapContextUsageZoneShort }, 1.1327 + { NULL, (DateFormatSymbols::ECapitalizationContextUsageType)0 }, 1.1328 +}; 1.1329 + 1.1330 +void 1.1331 +DateFormatSymbols::initializeData(const Locale& locale, const char *type, UErrorCode& status, UBool useLastResortData) 1.1332 +{ 1.1333 + int32_t i; 1.1334 + int32_t len = 0; 1.1335 + const UChar *resStr; 1.1336 + /* In case something goes wrong, initialize all of the data to NULL. */ 1.1337 + fEras = NULL; 1.1338 + fErasCount = 0; 1.1339 + fEraNames = NULL; 1.1340 + fEraNamesCount = 0; 1.1341 + fNarrowEras = NULL; 1.1342 + fNarrowErasCount = 0; 1.1343 + fMonths = NULL; 1.1344 + fMonthsCount=0; 1.1345 + fShortMonths = NULL; 1.1346 + fShortMonthsCount=0; 1.1347 + fNarrowMonths = NULL; 1.1348 + fNarrowMonthsCount=0; 1.1349 + fStandaloneMonths = NULL; 1.1350 + fStandaloneMonthsCount=0; 1.1351 + fStandaloneShortMonths = NULL; 1.1352 + fStandaloneShortMonthsCount=0; 1.1353 + fStandaloneNarrowMonths = NULL; 1.1354 + fStandaloneNarrowMonthsCount=0; 1.1355 + fWeekdays = NULL; 1.1356 + fWeekdaysCount=0; 1.1357 + fShortWeekdays = NULL; 1.1358 + fShortWeekdaysCount=0; 1.1359 + fShorterWeekdays = NULL; 1.1360 + fShorterWeekdaysCount=0; 1.1361 + fNarrowWeekdays = NULL; 1.1362 + fNarrowWeekdaysCount=0; 1.1363 + fStandaloneWeekdays = NULL; 1.1364 + fStandaloneWeekdaysCount=0; 1.1365 + fStandaloneShortWeekdays = NULL; 1.1366 + fStandaloneShortWeekdaysCount=0; 1.1367 + fStandaloneShorterWeekdays = NULL; 1.1368 + fStandaloneShorterWeekdaysCount=0; 1.1369 + fStandaloneNarrowWeekdays = NULL; 1.1370 + fStandaloneNarrowWeekdaysCount=0; 1.1371 + fAmPms = NULL; 1.1372 + fAmPmsCount=0; 1.1373 + fQuarters = NULL; 1.1374 + fQuartersCount = 0; 1.1375 + fShortQuarters = NULL; 1.1376 + fShortQuartersCount = 0; 1.1377 + fStandaloneQuarters = NULL; 1.1378 + fStandaloneQuartersCount = 0; 1.1379 + fStandaloneShortQuarters = NULL; 1.1380 + fStandaloneShortQuartersCount = 0; 1.1381 + fLeapMonthPatterns = NULL; 1.1382 + fLeapMonthPatternsCount = 0; 1.1383 + fShortYearNames = NULL; 1.1384 + fShortYearNamesCount = 0; 1.1385 + fZoneStringsRowCount = 0; 1.1386 + fZoneStringsColCount = 0; 1.1387 + fZoneStrings = NULL; 1.1388 + fLocaleZoneStrings = NULL; 1.1389 + uprv_memset(fCapitalization, 0, sizeof(fCapitalization)); 1.1390 + 1.1391 + // We need to preserve the requested locale for 1.1392 + // lazy ZoneStringFormat instantiation. ZoneStringFormat 1.1393 + // is region sensitive, thus, bundle locale bundle's locale 1.1394 + // is not sufficient. 1.1395 + fZSFLocale = locale; 1.1396 + 1.1397 + if (U_FAILURE(status)) return; 1.1398 + 1.1399 + /** 1.1400 + * Retrieve the string arrays we need from the resource bundle file. 1.1401 + * We cast away const here, but that's okay; we won't delete any of 1.1402 + * these. 1.1403 + */ 1.1404 + CalendarData calData(locale, type, status); 1.1405 + 1.1406 + // load the first data item 1.1407 + UResourceBundle *erasMain = calData.getByKey(gErasTag, status); 1.1408 + UResourceBundle *eras = ures_getByKeyWithFallback(erasMain, gNamesAbbrTag, NULL, &status); 1.1409 + UErrorCode oldStatus = status; 1.1410 + UResourceBundle *eraNames = ures_getByKeyWithFallback(erasMain, gNamesWideTag, NULL, &status); 1.1411 + if ( status == U_MISSING_RESOURCE_ERROR ) { // Workaround because eras/wide was omitted from CLDR 1.3 1.1412 + status = oldStatus; 1.1413 + eraNames = ures_getByKeyWithFallback(erasMain, gNamesAbbrTag, NULL, &status); 1.1414 + } 1.1415 + // current ICU4J falls back to abbreviated if narrow eras are missing, so we will too 1.1416 + oldStatus = status; 1.1417 + UResourceBundle *narrowEras = ures_getByKeyWithFallback(erasMain, gNamesNarrowTag, NULL, &status); 1.1418 + if ( status == U_MISSING_RESOURCE_ERROR ) { 1.1419 + status = oldStatus; 1.1420 + narrowEras = ures_getByKeyWithFallback(erasMain, gNamesAbbrTag, NULL, &status); 1.1421 + } 1.1422 + 1.1423 + UErrorCode tempStatus = U_ZERO_ERROR; 1.1424 + UResourceBundle *monthPatterns = calData.getByKey(gMonthPatternsTag, tempStatus); 1.1425 + if (U_SUCCESS(tempStatus) && monthPatterns != NULL) { 1.1426 + fLeapMonthPatterns = newUnicodeStringArray(kMonthPatternsCount); 1.1427 + if (fLeapMonthPatterns) { 1.1428 + initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternFormatWide, calData.getByKey2(gMonthPatternsTag, gNamesWideTag, tempStatus), tempStatus); 1.1429 + initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternFormatAbbrev, calData.getByKey2(gMonthPatternsTag, gNamesAbbrTag, tempStatus), tempStatus); 1.1430 + initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternFormatNarrow, calData.getByKey2(gMonthPatternsTag, gNamesNarrowTag, tempStatus), tempStatus); 1.1431 + initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternStandaloneWide, calData.getByKey3(gMonthPatternsTag, gNamesStandaloneTag, gNamesWideTag, tempStatus), tempStatus); 1.1432 + initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternStandaloneAbbrev, calData.getByKey3(gMonthPatternsTag, gNamesStandaloneTag, gNamesAbbrTag, tempStatus), tempStatus); 1.1433 + initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternStandaloneNarrow, calData.getByKey3(gMonthPatternsTag, gNamesStandaloneTag, gNamesNarrowTag, tempStatus), tempStatus); 1.1434 + initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternNumeric, calData.getByKey3(gMonthPatternsTag, gNamesNumericTag, gNamesAllTag, tempStatus), tempStatus); 1.1435 + if (U_SUCCESS(tempStatus)) { 1.1436 + fLeapMonthPatternsCount = kMonthPatternsCount; 1.1437 + } else { 1.1438 + delete[] fLeapMonthPatterns; 1.1439 + fLeapMonthPatterns = NULL; 1.1440 + } 1.1441 + } 1.1442 + } 1.1443 + 1.1444 + tempStatus = U_ZERO_ERROR; 1.1445 + UResourceBundle *cyclicNameSets= calData.getByKey(gCyclicNameSetsTag, tempStatus); 1.1446 + if (U_SUCCESS(tempStatus) && cyclicNameSets != NULL) { 1.1447 + UResourceBundle *nameSetYears = ures_getByKeyWithFallback(cyclicNameSets, gNameSetYearsTag, NULL, &tempStatus); 1.1448 + if (U_SUCCESS(tempStatus)) { 1.1449 + UResourceBundle *nameSetYearsFmt = ures_getByKeyWithFallback(nameSetYears, gNamesFormatTag, NULL, &tempStatus); 1.1450 + if (U_SUCCESS(tempStatus)) { 1.1451 + UResourceBundle *nameSetYearsFmtAbbrev = ures_getByKeyWithFallback(nameSetYearsFmt, gNamesAbbrTag, NULL, &tempStatus); 1.1452 + if (U_SUCCESS(tempStatus)) { 1.1453 + initField(&fShortYearNames, fShortYearNamesCount, nameSetYearsFmtAbbrev, tempStatus); 1.1454 + ures_close(nameSetYearsFmtAbbrev); 1.1455 + } 1.1456 + ures_close(nameSetYearsFmt); 1.1457 + } 1.1458 + ures_close(nameSetYears); 1.1459 + } 1.1460 + } 1.1461 + 1.1462 + tempStatus = U_ZERO_ERROR; 1.1463 + UResourceBundle *localeBundle = ures_open(NULL, locale.getName(), &tempStatus); 1.1464 + if (U_SUCCESS(tempStatus)) { 1.1465 + UResourceBundle *contextTransforms = ures_getByKeyWithFallback(localeBundle, gContextTransformsTag, NULL, &tempStatus); 1.1466 + if (U_SUCCESS(tempStatus)) { 1.1467 + UResourceBundle *contextTransformUsage; 1.1468 + while ( (contextTransformUsage = ures_getNextResource(contextTransforms, NULL, &tempStatus)) != NULL ) { 1.1469 + const int32_t * intVector = ures_getIntVector(contextTransformUsage, &len, &status); 1.1470 + if (U_SUCCESS(tempStatus) && intVector != NULL && len >= 2) { 1.1471 + const char* usageType = ures_getKey(contextTransformUsage); 1.1472 + if (usageType != NULL) { 1.1473 + const ContextUsageTypeNameToEnumValue * typeMapPtr = contextUsageTypeMap; 1.1474 + int32_t compResult = 0; 1.1475 + // linear search; list is short and we cannot be sure that bsearch is available 1.1476 + while ( typeMapPtr->usageTypeName != NULL && (compResult = uprv_strcmp(usageType, typeMapPtr->usageTypeName)) > 0 ) { 1.1477 + ++typeMapPtr; 1.1478 + } 1.1479 + if (typeMapPtr->usageTypeName != NULL && compResult == 0) { 1.1480 + fCapitalization[typeMapPtr->usageTypeEnumValue][0] = intVector[0]; 1.1481 + fCapitalization[typeMapPtr->usageTypeEnumValue][1] = intVector[1]; 1.1482 + } 1.1483 + } 1.1484 + } 1.1485 + tempStatus = U_ZERO_ERROR; 1.1486 + ures_close(contextTransformUsage); 1.1487 + } 1.1488 + ures_close(contextTransforms); 1.1489 + } 1.1490 + ures_close(localeBundle); 1.1491 + } 1.1492 + 1.1493 + UResourceBundle *weekdaysData = NULL; // Data closed by calData 1.1494 + UResourceBundle *abbrWeekdaysData = NULL; // Data closed by calData 1.1495 + UResourceBundle *shorterWeekdaysData = NULL; // Data closed by calData 1.1496 + UResourceBundle *narrowWeekdaysData = NULL; // Data closed by calData 1.1497 + UResourceBundle *standaloneWeekdaysData = NULL; // Data closed by calData 1.1498 + UResourceBundle *standaloneAbbrWeekdaysData = NULL; // Data closed by calData 1.1499 + UResourceBundle *standaloneShorterWeekdaysData = NULL; // Data closed by calData 1.1500 + UResourceBundle *standaloneNarrowWeekdaysData = NULL; // Data closed by calData 1.1501 + 1.1502 + U_LOCALE_BASED(locBased, *this); 1.1503 + if (U_FAILURE(status)) 1.1504 + { 1.1505 + if (useLastResortData) 1.1506 + { 1.1507 + // Handle the case in which there is no resource data present. 1.1508 + // We don't have to generate usable patterns in this situation; 1.1509 + // we just need to produce something that will be semi-intelligible 1.1510 + // in most locales. 1.1511 + 1.1512 + status = U_USING_FALLBACK_WARNING; 1.1513 + 1.1514 + initField(&fEras, fErasCount, (const UChar *)gLastResortEras, kEraNum, kEraLen, status); 1.1515 + initField(&fEraNames, fEraNamesCount, (const UChar *)gLastResortEras, kEraNum, kEraLen, status); 1.1516 + initField(&fNarrowEras, fNarrowErasCount, (const UChar *)gLastResortEras, kEraNum, kEraLen, status); 1.1517 + initField(&fMonths, fMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status); 1.1518 + initField(&fShortMonths, fShortMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status); 1.1519 + initField(&fNarrowMonths, fNarrowMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status); 1.1520 + initField(&fStandaloneMonths, fStandaloneMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status); 1.1521 + initField(&fStandaloneShortMonths, fStandaloneShortMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status); 1.1522 + initField(&fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status); 1.1523 + initField(&fWeekdays, fWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); 1.1524 + initField(&fShortWeekdays, fShortWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); 1.1525 + initField(&fShorterWeekdays, fShorterWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); 1.1526 + initField(&fNarrowWeekdays, fNarrowWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); 1.1527 + initField(&fStandaloneWeekdays, fStandaloneWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); 1.1528 + initField(&fStandaloneShortWeekdays, fStandaloneShortWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); 1.1529 + initField(&fStandaloneShorterWeekdays, fStandaloneShorterWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); 1.1530 + initField(&fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); 1.1531 + initField(&fAmPms, fAmPmsCount, (const UChar *)gLastResortAmPmMarkers, kAmPmNum, kAmPmLen, status); 1.1532 + initField(&fQuarters, fQuartersCount, (const UChar *)gLastResortQuarters, kQuarterNum, kQuarterLen, status); 1.1533 + initField(&fShortQuarters, fShortQuartersCount, (const UChar *)gLastResortQuarters, kQuarterNum, kQuarterLen, status); 1.1534 + initField(&fStandaloneQuarters, fStandaloneQuartersCount, (const UChar *)gLastResortQuarters, kQuarterNum, kQuarterLen, status); 1.1535 + initField(&fStandaloneShortQuarters, fStandaloneShortQuartersCount, (const UChar *)gLastResortQuarters, kQuarterNum, kQuarterLen, status); 1.1536 + fLocalPatternChars.setTo(TRUE, gPatternChars, PATTERN_CHARS_LEN); 1.1537 + } 1.1538 + goto cleanup; 1.1539 + } 1.1540 + 1.1541 + // if we make it to here, the resource data is cool, and we can get everything out 1.1542 + // of it that we need except for the time-zone and localized-pattern data, which 1.1543 + // are stored in a separate file 1.1544 + locBased.setLocaleIDs(ures_getLocaleByType(eras, ULOC_VALID_LOCALE, &status), 1.1545 + ures_getLocaleByType(eras, ULOC_ACTUAL_LOCALE, &status)); 1.1546 + 1.1547 + initField(&fEras, fErasCount, eras, status); 1.1548 + initField(&fEraNames, fEraNamesCount, eraNames, status); 1.1549 + initField(&fNarrowEras, fNarrowErasCount, narrowEras, status); 1.1550 + 1.1551 + initField(&fMonths, fMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesWideTag, status), status); 1.1552 + initField(&fShortMonths, fShortMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesAbbrTag, status), status); 1.1553 + 1.1554 + initField(&fNarrowMonths, fNarrowMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesNarrowTag, status), status); 1.1555 + if(status == U_MISSING_RESOURCE_ERROR) { 1.1556 + status = U_ZERO_ERROR; 1.1557 + initField(&fNarrowMonths, fNarrowMonthsCount, calData.getByKey3(gMonthNamesTag, gNamesStandaloneTag, gNamesNarrowTag, status), status); 1.1558 + } 1.1559 + if ( status == U_MISSING_RESOURCE_ERROR ) { /* If format/narrow not available, use format/abbreviated */ 1.1560 + status = U_ZERO_ERROR; 1.1561 + initField(&fNarrowMonths, fNarrowMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesAbbrTag, status), status); 1.1562 + } 1.1563 + 1.1564 + initField(&fStandaloneMonths, fStandaloneMonthsCount, calData.getByKey3(gMonthNamesTag, gNamesStandaloneTag, gNamesWideTag, status), status); 1.1565 + if ( status == U_MISSING_RESOURCE_ERROR ) { /* If standalone/wide not available, use format/wide */ 1.1566 + status = U_ZERO_ERROR; 1.1567 + initField(&fStandaloneMonths, fStandaloneMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesWideTag, status), status); 1.1568 + } 1.1569 + initField(&fStandaloneShortMonths, fStandaloneShortMonthsCount, calData.getByKey3(gMonthNamesTag, gNamesStandaloneTag, gNamesAbbrTag, status), status); 1.1570 + if ( status == U_MISSING_RESOURCE_ERROR ) { /* If standalone/abbreviated not available, use format/abbreviated */ 1.1571 + status = U_ZERO_ERROR; 1.1572 + initField(&fStandaloneShortMonths, fStandaloneShortMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesAbbrTag, status), status); 1.1573 + } 1.1574 + initField(&fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, calData.getByKey3(gMonthNamesTag, gNamesStandaloneTag, gNamesNarrowTag, status), status); 1.1575 + if ( status == U_MISSING_RESOURCE_ERROR ) { /* if standalone/narrow not availabe, try format/narrow */ 1.1576 + status = U_ZERO_ERROR; 1.1577 + initField(&fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesNarrowTag, status), status); 1.1578 + if ( status == U_MISSING_RESOURCE_ERROR ) { /* if still not there, use format/abbreviated */ 1.1579 + status = U_ZERO_ERROR; 1.1580 + initField(&fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesAbbrTag, status), status); 1.1581 + } 1.1582 + } 1.1583 + initField(&fAmPms, fAmPmsCount, calData.getByKey(gAmPmMarkersTag, status), status); 1.1584 + 1.1585 + initField(&fQuarters, fQuartersCount, calData.getByKey2(gQuartersTag, gNamesWideTag, status), status); 1.1586 + initField(&fShortQuarters, fShortQuartersCount, calData.getByKey2(gQuartersTag, gNamesAbbrTag, status), status); 1.1587 + 1.1588 + initField(&fStandaloneQuarters, fStandaloneQuartersCount, calData.getByKey3(gQuartersTag, gNamesStandaloneTag, gNamesWideTag, status), status); 1.1589 + if(status == U_MISSING_RESOURCE_ERROR) { 1.1590 + status = U_ZERO_ERROR; 1.1591 + initField(&fStandaloneQuarters, fStandaloneQuartersCount, calData.getByKey2(gQuartersTag, gNamesWideTag, status), status); 1.1592 + } 1.1593 + 1.1594 + initField(&fStandaloneShortQuarters, fStandaloneShortQuartersCount, calData.getByKey3(gQuartersTag, gNamesStandaloneTag, gNamesAbbrTag, status), status); 1.1595 + if(status == U_MISSING_RESOURCE_ERROR) { 1.1596 + status = U_ZERO_ERROR; 1.1597 + initField(&fStandaloneShortQuarters, fStandaloneShortQuartersCount, calData.getByKey2(gQuartersTag, gNamesAbbrTag, status), status); 1.1598 + } 1.1599 + 1.1600 + // ICU 3.8 or later version no longer uses localized date-time pattern characters by default (ticket#5597) 1.1601 + /* 1.1602 + // fastCopyFrom()/setTo() - see assignArray comments 1.1603 + resStr = ures_getStringByKey(fResourceBundle, gLocalPatternCharsTag, &len, &status); 1.1604 + fLocalPatternChars.setTo(TRUE, resStr, len); 1.1605 + // If the locale data does not include new pattern chars, use the defaults 1.1606 + // TODO: Consider making this an error, since this may add conflicting characters. 1.1607 + if (len < PATTERN_CHARS_LEN) { 1.1608 + fLocalPatternChars.append(UnicodeString(TRUE, &gPatternChars[len], PATTERN_CHARS_LEN-len)); 1.1609 + } 1.1610 + */ 1.1611 + fLocalPatternChars.setTo(TRUE, gPatternChars, PATTERN_CHARS_LEN); 1.1612 + 1.1613 + // Format wide weekdays -> fWeekdays 1.1614 + // {sfb} fixed to handle 1-based weekdays 1.1615 + weekdaysData = calData.getByKey2(gDayNamesTag, gNamesWideTag, status); 1.1616 + fWeekdaysCount = ures_getSize(weekdaysData); 1.1617 + fWeekdays = new UnicodeString[fWeekdaysCount+1]; 1.1618 + /* pin the blame on system. If we cannot get a chunk of memory .. the system is dying!*/ 1.1619 + if (fWeekdays == NULL) { 1.1620 + status = U_MEMORY_ALLOCATION_ERROR; 1.1621 + goto cleanup; 1.1622 + } 1.1623 + // leave fWeekdays[0] empty 1.1624 + for(i = 0; i<fWeekdaysCount; i++) { 1.1625 + resStr = ures_getStringByIndex(weekdaysData, i, &len, &status); 1.1626 + // setTo() - see assignArray comments 1.1627 + fWeekdays[i+1].setTo(TRUE, resStr, len); 1.1628 + } 1.1629 + fWeekdaysCount++; 1.1630 + 1.1631 + // Format abbreviated weekdays -> fShortWeekdays 1.1632 + abbrWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status); 1.1633 + fShortWeekdaysCount = ures_getSize(abbrWeekdaysData); 1.1634 + fShortWeekdays = new UnicodeString[fShortWeekdaysCount+1]; 1.1635 + /* test for NULL */ 1.1636 + if (fShortWeekdays == 0) { 1.1637 + status = U_MEMORY_ALLOCATION_ERROR; 1.1638 + goto cleanup; 1.1639 + } 1.1640 + // leave fShortWeekdays[0] empty 1.1641 + for(i = 0; i<fShortWeekdaysCount; i++) { 1.1642 + resStr = ures_getStringByIndex(abbrWeekdaysData, i, &len, &status); 1.1643 + // setTo() - see assignArray comments 1.1644 + fShortWeekdays[i+1].setTo(TRUE, resStr, len); 1.1645 + } 1.1646 + fShortWeekdaysCount++; 1.1647 + 1.1648 + // Format short weekdays -> fShorterWeekdays (fall back to abbreviated) 1.1649 + shorterWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesShortTag, status); 1.1650 + if ( status == U_MISSING_RESOURCE_ERROR ) { 1.1651 + status = U_ZERO_ERROR; 1.1652 + shorterWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status); 1.1653 + } 1.1654 + fShorterWeekdaysCount = ures_getSize(shorterWeekdaysData); 1.1655 + fShorterWeekdays = new UnicodeString[fShorterWeekdaysCount+1]; 1.1656 + /* test for NULL */ 1.1657 + if (fShorterWeekdays == 0) { 1.1658 + status = U_MEMORY_ALLOCATION_ERROR; 1.1659 + goto cleanup; 1.1660 + } 1.1661 + // leave fShorterWeekdays[0] empty 1.1662 + for(i = 0; i<fShorterWeekdaysCount; i++) { 1.1663 + resStr = ures_getStringByIndex(shorterWeekdaysData, i, &len, &status); 1.1664 + // setTo() - see assignArray comments 1.1665 + fShorterWeekdays[i+1].setTo(TRUE, resStr, len); 1.1666 + } 1.1667 + fShorterWeekdaysCount++; 1.1668 + 1.1669 + // Format narrow weekdays -> fNarrowWeekdays 1.1670 + narrowWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesNarrowTag, status); 1.1671 + if(status == U_MISSING_RESOURCE_ERROR) { 1.1672 + status = U_ZERO_ERROR; 1.1673 + narrowWeekdaysData = calData.getByKey3(gDayNamesTag, gNamesStandaloneTag, gNamesNarrowTag, status); 1.1674 + } 1.1675 + if ( status == U_MISSING_RESOURCE_ERROR ) { 1.1676 + status = U_ZERO_ERROR; 1.1677 + narrowWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status); 1.1678 + } 1.1679 + fNarrowWeekdaysCount = ures_getSize(narrowWeekdaysData); 1.1680 + fNarrowWeekdays = new UnicodeString[fNarrowWeekdaysCount+1]; 1.1681 + /* test for NULL */ 1.1682 + if (fNarrowWeekdays == 0) { 1.1683 + status = U_MEMORY_ALLOCATION_ERROR; 1.1684 + goto cleanup; 1.1685 + } 1.1686 + // leave fNarrowWeekdays[0] empty 1.1687 + for(i = 0; i<fNarrowWeekdaysCount; i++) { 1.1688 + resStr = ures_getStringByIndex(narrowWeekdaysData, i, &len, &status); 1.1689 + // setTo() - see assignArray comments 1.1690 + fNarrowWeekdays[i+1].setTo(TRUE, resStr, len); 1.1691 + } 1.1692 + fNarrowWeekdaysCount++; 1.1693 + 1.1694 + // Stand-alone wide weekdays -> fStandaloneWeekdays 1.1695 + standaloneWeekdaysData = calData.getByKey3(gDayNamesTag, gNamesStandaloneTag, gNamesWideTag, status); 1.1696 + if ( status == U_MISSING_RESOURCE_ERROR ) { 1.1697 + status = U_ZERO_ERROR; 1.1698 + standaloneWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesWideTag, status); 1.1699 + } 1.1700 + fStandaloneWeekdaysCount = ures_getSize(standaloneWeekdaysData); 1.1701 + fStandaloneWeekdays = new UnicodeString[fStandaloneWeekdaysCount+1]; 1.1702 + /* test for NULL */ 1.1703 + if (fStandaloneWeekdays == 0) { 1.1704 + status = U_MEMORY_ALLOCATION_ERROR; 1.1705 + goto cleanup; 1.1706 + } 1.1707 + // leave fStandaloneWeekdays[0] empty 1.1708 + for(i = 0; i<fStandaloneWeekdaysCount; i++) { 1.1709 + resStr = ures_getStringByIndex(standaloneWeekdaysData, i, &len, &status); 1.1710 + // setTo() - see assignArray comments 1.1711 + fStandaloneWeekdays[i+1].setTo(TRUE, resStr, len); 1.1712 + } 1.1713 + fStandaloneWeekdaysCount++; 1.1714 + 1.1715 + // Stand-alone abbreviated weekdays -> fStandaloneShortWeekdays 1.1716 + standaloneAbbrWeekdaysData = calData.getByKey3(gDayNamesTag, gNamesStandaloneTag, gNamesAbbrTag, status); 1.1717 + if ( status == U_MISSING_RESOURCE_ERROR ) { 1.1718 + status = U_ZERO_ERROR; 1.1719 + standaloneAbbrWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status); 1.1720 + } 1.1721 + fStandaloneShortWeekdaysCount = ures_getSize(standaloneAbbrWeekdaysData); 1.1722 + fStandaloneShortWeekdays = new UnicodeString[fStandaloneShortWeekdaysCount+1]; 1.1723 + /* test for NULL */ 1.1724 + if (fStandaloneShortWeekdays == 0) { 1.1725 + status = U_MEMORY_ALLOCATION_ERROR; 1.1726 + goto cleanup; 1.1727 + } 1.1728 + // leave fStandaloneShortWeekdays[0] empty 1.1729 + for(i = 0; i<fStandaloneShortWeekdaysCount; i++) { 1.1730 + resStr = ures_getStringByIndex(standaloneAbbrWeekdaysData, i, &len, &status); 1.1731 + // setTo() - see assignArray comments 1.1732 + fStandaloneShortWeekdays[i+1].setTo(TRUE, resStr, len); 1.1733 + } 1.1734 + fStandaloneShortWeekdaysCount++; 1.1735 + 1.1736 + // Stand-alone short weekdays -> fStandaloneShorterWeekdays (fall back to format abbreviated) 1.1737 + standaloneShorterWeekdaysData = calData.getByKey3(gDayNamesTag, gNamesStandaloneTag, gNamesShortTag, status); 1.1738 + if ( status == U_MISSING_RESOURCE_ERROR ) { 1.1739 + status = U_ZERO_ERROR; 1.1740 + standaloneShorterWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status); 1.1741 + } 1.1742 + fStandaloneShorterWeekdaysCount = ures_getSize(standaloneShorterWeekdaysData); 1.1743 + fStandaloneShorterWeekdays = new UnicodeString[fStandaloneShorterWeekdaysCount+1]; 1.1744 + /* test for NULL */ 1.1745 + if (fStandaloneShorterWeekdays == 0) { 1.1746 + status = U_MEMORY_ALLOCATION_ERROR; 1.1747 + goto cleanup; 1.1748 + } 1.1749 + // leave fStandaloneShorterWeekdays[0] empty 1.1750 + for(i = 0; i<fStandaloneShorterWeekdaysCount; i++) { 1.1751 + resStr = ures_getStringByIndex(standaloneShorterWeekdaysData, i, &len, &status); 1.1752 + // setTo() - see assignArray comments 1.1753 + fStandaloneShorterWeekdays[i+1].setTo(TRUE, resStr, len); 1.1754 + } 1.1755 + fStandaloneShorterWeekdaysCount++; 1.1756 + 1.1757 + // Stand-alone narrow weekdays -> fStandaloneNarrowWeekdays 1.1758 + standaloneNarrowWeekdaysData = calData.getByKey3(gDayNamesTag, gNamesStandaloneTag, gNamesNarrowTag, status); 1.1759 + if ( status == U_MISSING_RESOURCE_ERROR ) { 1.1760 + status = U_ZERO_ERROR; 1.1761 + standaloneNarrowWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesNarrowTag, status); 1.1762 + if ( status == U_MISSING_RESOURCE_ERROR ) { 1.1763 + status = U_ZERO_ERROR; 1.1764 + standaloneNarrowWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status); 1.1765 + } 1.1766 + } 1.1767 + fStandaloneNarrowWeekdaysCount = ures_getSize(standaloneNarrowWeekdaysData); 1.1768 + fStandaloneNarrowWeekdays = new UnicodeString[fStandaloneNarrowWeekdaysCount+1]; 1.1769 + /* test for NULL */ 1.1770 + if (fStandaloneNarrowWeekdays == 0) { 1.1771 + status = U_MEMORY_ALLOCATION_ERROR; 1.1772 + goto cleanup; 1.1773 + } 1.1774 + // leave fStandaloneNarrowWeekdays[0] empty 1.1775 + for(i = 0; i<fStandaloneNarrowWeekdaysCount; i++) { 1.1776 + resStr = ures_getStringByIndex(standaloneNarrowWeekdaysData, i, &len, &status); 1.1777 + // setTo() - see assignArray comments 1.1778 + fStandaloneNarrowWeekdays[i+1].setTo(TRUE, resStr, len); 1.1779 + } 1.1780 + fStandaloneNarrowWeekdaysCount++; 1.1781 + 1.1782 +cleanup: 1.1783 + ures_close(eras); 1.1784 + ures_close(eraNames); 1.1785 + ures_close(narrowEras); 1.1786 +} 1.1787 + 1.1788 +Locale 1.1789 +DateFormatSymbols::getLocale(ULocDataLocaleType type, UErrorCode& status) const { 1.1790 + U_LOCALE_BASED(locBased, *this); 1.1791 + return locBased.getLocale(type, status); 1.1792 +} 1.1793 + 1.1794 +U_NAMESPACE_END 1.1795 + 1.1796 +#endif /* #if !UCONFIG_NO_FORMATTING */ 1.1797 + 1.1798 +//eof