michael@0: /* michael@0: ******************************************************************************* michael@0: * Copyright (C) 1997-2013, International Business Machines Corporation and * michael@0: * others. All Rights Reserved. * michael@0: ******************************************************************************* michael@0: * michael@0: * File DTFMTSYM.CPP michael@0: * michael@0: * Modification History: michael@0: * michael@0: * Date Name Description michael@0: * 02/19/97 aliu Converted from java. michael@0: * 07/21/98 stephen Added getZoneIndex michael@0: * Changed weekdays/short weekdays to be one-based michael@0: * 06/14/99 stephen Removed SimpleDateFormat::fgTimeZoneDataSuffix michael@0: * 11/16/99 weiv Added 'Y' and 'e' to fgPatternChars michael@0: * 03/27/00 weiv Keeping resource bundle around! michael@0: * 06/30/05 emmons Added eraNames, narrow month/day, standalone context michael@0: * 10/12/05 emmons Added setters for eraNames, month/day by width/context michael@0: ******************************************************************************* michael@0: */ michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: #include "unicode/ustring.h" michael@0: #include "unicode/dtfmtsym.h" michael@0: #include "unicode/smpdtfmt.h" michael@0: #include "unicode/msgfmt.h" michael@0: #include "unicode/tznames.h" michael@0: #include "cpputils.h" michael@0: #include "ucln_in.h" michael@0: #include "umutex.h" michael@0: #include "cmemory.h" michael@0: #include "cstring.h" michael@0: #include "locbased.h" michael@0: #include "gregoimp.h" michael@0: #include "hash.h" michael@0: #include "uresimp.h" michael@0: #include "ureslocs.h" michael@0: michael@0: // ***************************************************************************** michael@0: // class DateFormatSymbols michael@0: // ***************************************************************************** michael@0: michael@0: /** michael@0: * These are static arrays we use only in the case where we have no michael@0: * resource data. michael@0: */ michael@0: michael@0: #define PATTERN_CHARS_LEN 34 michael@0: michael@0: /** michael@0: * Unlocalized date-time pattern characters. For example: 'y', 'd', etc. All michael@0: * locales use the same these unlocalized pattern characters. michael@0: */ michael@0: static const UChar gPatternChars[] = { michael@0: // GyMdkHmsSEDFwWahKzYeugAZvcLQqVUOXx michael@0: 0x47, 0x79, 0x4D, 0x64, 0x6B, 0x48, 0x6D, 0x73, 0x53, 0x45, michael@0: 0x44, 0x46, 0x77, 0x57, 0x61, 0x68, 0x4B, 0x7A, 0x59, 0x65, michael@0: 0x75, 0x67, 0x41, 0x5A, 0x76, 0x63, 0x4c, 0x51, 0x71, 0x56, michael@0: 0x55, 0x4F, 0x58, 0x78, 0 michael@0: }; michael@0: michael@0: /* length of an array */ michael@0: #define ARRAY_LENGTH(array) (sizeof(array)/sizeof(array[0])) michael@0: michael@0: //------------------------------------------------------ michael@0: // Strings of last resort. These are only used if we have no resource michael@0: // files. They aren't designed for actual use, just for backup. michael@0: michael@0: // These are the month names and abbreviations of last resort. michael@0: static const UChar gLastResortMonthNames[13][3] = michael@0: { michael@0: {0x0030, 0x0031, 0x0000}, /* "01" */ michael@0: {0x0030, 0x0032, 0x0000}, /* "02" */ michael@0: {0x0030, 0x0033, 0x0000}, /* "03" */ michael@0: {0x0030, 0x0034, 0x0000}, /* "04" */ michael@0: {0x0030, 0x0035, 0x0000}, /* "05" */ michael@0: {0x0030, 0x0036, 0x0000}, /* "06" */ michael@0: {0x0030, 0x0037, 0x0000}, /* "07" */ michael@0: {0x0030, 0x0038, 0x0000}, /* "08" */ michael@0: {0x0030, 0x0039, 0x0000}, /* "09" */ michael@0: {0x0031, 0x0030, 0x0000}, /* "10" */ michael@0: {0x0031, 0x0031, 0x0000}, /* "11" */ michael@0: {0x0031, 0x0032, 0x0000}, /* "12" */ michael@0: {0x0031, 0x0033, 0x0000} /* "13" */ michael@0: }; michael@0: michael@0: // These are the weekday names and abbreviations of last resort. michael@0: static const UChar gLastResortDayNames[8][2] = michael@0: { michael@0: {0x0030, 0x0000}, /* "0" */ michael@0: {0x0031, 0x0000}, /* "1" */ michael@0: {0x0032, 0x0000}, /* "2" */ michael@0: {0x0033, 0x0000}, /* "3" */ michael@0: {0x0034, 0x0000}, /* "4" */ michael@0: {0x0035, 0x0000}, /* "5" */ michael@0: {0x0036, 0x0000}, /* "6" */ michael@0: {0x0037, 0x0000} /* "7" */ michael@0: }; michael@0: michael@0: // These are the quarter names and abbreviations of last resort. michael@0: static const UChar gLastResortQuarters[4][2] = michael@0: { michael@0: {0x0031, 0x0000}, /* "1" */ michael@0: {0x0032, 0x0000}, /* "2" */ michael@0: {0x0033, 0x0000}, /* "3" */ michael@0: {0x0034, 0x0000}, /* "4" */ michael@0: }; michael@0: michael@0: // These are the am/pm and BC/AD markers of last resort. michael@0: static const UChar gLastResortAmPmMarkers[2][3] = michael@0: { michael@0: {0x0041, 0x004D, 0x0000}, /* "AM" */ michael@0: {0x0050, 0x004D, 0x0000} /* "PM" */ michael@0: }; michael@0: michael@0: static const UChar gLastResortEras[2][3] = michael@0: { michael@0: {0x0042, 0x0043, 0x0000}, /* "BC" */ michael@0: {0x0041, 0x0044, 0x0000} /* "AD" */ michael@0: }; michael@0: michael@0: /* Sizes for the last resort string arrays */ michael@0: typedef enum LastResortSize { michael@0: kMonthNum = 13, michael@0: kMonthLen = 3, michael@0: michael@0: kDayNum = 8, michael@0: kDayLen = 2, michael@0: michael@0: kAmPmNum = 2, michael@0: kAmPmLen = 3, michael@0: michael@0: kQuarterNum = 4, michael@0: kQuarterLen = 2, michael@0: michael@0: kEraNum = 2, michael@0: kEraLen = 3, michael@0: michael@0: kZoneNum = 5, michael@0: kZoneLen = 4, michael@0: michael@0: kGmtHourNum = 4, michael@0: kGmtHourLen = 10 michael@0: } LastResortSize; michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateFormatSymbols) michael@0: michael@0: #define kSUPPLEMENTAL "supplementalData" michael@0: michael@0: /** michael@0: * These are the tags we expect to see in normal resource bundle files associated michael@0: * with a locale and calendar michael@0: */ michael@0: static const char gErasTag[]="eras"; michael@0: static const char gCyclicNameSetsTag[]="cyclicNameSets"; michael@0: static const char gNameSetYearsTag[]="years"; michael@0: static const char gMonthNamesTag[]="monthNames"; michael@0: static const char gMonthPatternsTag[]="monthPatterns"; michael@0: static const char gDayNamesTag[]="dayNames"; michael@0: static const char gNamesWideTag[]="wide"; michael@0: static const char gNamesAbbrTag[]="abbreviated"; michael@0: static const char gNamesShortTag[]="short"; michael@0: static const char gNamesNarrowTag[]="narrow"; michael@0: static const char gNamesAllTag[]="all"; michael@0: static const char gNamesLeapTag[]="leap"; michael@0: static const char gNamesFormatTag[]="format"; michael@0: static const char gNamesStandaloneTag[]="stand-alone"; michael@0: static const char gNamesNumericTag[]="numeric"; michael@0: static const char gAmPmMarkersTag[]="AmPmMarkers"; michael@0: static const char gQuartersTag[]="quarters"; michael@0: michael@0: // static const char gZoneStringsTag[]="zoneStrings"; michael@0: michael@0: // static const char gLocalPatternCharsTag[]="localPatternChars"; michael@0: michael@0: static const char gContextTransformsTag[]="contextTransforms"; michael@0: michael@0: static UMutex LOCK = U_MUTEX_INITIALIZER; michael@0: michael@0: /** michael@0: * Jitterbug 2974: MSVC has a bug whereby new X[0] behaves badly. michael@0: * Work around this. michael@0: */ michael@0: static inline UnicodeString* newUnicodeStringArray(size_t count) { michael@0: return new UnicodeString[count ? count : 1]; michael@0: } michael@0: michael@0: //------------------------------------------------------ michael@0: michael@0: DateFormatSymbols::DateFormatSymbols(const Locale& locale, michael@0: UErrorCode& status) michael@0: : UObject() michael@0: { michael@0: initializeData(locale, NULL, status); michael@0: } michael@0: michael@0: DateFormatSymbols::DateFormatSymbols(UErrorCode& status) michael@0: : UObject() michael@0: { michael@0: initializeData(Locale::getDefault(), NULL, status, TRUE); michael@0: } michael@0: michael@0: michael@0: DateFormatSymbols::DateFormatSymbols(const Locale& locale, michael@0: const char *type, michael@0: UErrorCode& status) michael@0: : UObject() michael@0: { michael@0: initializeData(locale, type, status); michael@0: } michael@0: michael@0: DateFormatSymbols::DateFormatSymbols(const char *type, UErrorCode& status) michael@0: : UObject() michael@0: { michael@0: initializeData(Locale::getDefault(), type, status, TRUE); michael@0: } michael@0: michael@0: DateFormatSymbols::DateFormatSymbols(const DateFormatSymbols& other) michael@0: : UObject(other) michael@0: { michael@0: copyData(other); michael@0: } michael@0: michael@0: void michael@0: DateFormatSymbols::assignArray(UnicodeString*& dstArray, michael@0: int32_t& dstCount, michael@0: const UnicodeString* srcArray, michael@0: int32_t srcCount) michael@0: { michael@0: // assignArray() is only called by copyData(), which in turn implements the michael@0: // copy constructor and the assignment operator. michael@0: // All strings in a DateFormatSymbols object are created in one of the following michael@0: // three ways that all allow to safely use UnicodeString::fastCopyFrom(): michael@0: // - readonly-aliases from resource bundles michael@0: // - readonly-aliases or allocated strings from constants michael@0: // - safely cloned strings (with owned buffers) from setXYZ() functions michael@0: // michael@0: // Note that this is true for as long as DateFormatSymbols can be constructed michael@0: // only from a locale bundle or set via the cloning API, michael@0: // *and* for as long as all the strings are in *private* fields, preventing michael@0: // a subclass from creating these strings in an "unsafe" way (with respect to fastCopyFrom()). michael@0: dstCount = srcCount; michael@0: dstArray = newUnicodeStringArray(srcCount); michael@0: if(dstArray != NULL) { michael@0: int32_t i; michael@0: for(i=0; i= 0; i--) { michael@0: delete[] fZoneStrings[i]; michael@0: } michael@0: uprv_free(fZoneStrings); michael@0: fZoneStrings = NULL; michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Copy all of the other's data to this. michael@0: */ michael@0: void michael@0: DateFormatSymbols::copyData(const DateFormatSymbols& other) { michael@0: assignArray(fEras, fErasCount, other.fEras, other.fErasCount); michael@0: assignArray(fEraNames, fEraNamesCount, other.fEraNames, other.fEraNamesCount); michael@0: assignArray(fNarrowEras, fNarrowErasCount, other.fNarrowEras, other.fNarrowErasCount); michael@0: assignArray(fMonths, fMonthsCount, other.fMonths, other.fMonthsCount); michael@0: assignArray(fShortMonths, fShortMonthsCount, other.fShortMonths, other.fShortMonthsCount); michael@0: assignArray(fNarrowMonths, fNarrowMonthsCount, other.fNarrowMonths, other.fNarrowMonthsCount); michael@0: assignArray(fStandaloneMonths, fStandaloneMonthsCount, other.fStandaloneMonths, other.fStandaloneMonthsCount); michael@0: assignArray(fStandaloneShortMonths, fStandaloneShortMonthsCount, other.fStandaloneShortMonths, other.fStandaloneShortMonthsCount); michael@0: assignArray(fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, other.fStandaloneNarrowMonths, other.fStandaloneNarrowMonthsCount); michael@0: assignArray(fWeekdays, fWeekdaysCount, other.fWeekdays, other.fWeekdaysCount); michael@0: assignArray(fShortWeekdays, fShortWeekdaysCount, other.fShortWeekdays, other.fShortWeekdaysCount); michael@0: assignArray(fShorterWeekdays, fShorterWeekdaysCount, other.fShorterWeekdays, other.fShorterWeekdaysCount); michael@0: assignArray(fNarrowWeekdays, fNarrowWeekdaysCount, other.fNarrowWeekdays, other.fNarrowWeekdaysCount); michael@0: assignArray(fStandaloneWeekdays, fStandaloneWeekdaysCount, other.fStandaloneWeekdays, other.fStandaloneWeekdaysCount); michael@0: assignArray(fStandaloneShortWeekdays, fStandaloneShortWeekdaysCount, other.fStandaloneShortWeekdays, other.fStandaloneShortWeekdaysCount); michael@0: assignArray(fStandaloneShorterWeekdays, fStandaloneShorterWeekdaysCount, other.fStandaloneShorterWeekdays, other.fStandaloneShorterWeekdaysCount); michael@0: assignArray(fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount, other.fStandaloneNarrowWeekdays, other.fStandaloneNarrowWeekdaysCount); michael@0: assignArray(fAmPms, fAmPmsCount, other.fAmPms, other.fAmPmsCount); michael@0: assignArray(fQuarters, fQuartersCount, other.fQuarters, other.fQuartersCount); michael@0: assignArray(fShortQuarters, fShortQuartersCount, other.fShortQuarters, other.fShortQuartersCount); michael@0: assignArray(fStandaloneQuarters, fStandaloneQuartersCount, other.fStandaloneQuarters, other.fStandaloneQuartersCount); michael@0: assignArray(fStandaloneShortQuarters, fStandaloneShortQuartersCount, other.fStandaloneShortQuarters, other.fStandaloneShortQuartersCount); michael@0: if (other.fLeapMonthPatterns != NULL) { michael@0: assignArray(fLeapMonthPatterns, fLeapMonthPatternsCount, other.fLeapMonthPatterns, other.fLeapMonthPatternsCount); michael@0: } else { michael@0: fLeapMonthPatterns = NULL; michael@0: fLeapMonthPatternsCount = 0; michael@0: } michael@0: if (other.fShortYearNames != NULL) { michael@0: assignArray(fShortYearNames, fShortYearNamesCount, other.fShortYearNames, other.fShortYearNamesCount); michael@0: } else { michael@0: fShortYearNames = NULL; michael@0: fShortYearNamesCount = 0; michael@0: } michael@0: michael@0: if (other.fZoneStrings != NULL) { michael@0: fZoneStringsColCount = other.fZoneStringsColCount; michael@0: fZoneStringsRowCount = other.fZoneStringsRowCount; michael@0: createZoneStrings((const UnicodeString**)other.fZoneStrings); michael@0: michael@0: } else { michael@0: fZoneStrings = NULL; michael@0: fZoneStringsColCount = 0; michael@0: fZoneStringsRowCount = 0; michael@0: } michael@0: fZSFLocale = other.fZSFLocale; michael@0: // Other zone strings data is created on demand michael@0: fLocaleZoneStrings = NULL; michael@0: michael@0: // fastCopyFrom() - see assignArray comments michael@0: fLocalPatternChars.fastCopyFrom(other.fLocalPatternChars); michael@0: michael@0: uprv_memcpy(fCapitalization, other.fCapitalization, sizeof(fCapitalization)); michael@0: } michael@0: michael@0: /** michael@0: * Assignment operator. michael@0: */ michael@0: DateFormatSymbols& DateFormatSymbols::operator=(const DateFormatSymbols& other) michael@0: { michael@0: dispose(); michael@0: copyData(other); michael@0: michael@0: return *this; michael@0: } michael@0: michael@0: DateFormatSymbols::~DateFormatSymbols() michael@0: { michael@0: dispose(); michael@0: } michael@0: michael@0: void DateFormatSymbols::dispose() michael@0: { michael@0: if (fEras) delete[] fEras; michael@0: if (fEraNames) delete[] fEraNames; michael@0: if (fNarrowEras) delete[] fNarrowEras; michael@0: if (fMonths) delete[] fMonths; michael@0: if (fShortMonths) delete[] fShortMonths; michael@0: if (fNarrowMonths) delete[] fNarrowMonths; michael@0: if (fStandaloneMonths) delete[] fStandaloneMonths; michael@0: if (fStandaloneShortMonths) delete[] fStandaloneShortMonths; michael@0: if (fStandaloneNarrowMonths) delete[] fStandaloneNarrowMonths; michael@0: if (fWeekdays) delete[] fWeekdays; michael@0: if (fShortWeekdays) delete[] fShortWeekdays; michael@0: if (fShorterWeekdays) delete[] fShorterWeekdays; michael@0: if (fNarrowWeekdays) delete[] fNarrowWeekdays; michael@0: if (fStandaloneWeekdays) delete[] fStandaloneWeekdays; michael@0: if (fStandaloneShortWeekdays) delete[] fStandaloneShortWeekdays; michael@0: if (fStandaloneShorterWeekdays) delete[] fStandaloneShorterWeekdays; michael@0: if (fStandaloneNarrowWeekdays) delete[] fStandaloneNarrowWeekdays; michael@0: if (fAmPms) delete[] fAmPms; michael@0: if (fQuarters) delete[] fQuarters; michael@0: if (fShortQuarters) delete[] fShortQuarters; michael@0: if (fStandaloneQuarters) delete[] fStandaloneQuarters; michael@0: if (fStandaloneShortQuarters) delete[] fStandaloneShortQuarters; michael@0: if (fLeapMonthPatterns) delete[] fLeapMonthPatterns; michael@0: if (fShortYearNames) delete[] fShortYearNames; michael@0: michael@0: disposeZoneStrings(); michael@0: } michael@0: michael@0: void DateFormatSymbols::disposeZoneStrings() michael@0: { michael@0: if (fZoneStrings) { michael@0: for (int32_t row = 0; row < fZoneStringsRowCount; ++row) { michael@0: delete[] fZoneStrings[row]; michael@0: } michael@0: uprv_free(fZoneStrings); michael@0: } michael@0: if (fLocaleZoneStrings) { michael@0: for (int32_t row = 0; row < fZoneStringsRowCount; ++row) { michael@0: delete[] fLocaleZoneStrings[row]; michael@0: } michael@0: uprv_free(fLocaleZoneStrings); michael@0: } michael@0: michael@0: fZoneStrings = NULL; michael@0: fLocaleZoneStrings = NULL; michael@0: fZoneStringsRowCount = 0; michael@0: fZoneStringsColCount = 0; michael@0: } michael@0: michael@0: UBool michael@0: DateFormatSymbols::arrayCompare(const UnicodeString* array1, michael@0: const UnicodeString* array2, michael@0: int32_t count) michael@0: { michael@0: if (array1 == array2) return TRUE; michael@0: while (count>0) michael@0: { michael@0: --count; michael@0: if (array1[count] != array2[count]) return FALSE; michael@0: } michael@0: return TRUE; michael@0: } michael@0: michael@0: UBool michael@0: DateFormatSymbols::operator==(const DateFormatSymbols& other) const michael@0: { michael@0: // First do cheap comparisons michael@0: if (this == &other) { michael@0: return TRUE; michael@0: } michael@0: if (fErasCount == other.fErasCount && michael@0: fEraNamesCount == other.fEraNamesCount && michael@0: fNarrowErasCount == other.fNarrowErasCount && michael@0: fMonthsCount == other.fMonthsCount && michael@0: fShortMonthsCount == other.fShortMonthsCount && michael@0: fNarrowMonthsCount == other.fNarrowMonthsCount && michael@0: fStandaloneMonthsCount == other.fStandaloneMonthsCount && michael@0: fStandaloneShortMonthsCount == other.fStandaloneShortMonthsCount && michael@0: fStandaloneNarrowMonthsCount == other.fStandaloneNarrowMonthsCount && michael@0: fWeekdaysCount == other.fWeekdaysCount && michael@0: fShortWeekdaysCount == other.fShortWeekdaysCount && michael@0: fShorterWeekdaysCount == other.fShorterWeekdaysCount && michael@0: fNarrowWeekdaysCount == other.fNarrowWeekdaysCount && michael@0: fStandaloneWeekdaysCount == other.fStandaloneWeekdaysCount && michael@0: fStandaloneShortWeekdaysCount == other.fStandaloneShortWeekdaysCount && michael@0: fStandaloneShorterWeekdaysCount == other.fStandaloneShorterWeekdaysCount && michael@0: fStandaloneNarrowWeekdaysCount == other.fStandaloneNarrowWeekdaysCount && michael@0: fAmPmsCount == other.fAmPmsCount && michael@0: fQuartersCount == other.fQuartersCount && michael@0: fShortQuartersCount == other.fShortQuartersCount && michael@0: fStandaloneQuartersCount == other.fStandaloneQuartersCount && michael@0: fStandaloneShortQuartersCount == other.fStandaloneShortQuartersCount && michael@0: fLeapMonthPatternsCount == other.fLeapMonthPatternsCount && michael@0: fShortYearNamesCount == other.fShortYearNamesCount && michael@0: (uprv_memcmp(fCapitalization, other.fCapitalization, sizeof(fCapitalization))==0)) michael@0: { michael@0: // Now compare the arrays themselves michael@0: if (arrayCompare(fEras, other.fEras, fErasCount) && michael@0: arrayCompare(fEraNames, other.fEraNames, fEraNamesCount) && michael@0: arrayCompare(fNarrowEras, other.fNarrowEras, fNarrowErasCount) && michael@0: arrayCompare(fMonths, other.fMonths, fMonthsCount) && michael@0: arrayCompare(fShortMonths, other.fShortMonths, fShortMonthsCount) && michael@0: arrayCompare(fNarrowMonths, other.fNarrowMonths, fNarrowMonthsCount) && michael@0: arrayCompare(fStandaloneMonths, other.fStandaloneMonths, fStandaloneMonthsCount) && michael@0: arrayCompare(fStandaloneShortMonths, other.fStandaloneShortMonths, fStandaloneShortMonthsCount) && michael@0: arrayCompare(fStandaloneNarrowMonths, other.fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount) && michael@0: arrayCompare(fWeekdays, other.fWeekdays, fWeekdaysCount) && michael@0: arrayCompare(fShortWeekdays, other.fShortWeekdays, fShortWeekdaysCount) && michael@0: arrayCompare(fShorterWeekdays, other.fShorterWeekdays, fShorterWeekdaysCount) && michael@0: arrayCompare(fNarrowWeekdays, other.fNarrowWeekdays, fNarrowWeekdaysCount) && michael@0: arrayCompare(fStandaloneWeekdays, other.fStandaloneWeekdays, fStandaloneWeekdaysCount) && michael@0: arrayCompare(fStandaloneShortWeekdays, other.fStandaloneShortWeekdays, fStandaloneShortWeekdaysCount) && michael@0: arrayCompare(fStandaloneShorterWeekdays, other.fStandaloneShorterWeekdays, fStandaloneShorterWeekdaysCount) && michael@0: arrayCompare(fStandaloneNarrowWeekdays, other.fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount) && michael@0: arrayCompare(fAmPms, other.fAmPms, fAmPmsCount) && michael@0: arrayCompare(fQuarters, other.fQuarters, fQuartersCount) && michael@0: arrayCompare(fShortQuarters, other.fShortQuarters, fShortQuartersCount) && michael@0: arrayCompare(fStandaloneQuarters, other.fStandaloneQuarters, fStandaloneQuartersCount) && michael@0: arrayCompare(fStandaloneShortQuarters, other.fStandaloneShortQuarters, fStandaloneShortQuartersCount) && michael@0: arrayCompare(fLeapMonthPatterns, other.fLeapMonthPatterns, fLeapMonthPatternsCount) && michael@0: arrayCompare(fShortYearNames, other.fShortYearNames, fShortYearNamesCount)) michael@0: { michael@0: // Compare the contents of fZoneStrings michael@0: if (fZoneStrings == NULL && other.fZoneStrings == NULL) { michael@0: if (fZSFLocale == other.fZSFLocale) { michael@0: return TRUE; michael@0: } michael@0: } else if (fZoneStrings != NULL && other.fZoneStrings != NULL) { michael@0: if (fZoneStringsRowCount == other.fZoneStringsRowCount michael@0: && fZoneStringsColCount == other.fZoneStringsColCount) { michael@0: UBool cmpres = TRUE; michael@0: for (int32_t i = 0; (i < fZoneStringsRowCount) && cmpres; i++) { michael@0: cmpres = arrayCompare(fZoneStrings[i], other.fZoneStrings[i], fZoneStringsColCount); michael@0: } michael@0: return cmpres; michael@0: } michael@0: } michael@0: return FALSE; michael@0: } michael@0: } michael@0: return FALSE; michael@0: } michael@0: michael@0: //------------------------------------------------------ michael@0: michael@0: const UnicodeString* michael@0: DateFormatSymbols::getEras(int32_t &count) const michael@0: { michael@0: count = fErasCount; michael@0: return fEras; michael@0: } michael@0: michael@0: const UnicodeString* michael@0: DateFormatSymbols::getEraNames(int32_t &count) const michael@0: { michael@0: count = fEraNamesCount; michael@0: return fEraNames; michael@0: } michael@0: michael@0: const UnicodeString* michael@0: DateFormatSymbols::getNarrowEras(int32_t &count) const michael@0: { michael@0: count = fNarrowErasCount; michael@0: return fNarrowEras; michael@0: } michael@0: michael@0: const UnicodeString* michael@0: DateFormatSymbols::getMonths(int32_t &count) const michael@0: { michael@0: count = fMonthsCount; michael@0: return fMonths; michael@0: } michael@0: michael@0: const UnicodeString* michael@0: DateFormatSymbols::getShortMonths(int32_t &count) const michael@0: { michael@0: count = fShortMonthsCount; michael@0: return fShortMonths; michael@0: } michael@0: michael@0: const UnicodeString* michael@0: DateFormatSymbols::getMonths(int32_t &count, DtContextType context, DtWidthType width ) const michael@0: { michael@0: UnicodeString *returnValue = NULL; michael@0: michael@0: switch (context) { michael@0: case FORMAT : michael@0: switch(width) { michael@0: case WIDE : michael@0: count = fMonthsCount; michael@0: returnValue = fMonths; michael@0: break; michael@0: case ABBREVIATED : michael@0: case SHORT : // no month data for this, defaults to ABBREVIATED michael@0: count = fShortMonthsCount; michael@0: returnValue = fShortMonths; michael@0: break; michael@0: case NARROW : michael@0: count = fNarrowMonthsCount; michael@0: returnValue = fNarrowMonths; michael@0: break; michael@0: case DT_WIDTH_COUNT : michael@0: break; michael@0: } michael@0: break; michael@0: case STANDALONE : michael@0: switch(width) { michael@0: case WIDE : michael@0: count = fStandaloneMonthsCount; michael@0: returnValue = fStandaloneMonths; michael@0: break; michael@0: case ABBREVIATED : michael@0: case SHORT : // no month data for this, defaults to ABBREVIATED michael@0: count = fStandaloneShortMonthsCount; michael@0: returnValue = fStandaloneShortMonths; michael@0: break; michael@0: case NARROW : michael@0: count = fStandaloneNarrowMonthsCount; michael@0: returnValue = fStandaloneNarrowMonths; michael@0: break; michael@0: case DT_WIDTH_COUNT : michael@0: break; michael@0: } michael@0: break; michael@0: case DT_CONTEXT_COUNT : michael@0: break; michael@0: } michael@0: return returnValue; michael@0: } michael@0: michael@0: const UnicodeString* michael@0: DateFormatSymbols::getWeekdays(int32_t &count) const michael@0: { michael@0: count = fWeekdaysCount; michael@0: return fWeekdays; michael@0: } michael@0: michael@0: const UnicodeString* michael@0: DateFormatSymbols::getShortWeekdays(int32_t &count) const michael@0: { michael@0: count = fShortWeekdaysCount; michael@0: return fShortWeekdays; michael@0: } michael@0: michael@0: const UnicodeString* michael@0: DateFormatSymbols::getWeekdays(int32_t &count, DtContextType context, DtWidthType width) const michael@0: { michael@0: UnicodeString *returnValue = NULL; michael@0: switch (context) { michael@0: case FORMAT : michael@0: switch(width) { michael@0: case WIDE : michael@0: count = fWeekdaysCount; michael@0: returnValue = fWeekdays; michael@0: break; michael@0: case ABBREVIATED : michael@0: count = fShortWeekdaysCount; michael@0: returnValue = fShortWeekdays; michael@0: break; michael@0: case SHORT : michael@0: count = fShorterWeekdaysCount; michael@0: returnValue = fShorterWeekdays; michael@0: break; michael@0: case NARROW : michael@0: count = fNarrowWeekdaysCount; michael@0: returnValue = fNarrowWeekdays; michael@0: break; michael@0: case DT_WIDTH_COUNT : michael@0: break; michael@0: } michael@0: break; michael@0: case STANDALONE : michael@0: switch(width) { michael@0: case WIDE : michael@0: count = fStandaloneWeekdaysCount; michael@0: returnValue = fStandaloneWeekdays; michael@0: break; michael@0: case ABBREVIATED : michael@0: count = fStandaloneShortWeekdaysCount; michael@0: returnValue = fStandaloneShortWeekdays; michael@0: break; michael@0: case SHORT : michael@0: count = fStandaloneShorterWeekdaysCount; michael@0: returnValue = fStandaloneShorterWeekdays; michael@0: break; michael@0: case NARROW : michael@0: count = fStandaloneNarrowWeekdaysCount; michael@0: returnValue = fStandaloneNarrowWeekdays; michael@0: break; michael@0: case DT_WIDTH_COUNT : michael@0: break; michael@0: } michael@0: break; michael@0: case DT_CONTEXT_COUNT : michael@0: break; michael@0: } michael@0: return returnValue; michael@0: } michael@0: michael@0: const UnicodeString* michael@0: DateFormatSymbols::getQuarters(int32_t &count, DtContextType context, DtWidthType width ) const michael@0: { michael@0: UnicodeString *returnValue = NULL; michael@0: michael@0: switch (context) { michael@0: case FORMAT : michael@0: switch(width) { michael@0: case WIDE : michael@0: count = fQuartersCount; michael@0: returnValue = fQuarters; michael@0: break; michael@0: case ABBREVIATED : michael@0: case SHORT : // no quarter data for this, defaults to ABBREVIATED michael@0: count = fShortQuartersCount; michael@0: returnValue = fShortQuarters; michael@0: break; michael@0: case NARROW : michael@0: count = 0; michael@0: returnValue = NULL; michael@0: break; michael@0: case DT_WIDTH_COUNT : michael@0: break; michael@0: } michael@0: break; michael@0: case STANDALONE : michael@0: switch(width) { michael@0: case WIDE : michael@0: count = fStandaloneQuartersCount; michael@0: returnValue = fStandaloneQuarters; michael@0: break; michael@0: case ABBREVIATED : michael@0: case SHORT : // no quarter data for this, defaults to ABBREVIATED michael@0: count = fStandaloneShortQuartersCount; michael@0: returnValue = fStandaloneShortQuarters; michael@0: break; michael@0: case NARROW : michael@0: count = 0; michael@0: returnValue = NULL; michael@0: break; michael@0: case DT_WIDTH_COUNT : michael@0: break; michael@0: } michael@0: break; michael@0: case DT_CONTEXT_COUNT : michael@0: break; michael@0: } michael@0: return returnValue; michael@0: } michael@0: michael@0: const UnicodeString* michael@0: DateFormatSymbols::getAmPmStrings(int32_t &count) const michael@0: { michael@0: count = fAmPmsCount; michael@0: return fAmPms; michael@0: } michael@0: michael@0: const UnicodeString* michael@0: DateFormatSymbols::getLeapMonthPatterns(int32_t &count) const michael@0: { michael@0: count = fLeapMonthPatternsCount; michael@0: return fLeapMonthPatterns; michael@0: } michael@0: michael@0: //------------------------------------------------------ michael@0: michael@0: void michael@0: DateFormatSymbols::setEras(const UnicodeString* erasArray, int32_t count) michael@0: { michael@0: // delete the old list if we own it michael@0: if (fEras) michael@0: delete[] fEras; michael@0: michael@0: // we always own the new list, which we create here (we duplicate rather michael@0: // than adopting the list passed in) michael@0: fEras = newUnicodeStringArray(count); michael@0: uprv_arrayCopy(erasArray,fEras, count); michael@0: fErasCount = count; michael@0: } michael@0: michael@0: void michael@0: DateFormatSymbols::setEraNames(const UnicodeString* eraNamesArray, int32_t count) michael@0: { michael@0: // delete the old list if we own it michael@0: if (fEraNames) michael@0: delete[] fEraNames; michael@0: michael@0: // we always own the new list, which we create here (we duplicate rather michael@0: // than adopting the list passed in) michael@0: fEraNames = newUnicodeStringArray(count); michael@0: uprv_arrayCopy(eraNamesArray,fEraNames, count); michael@0: fEraNamesCount = count; michael@0: } michael@0: michael@0: void michael@0: DateFormatSymbols::setNarrowEras(const UnicodeString* narrowErasArray, int32_t count) michael@0: { michael@0: // delete the old list if we own it michael@0: if (fNarrowEras) michael@0: delete[] fNarrowEras; michael@0: michael@0: // we always own the new list, which we create here (we duplicate rather michael@0: // than adopting the list passed in) michael@0: fNarrowEras = newUnicodeStringArray(count); michael@0: uprv_arrayCopy(narrowErasArray,fNarrowEras, count); michael@0: fNarrowErasCount = count; michael@0: } michael@0: michael@0: void michael@0: DateFormatSymbols::setMonths(const UnicodeString* monthsArray, int32_t count) michael@0: { michael@0: // delete the old list if we own it michael@0: if (fMonths) michael@0: delete[] fMonths; michael@0: michael@0: // we always own the new list, which we create here (we duplicate rather michael@0: // than adopting the list passed in) michael@0: fMonths = newUnicodeStringArray(count); michael@0: uprv_arrayCopy( monthsArray,fMonths,count); michael@0: fMonthsCount = count; michael@0: } michael@0: michael@0: void michael@0: DateFormatSymbols::setShortMonths(const UnicodeString* shortMonthsArray, int32_t count) michael@0: { michael@0: // delete the old list if we own it michael@0: if (fShortMonths) michael@0: delete[] fShortMonths; michael@0: michael@0: // we always own the new list, which we create here (we duplicate rather michael@0: // than adopting the list passed in) michael@0: fShortMonths = newUnicodeStringArray(count); michael@0: uprv_arrayCopy(shortMonthsArray,fShortMonths, count); michael@0: fShortMonthsCount = count; michael@0: } michael@0: michael@0: void michael@0: DateFormatSymbols::setMonths(const UnicodeString* monthsArray, int32_t count, DtContextType context, DtWidthType width) michael@0: { michael@0: // delete the old list if we own it michael@0: // we always own the new list, which we create here (we duplicate rather michael@0: // than adopting the list passed in) michael@0: michael@0: switch (context) { michael@0: case FORMAT : michael@0: switch (width) { michael@0: case WIDE : michael@0: if (fMonths) michael@0: delete[] fMonths; michael@0: fMonths = newUnicodeStringArray(count); michael@0: uprv_arrayCopy( monthsArray,fMonths,count); michael@0: fMonthsCount = count; michael@0: break; michael@0: case ABBREVIATED : michael@0: if (fShortMonths) michael@0: delete[] fShortMonths; michael@0: fShortMonths = newUnicodeStringArray(count); michael@0: uprv_arrayCopy( monthsArray,fShortMonths,count); michael@0: fShortMonthsCount = count; michael@0: break; michael@0: case NARROW : michael@0: if (fNarrowMonths) michael@0: delete[] fNarrowMonths; michael@0: fNarrowMonths = newUnicodeStringArray(count); michael@0: uprv_arrayCopy( monthsArray,fNarrowMonths,count); michael@0: fNarrowMonthsCount = count; michael@0: break; michael@0: default : michael@0: break; michael@0: } michael@0: break; michael@0: case STANDALONE : michael@0: switch (width) { michael@0: case WIDE : michael@0: if (fStandaloneMonths) michael@0: delete[] fStandaloneMonths; michael@0: fStandaloneMonths = newUnicodeStringArray(count); michael@0: uprv_arrayCopy( monthsArray,fStandaloneMonths,count); michael@0: fStandaloneMonthsCount = count; michael@0: break; michael@0: case ABBREVIATED : michael@0: if (fStandaloneShortMonths) michael@0: delete[] fStandaloneShortMonths; michael@0: fStandaloneShortMonths = newUnicodeStringArray(count); michael@0: uprv_arrayCopy( monthsArray,fStandaloneShortMonths,count); michael@0: fStandaloneShortMonthsCount = count; michael@0: break; michael@0: case NARROW : michael@0: if (fStandaloneNarrowMonths) michael@0: delete[] fStandaloneNarrowMonths; michael@0: fStandaloneNarrowMonths = newUnicodeStringArray(count); michael@0: uprv_arrayCopy( monthsArray,fStandaloneNarrowMonths,count); michael@0: fStandaloneNarrowMonthsCount = count; michael@0: break; michael@0: default : michael@0: break; michael@0: } michael@0: break; michael@0: case DT_CONTEXT_COUNT : michael@0: break; michael@0: } michael@0: } michael@0: michael@0: void DateFormatSymbols::setWeekdays(const UnicodeString* weekdaysArray, int32_t count) michael@0: { michael@0: // delete the old list if we own it michael@0: if (fWeekdays) michael@0: delete[] fWeekdays; michael@0: michael@0: // we always own the new list, which we create here (we duplicate rather michael@0: // than adopting the list passed in) michael@0: fWeekdays = newUnicodeStringArray(count); michael@0: uprv_arrayCopy(weekdaysArray,fWeekdays,count); michael@0: fWeekdaysCount = count; michael@0: } michael@0: michael@0: void michael@0: DateFormatSymbols::setShortWeekdays(const UnicodeString* shortWeekdaysArray, int32_t count) michael@0: { michael@0: // delete the old list if we own it michael@0: if (fShortWeekdays) michael@0: delete[] fShortWeekdays; michael@0: michael@0: // we always own the new list, which we create here (we duplicate rather michael@0: // than adopting the list passed in) michael@0: fShortWeekdays = newUnicodeStringArray(count); michael@0: uprv_arrayCopy(shortWeekdaysArray, fShortWeekdays, count); michael@0: fShortWeekdaysCount = count; michael@0: } michael@0: michael@0: void michael@0: DateFormatSymbols::setWeekdays(const UnicodeString* weekdaysArray, int32_t count, DtContextType context, DtWidthType width) michael@0: { michael@0: // delete the old list if we own it michael@0: // we always own the new list, which we create here (we duplicate rather michael@0: // than adopting the list passed in) michael@0: michael@0: switch (context) { michael@0: case FORMAT : michael@0: switch (width) { michael@0: case WIDE : michael@0: if (fWeekdays) michael@0: delete[] fWeekdays; michael@0: fWeekdays = newUnicodeStringArray(count); michael@0: uprv_arrayCopy(weekdaysArray, fWeekdays, count); michael@0: fWeekdaysCount = count; michael@0: break; michael@0: case ABBREVIATED : michael@0: if (fShortWeekdays) michael@0: delete[] fShortWeekdays; michael@0: fShortWeekdays = newUnicodeStringArray(count); michael@0: uprv_arrayCopy(weekdaysArray, fShortWeekdays, count); michael@0: fShortWeekdaysCount = count; michael@0: break; michael@0: case SHORT : michael@0: if (fShorterWeekdays) michael@0: delete[] fShorterWeekdays; michael@0: fShorterWeekdays = newUnicodeStringArray(count); michael@0: uprv_arrayCopy(weekdaysArray, fShorterWeekdays, count); michael@0: fShorterWeekdaysCount = count; michael@0: break; michael@0: case NARROW : michael@0: if (fNarrowWeekdays) michael@0: delete[] fNarrowWeekdays; michael@0: fNarrowWeekdays = newUnicodeStringArray(count); michael@0: uprv_arrayCopy(weekdaysArray, fNarrowWeekdays, count); michael@0: fNarrowWeekdaysCount = count; michael@0: break; michael@0: case DT_WIDTH_COUNT : michael@0: break; michael@0: } michael@0: break; michael@0: case STANDALONE : michael@0: switch (width) { michael@0: case WIDE : michael@0: if (fStandaloneWeekdays) michael@0: delete[] fStandaloneWeekdays; michael@0: fStandaloneWeekdays = newUnicodeStringArray(count); michael@0: uprv_arrayCopy(weekdaysArray, fStandaloneWeekdays, count); michael@0: fStandaloneWeekdaysCount = count; michael@0: break; michael@0: case ABBREVIATED : michael@0: if (fStandaloneShortWeekdays) michael@0: delete[] fStandaloneShortWeekdays; michael@0: fStandaloneShortWeekdays = newUnicodeStringArray(count); michael@0: uprv_arrayCopy(weekdaysArray, fStandaloneShortWeekdays, count); michael@0: fStandaloneShortWeekdaysCount = count; michael@0: break; michael@0: case SHORT : michael@0: if (fStandaloneShorterWeekdays) michael@0: delete[] fStandaloneShorterWeekdays; michael@0: fStandaloneShorterWeekdays = newUnicodeStringArray(count); michael@0: uprv_arrayCopy(weekdaysArray, fStandaloneShorterWeekdays, count); michael@0: fStandaloneShorterWeekdaysCount = count; michael@0: break; michael@0: case NARROW : michael@0: if (fStandaloneNarrowWeekdays) michael@0: delete[] fStandaloneNarrowWeekdays; michael@0: fStandaloneNarrowWeekdays = newUnicodeStringArray(count); michael@0: uprv_arrayCopy(weekdaysArray, fStandaloneNarrowWeekdays, count); michael@0: fStandaloneNarrowWeekdaysCount = count; michael@0: break; michael@0: case DT_WIDTH_COUNT : michael@0: break; michael@0: } michael@0: break; michael@0: case DT_CONTEXT_COUNT : michael@0: break; michael@0: } michael@0: } michael@0: michael@0: void michael@0: DateFormatSymbols::setQuarters(const UnicodeString* quartersArray, int32_t count, DtContextType context, DtWidthType width) michael@0: { michael@0: // delete the old list if we own it michael@0: // we always own the new list, which we create here (we duplicate rather michael@0: // than adopting the list passed in) michael@0: michael@0: switch (context) { michael@0: case FORMAT : michael@0: switch (width) { michael@0: case WIDE : michael@0: if (fQuarters) michael@0: delete[] fQuarters; michael@0: fQuarters = newUnicodeStringArray(count); michael@0: uprv_arrayCopy( quartersArray,fQuarters,count); michael@0: fQuartersCount = count; michael@0: break; michael@0: case ABBREVIATED : michael@0: if (fShortQuarters) michael@0: delete[] fShortQuarters; michael@0: fShortQuarters = newUnicodeStringArray(count); michael@0: uprv_arrayCopy( quartersArray,fShortQuarters,count); michael@0: fShortQuartersCount = count; michael@0: break; michael@0: case NARROW : michael@0: /* michael@0: if (fNarrowQuarters) michael@0: delete[] fNarrowQuarters; michael@0: fNarrowQuarters = newUnicodeStringArray(count); michael@0: uprv_arrayCopy( quartersArray,fNarrowQuarters,count); michael@0: fNarrowQuartersCount = count; michael@0: */ michael@0: break; michael@0: default : michael@0: break; michael@0: } michael@0: break; michael@0: case STANDALONE : michael@0: switch (width) { michael@0: case WIDE : michael@0: if (fStandaloneQuarters) michael@0: delete[] fStandaloneQuarters; michael@0: fStandaloneQuarters = newUnicodeStringArray(count); michael@0: uprv_arrayCopy( quartersArray,fStandaloneQuarters,count); michael@0: fStandaloneQuartersCount = count; michael@0: break; michael@0: case ABBREVIATED : michael@0: if (fStandaloneShortQuarters) michael@0: delete[] fStandaloneShortQuarters; michael@0: fStandaloneShortQuarters = newUnicodeStringArray(count); michael@0: uprv_arrayCopy( quartersArray,fStandaloneShortQuarters,count); michael@0: fStandaloneShortQuartersCount = count; michael@0: break; michael@0: case NARROW : michael@0: /* michael@0: if (fStandaloneNarrowQuarters) michael@0: delete[] fStandaloneNarrowQuarters; michael@0: fStandaloneNarrowQuarters = newUnicodeStringArray(count); michael@0: uprv_arrayCopy( quartersArray,fStandaloneNarrowQuarters,count); michael@0: fStandaloneNarrowQuartersCount = count; michael@0: */ michael@0: break; michael@0: default : michael@0: break; michael@0: } michael@0: break; michael@0: case DT_CONTEXT_COUNT : michael@0: break; michael@0: } michael@0: } michael@0: michael@0: void michael@0: DateFormatSymbols::setAmPmStrings(const UnicodeString* amPmsArray, int32_t count) michael@0: { michael@0: // delete the old list if we own it michael@0: if (fAmPms) delete[] fAmPms; michael@0: michael@0: // we always own the new list, which we create here (we duplicate rather michael@0: // than adopting the list passed in) michael@0: fAmPms = newUnicodeStringArray(count); michael@0: uprv_arrayCopy(amPmsArray,fAmPms,count); michael@0: fAmPmsCount = count; michael@0: } michael@0: michael@0: const UnicodeString** michael@0: DateFormatSymbols::getZoneStrings(int32_t& rowCount, int32_t& columnCount) const michael@0: { michael@0: const UnicodeString **result = NULL; michael@0: michael@0: umtx_lock(&LOCK); michael@0: if (fZoneStrings == NULL) { michael@0: if (fLocaleZoneStrings == NULL) { michael@0: ((DateFormatSymbols*)this)->initZoneStringsArray(); michael@0: } michael@0: result = (const UnicodeString**)fLocaleZoneStrings; michael@0: } else { michael@0: result = (const UnicodeString**)fZoneStrings; michael@0: } michael@0: rowCount = fZoneStringsRowCount; michael@0: columnCount = fZoneStringsColCount; michael@0: umtx_unlock(&LOCK); michael@0: michael@0: return result; michael@0: } michael@0: michael@0: // For now, we include all zones michael@0: #define ZONE_SET UCAL_ZONE_TYPE_ANY michael@0: michael@0: // This code must be called within a synchronized block michael@0: void michael@0: DateFormatSymbols::initZoneStringsArray(void) { michael@0: if (fZoneStrings != NULL || fLocaleZoneStrings != NULL) { michael@0: return; michael@0: } michael@0: michael@0: UErrorCode status = U_ZERO_ERROR; michael@0: michael@0: StringEnumeration *tzids = NULL; michael@0: UnicodeString ** zarray = NULL; michael@0: TimeZoneNames *tzNames = NULL; michael@0: int32_t rows = 0; michael@0: michael@0: do { // dummy do-while michael@0: michael@0: tzids = TimeZone::createTimeZoneIDEnumeration(ZONE_SET, NULL, NULL, status); michael@0: rows = tzids->count(status); michael@0: if (U_FAILURE(status)) { michael@0: break; michael@0: } michael@0: michael@0: // Allocate array michael@0: int32_t size = rows * sizeof(UnicodeString*); michael@0: zarray = (UnicodeString**)uprv_malloc(size); michael@0: if (zarray == NULL) { michael@0: status = U_MEMORY_ALLOCATION_ERROR; michael@0: break; michael@0: } michael@0: uprv_memset(zarray, 0, size); michael@0: michael@0: tzNames = TimeZoneNames::createInstance(fZSFLocale, status); michael@0: michael@0: const UnicodeString *tzid; michael@0: int32_t i = 0; michael@0: UDate now = Calendar::getNow(); michael@0: UnicodeString tzDispName; michael@0: michael@0: while ((tzid = tzids->snext(status))) { michael@0: if (U_FAILURE(status)) { michael@0: break; michael@0: } michael@0: michael@0: zarray[i] = new UnicodeString[5]; michael@0: if (zarray[i] == NULL) { michael@0: status = U_MEMORY_ALLOCATION_ERROR; michael@0: break; michael@0: } michael@0: michael@0: zarray[i][0].setTo(*tzid); michael@0: zarray[i][1].setTo(tzNames->getDisplayName(*tzid, UTZNM_LONG_STANDARD, now, tzDispName)); michael@0: zarray[i][2].setTo(tzNames->getDisplayName(*tzid, UTZNM_SHORT_STANDARD, now, tzDispName)); michael@0: zarray[i][3].setTo(tzNames->getDisplayName(*tzid, UTZNM_LONG_DAYLIGHT, now, tzDispName)); michael@0: zarray[i][4].setTo(tzNames->getDisplayName(*tzid, UTZNM_SHORT_DAYLIGHT, now, tzDispName)); michael@0: i++; michael@0: } michael@0: michael@0: } while (FALSE); michael@0: michael@0: if (U_FAILURE(status)) { michael@0: if (zarray) { michael@0: for (int32_t i = 0; i < rows; i++) { michael@0: if (zarray[i]) { michael@0: delete[] zarray[i]; michael@0: } michael@0: } michael@0: uprv_free(zarray); michael@0: } michael@0: } michael@0: michael@0: if (tzNames) { michael@0: delete tzNames; michael@0: } michael@0: if (tzids) { michael@0: delete tzids; michael@0: } michael@0: michael@0: fLocaleZoneStrings = zarray; michael@0: fZoneStringsRowCount = rows; michael@0: fZoneStringsColCount = 5; michael@0: } michael@0: michael@0: void michael@0: DateFormatSymbols::setZoneStrings(const UnicodeString* const *strings, int32_t rowCount, int32_t columnCount) michael@0: { michael@0: // since deleting a 2-d array is a pain in the butt, we offload that task to michael@0: // a separate function michael@0: disposeZoneStrings(); michael@0: // we always own the new list, which we create here (we duplicate rather michael@0: // than adopting the list passed in) michael@0: fZoneStringsRowCount = rowCount; michael@0: fZoneStringsColCount = columnCount; michael@0: createZoneStrings((const UnicodeString**)strings); michael@0: } michael@0: michael@0: //------------------------------------------------------ michael@0: michael@0: const UChar * U_EXPORT2 michael@0: DateFormatSymbols::getPatternUChars(void) michael@0: { michael@0: return gPatternChars; michael@0: } michael@0: michael@0: UDateFormatField U_EXPORT2 michael@0: DateFormatSymbols::getPatternCharIndex(UChar c) { michael@0: const UChar *p = u_strchr(gPatternChars, c); michael@0: if (p == NULL) { michael@0: return UDAT_FIELD_COUNT; michael@0: } else { michael@0: return static_cast(p - gPatternChars); michael@0: } michael@0: } michael@0: michael@0: static const uint32_t kNumericFields = michael@0: ((uint32_t)1 << UDAT_YEAR_FIELD) | // y michael@0: ((uint32_t)1 << UDAT_MONTH_FIELD) | // M or MM michael@0: ((uint32_t)1 << UDAT_DATE_FIELD) | // d michael@0: ((uint32_t)1 << UDAT_HOUR_OF_DAY1_FIELD) | // k michael@0: ((uint32_t)1 << UDAT_HOUR_OF_DAY0_FIELD) | // H michael@0: ((uint32_t)1 << UDAT_MINUTE_FIELD) | // m michael@0: ((uint32_t)1 << UDAT_SECOND_FIELD) | // s michael@0: ((uint32_t)1 << UDAT_FRACTIONAL_SECOND_FIELD) | // S michael@0: ((uint32_t)1 << UDAT_DAY_OF_YEAR_FIELD) | // D michael@0: ((uint32_t)1 << UDAT_DAY_OF_WEEK_IN_MONTH_FIELD) | // F michael@0: ((uint32_t)1 << UDAT_WEEK_OF_YEAR_FIELD) | // w michael@0: ((uint32_t)1 << UDAT_WEEK_OF_MONTH_FIELD) | // W michael@0: ((uint32_t)1 << UDAT_HOUR1_FIELD) | // h michael@0: ((uint32_t)1 << UDAT_HOUR0_FIELD) | // K michael@0: ((uint32_t)1 << UDAT_YEAR_WOY_FIELD) | // Y michael@0: ((uint32_t)1 << UDAT_DOW_LOCAL_FIELD) | // e michael@0: ((uint32_t)1 << UDAT_EXTENDED_YEAR_FIELD); // u michael@0: michael@0: UBool U_EXPORT2 michael@0: DateFormatSymbols::isNumericField(UDateFormatField f, int32_t count) { michael@0: return michael@0: f != UDAT_FIELD_COUNT && michael@0: (kNumericFields & ((uint32_t)1 << f)) != 0 && michael@0: (f != UDAT_MONTH_FIELD || count < 3); michael@0: } michael@0: michael@0: UBool U_EXPORT2 michael@0: DateFormatSymbols::isNumericPatternChar(UChar c, int32_t count) { michael@0: return isNumericField(getPatternCharIndex(c), count); michael@0: } michael@0: michael@0: //------------------------------------------------------ michael@0: michael@0: UnicodeString& michael@0: DateFormatSymbols::getLocalPatternChars(UnicodeString& result) const michael@0: { michael@0: // fastCopyFrom() - see assignArray comments michael@0: return result.fastCopyFrom(fLocalPatternChars); michael@0: } michael@0: michael@0: //------------------------------------------------------ michael@0: michael@0: void michael@0: DateFormatSymbols::setLocalPatternChars(const UnicodeString& newLocalPatternChars) michael@0: { michael@0: fLocalPatternChars = newLocalPatternChars; michael@0: } michael@0: michael@0: //------------------------------------------------------ michael@0: michael@0: static void michael@0: initField(UnicodeString **field, int32_t& length, const UResourceBundle *data, UErrorCode &status) { michael@0: if (U_SUCCESS(status)) { michael@0: int32_t strLen = 0; michael@0: length = ures_getSize(data); michael@0: *field = newUnicodeStringArray(length); michael@0: if (*field) { michael@0: for(int32_t i = 0; isetTo(TRUE, resStr, strLen); michael@0: } michael@0: } michael@0: else { michael@0: length = 0; michael@0: status = U_MEMORY_ALLOCATION_ERROR; michael@0: } michael@0: } michael@0: } michael@0: michael@0: static void michael@0: initField(UnicodeString **field, int32_t& length, const UChar *data, LastResortSize numStr, LastResortSize strLen, UErrorCode &status) { michael@0: if (U_SUCCESS(status)) { michael@0: length = numStr; michael@0: *field = newUnicodeStringArray((size_t)numStr); michael@0: if (*field) { michael@0: for(int32_t i = 0; isetTo(TRUE, data+(i*((int32_t)strLen)), -1); michael@0: } michael@0: } michael@0: else { michael@0: length = 0; michael@0: status = U_MEMORY_ALLOCATION_ERROR; michael@0: } michael@0: } michael@0: } michael@0: michael@0: static void michael@0: initLeapMonthPattern(UnicodeString *field, int32_t index, const UResourceBundle *data, UErrorCode &status) { michael@0: field[index].remove(); michael@0: if (U_SUCCESS(status)) { michael@0: int32_t strLen = 0; michael@0: const UChar *resStr = ures_getStringByKey(data, gNamesLeapTag, &strLen, &status); michael@0: if (U_SUCCESS(status)) { michael@0: field[index].setTo(TRUE, resStr, strLen); michael@0: } michael@0: } michael@0: status = U_ZERO_ERROR; michael@0: } michael@0: michael@0: typedef struct { michael@0: const char * usageTypeName; michael@0: DateFormatSymbols::ECapitalizationContextUsageType usageTypeEnumValue; michael@0: } ContextUsageTypeNameToEnumValue; michael@0: michael@0: static const ContextUsageTypeNameToEnumValue contextUsageTypeMap[] = { michael@0: // Entries must be sorted by usageTypeName; entry with NULL name terminates list. michael@0: { "day-format-except-narrow", DateFormatSymbols::kCapContextUsageDayFormat }, michael@0: { "day-narrow", DateFormatSymbols::kCapContextUsageDayNarrow }, michael@0: { "day-standalone-except-narrow", DateFormatSymbols::kCapContextUsageDayStandalone }, michael@0: { "era-abbr", DateFormatSymbols::kCapContextUsageEraAbbrev }, michael@0: { "era-name", DateFormatSymbols::kCapContextUsageEraWide }, michael@0: { "era-narrow", DateFormatSymbols::kCapContextUsageEraNarrow }, michael@0: { "metazone-long", DateFormatSymbols::kCapContextUsageMetazoneLong }, michael@0: { "metazone-short", DateFormatSymbols::kCapContextUsageMetazoneShort }, michael@0: { "month-format-except-narrow", DateFormatSymbols::kCapContextUsageMonthFormat }, michael@0: { "month-narrow", DateFormatSymbols::kCapContextUsageMonthNarrow }, michael@0: { "month-standalone-except-narrow", DateFormatSymbols::kCapContextUsageMonthStandalone }, michael@0: { "zone-long", DateFormatSymbols::kCapContextUsageZoneLong }, michael@0: { "zone-short", DateFormatSymbols::kCapContextUsageZoneShort }, michael@0: { NULL, (DateFormatSymbols::ECapitalizationContextUsageType)0 }, michael@0: }; michael@0: michael@0: void michael@0: DateFormatSymbols::initializeData(const Locale& locale, const char *type, UErrorCode& status, UBool useLastResortData) michael@0: { michael@0: int32_t i; michael@0: int32_t len = 0; michael@0: const UChar *resStr; michael@0: /* In case something goes wrong, initialize all of the data to NULL. */ michael@0: fEras = NULL; michael@0: fErasCount = 0; michael@0: fEraNames = NULL; michael@0: fEraNamesCount = 0; michael@0: fNarrowEras = NULL; michael@0: fNarrowErasCount = 0; michael@0: fMonths = NULL; michael@0: fMonthsCount=0; michael@0: fShortMonths = NULL; michael@0: fShortMonthsCount=0; michael@0: fNarrowMonths = NULL; michael@0: fNarrowMonthsCount=0; michael@0: fStandaloneMonths = NULL; michael@0: fStandaloneMonthsCount=0; michael@0: fStandaloneShortMonths = NULL; michael@0: fStandaloneShortMonthsCount=0; michael@0: fStandaloneNarrowMonths = NULL; michael@0: fStandaloneNarrowMonthsCount=0; michael@0: fWeekdays = NULL; michael@0: fWeekdaysCount=0; michael@0: fShortWeekdays = NULL; michael@0: fShortWeekdaysCount=0; michael@0: fShorterWeekdays = NULL; michael@0: fShorterWeekdaysCount=0; michael@0: fNarrowWeekdays = NULL; michael@0: fNarrowWeekdaysCount=0; michael@0: fStandaloneWeekdays = NULL; michael@0: fStandaloneWeekdaysCount=0; michael@0: fStandaloneShortWeekdays = NULL; michael@0: fStandaloneShortWeekdaysCount=0; michael@0: fStandaloneShorterWeekdays = NULL; michael@0: fStandaloneShorterWeekdaysCount=0; michael@0: fStandaloneNarrowWeekdays = NULL; michael@0: fStandaloneNarrowWeekdaysCount=0; michael@0: fAmPms = NULL; michael@0: fAmPmsCount=0; michael@0: fQuarters = NULL; michael@0: fQuartersCount = 0; michael@0: fShortQuarters = NULL; michael@0: fShortQuartersCount = 0; michael@0: fStandaloneQuarters = NULL; michael@0: fStandaloneQuartersCount = 0; michael@0: fStandaloneShortQuarters = NULL; michael@0: fStandaloneShortQuartersCount = 0; michael@0: fLeapMonthPatterns = NULL; michael@0: fLeapMonthPatternsCount = 0; michael@0: fShortYearNames = NULL; michael@0: fShortYearNamesCount = 0; michael@0: fZoneStringsRowCount = 0; michael@0: fZoneStringsColCount = 0; michael@0: fZoneStrings = NULL; michael@0: fLocaleZoneStrings = NULL; michael@0: uprv_memset(fCapitalization, 0, sizeof(fCapitalization)); michael@0: michael@0: // We need to preserve the requested locale for michael@0: // lazy ZoneStringFormat instantiation. ZoneStringFormat michael@0: // is region sensitive, thus, bundle locale bundle's locale michael@0: // is not sufficient. michael@0: fZSFLocale = locale; michael@0: michael@0: if (U_FAILURE(status)) return; michael@0: michael@0: /** michael@0: * Retrieve the string arrays we need from the resource bundle file. michael@0: * We cast away const here, but that's okay; we won't delete any of michael@0: * these. michael@0: */ michael@0: CalendarData calData(locale, type, status); michael@0: michael@0: // load the first data item michael@0: UResourceBundle *erasMain = calData.getByKey(gErasTag, status); michael@0: UResourceBundle *eras = ures_getByKeyWithFallback(erasMain, gNamesAbbrTag, NULL, &status); michael@0: UErrorCode oldStatus = status; michael@0: UResourceBundle *eraNames = ures_getByKeyWithFallback(erasMain, gNamesWideTag, NULL, &status); michael@0: if ( status == U_MISSING_RESOURCE_ERROR ) { // Workaround because eras/wide was omitted from CLDR 1.3 michael@0: status = oldStatus; michael@0: eraNames = ures_getByKeyWithFallback(erasMain, gNamesAbbrTag, NULL, &status); michael@0: } michael@0: // current ICU4J falls back to abbreviated if narrow eras are missing, so we will too michael@0: oldStatus = status; michael@0: UResourceBundle *narrowEras = ures_getByKeyWithFallback(erasMain, gNamesNarrowTag, NULL, &status); michael@0: if ( status == U_MISSING_RESOURCE_ERROR ) { michael@0: status = oldStatus; michael@0: narrowEras = ures_getByKeyWithFallback(erasMain, gNamesAbbrTag, NULL, &status); michael@0: } michael@0: michael@0: UErrorCode tempStatus = U_ZERO_ERROR; michael@0: UResourceBundle *monthPatterns = calData.getByKey(gMonthPatternsTag, tempStatus); michael@0: if (U_SUCCESS(tempStatus) && monthPatterns != NULL) { michael@0: fLeapMonthPatterns = newUnicodeStringArray(kMonthPatternsCount); michael@0: if (fLeapMonthPatterns) { michael@0: initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternFormatWide, calData.getByKey2(gMonthPatternsTag, gNamesWideTag, tempStatus), tempStatus); michael@0: initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternFormatAbbrev, calData.getByKey2(gMonthPatternsTag, gNamesAbbrTag, tempStatus), tempStatus); michael@0: initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternFormatNarrow, calData.getByKey2(gMonthPatternsTag, gNamesNarrowTag, tempStatus), tempStatus); michael@0: initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternStandaloneWide, calData.getByKey3(gMonthPatternsTag, gNamesStandaloneTag, gNamesWideTag, tempStatus), tempStatus); michael@0: initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternStandaloneAbbrev, calData.getByKey3(gMonthPatternsTag, gNamesStandaloneTag, gNamesAbbrTag, tempStatus), tempStatus); michael@0: initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternStandaloneNarrow, calData.getByKey3(gMonthPatternsTag, gNamesStandaloneTag, gNamesNarrowTag, tempStatus), tempStatus); michael@0: initLeapMonthPattern(fLeapMonthPatterns, kLeapMonthPatternNumeric, calData.getByKey3(gMonthPatternsTag, gNamesNumericTag, gNamesAllTag, tempStatus), tempStatus); michael@0: if (U_SUCCESS(tempStatus)) { michael@0: fLeapMonthPatternsCount = kMonthPatternsCount; michael@0: } else { michael@0: delete[] fLeapMonthPatterns; michael@0: fLeapMonthPatterns = NULL; michael@0: } michael@0: } michael@0: } michael@0: michael@0: tempStatus = U_ZERO_ERROR; michael@0: UResourceBundle *cyclicNameSets= calData.getByKey(gCyclicNameSetsTag, tempStatus); michael@0: if (U_SUCCESS(tempStatus) && cyclicNameSets != NULL) { michael@0: UResourceBundle *nameSetYears = ures_getByKeyWithFallback(cyclicNameSets, gNameSetYearsTag, NULL, &tempStatus); michael@0: if (U_SUCCESS(tempStatus)) { michael@0: UResourceBundle *nameSetYearsFmt = ures_getByKeyWithFallback(nameSetYears, gNamesFormatTag, NULL, &tempStatus); michael@0: if (U_SUCCESS(tempStatus)) { michael@0: UResourceBundle *nameSetYearsFmtAbbrev = ures_getByKeyWithFallback(nameSetYearsFmt, gNamesAbbrTag, NULL, &tempStatus); michael@0: if (U_SUCCESS(tempStatus)) { michael@0: initField(&fShortYearNames, fShortYearNamesCount, nameSetYearsFmtAbbrev, tempStatus); michael@0: ures_close(nameSetYearsFmtAbbrev); michael@0: } michael@0: ures_close(nameSetYearsFmt); michael@0: } michael@0: ures_close(nameSetYears); michael@0: } michael@0: } michael@0: michael@0: tempStatus = U_ZERO_ERROR; michael@0: UResourceBundle *localeBundle = ures_open(NULL, locale.getName(), &tempStatus); michael@0: if (U_SUCCESS(tempStatus)) { michael@0: UResourceBundle *contextTransforms = ures_getByKeyWithFallback(localeBundle, gContextTransformsTag, NULL, &tempStatus); michael@0: if (U_SUCCESS(tempStatus)) { michael@0: UResourceBundle *contextTransformUsage; michael@0: while ( (contextTransformUsage = ures_getNextResource(contextTransforms, NULL, &tempStatus)) != NULL ) { michael@0: const int32_t * intVector = ures_getIntVector(contextTransformUsage, &len, &status); michael@0: if (U_SUCCESS(tempStatus) && intVector != NULL && len >= 2) { michael@0: const char* usageType = ures_getKey(contextTransformUsage); michael@0: if (usageType != NULL) { michael@0: const ContextUsageTypeNameToEnumValue * typeMapPtr = contextUsageTypeMap; michael@0: int32_t compResult = 0; michael@0: // linear search; list is short and we cannot be sure that bsearch is available michael@0: while ( typeMapPtr->usageTypeName != NULL && (compResult = uprv_strcmp(usageType, typeMapPtr->usageTypeName)) > 0 ) { michael@0: ++typeMapPtr; michael@0: } michael@0: if (typeMapPtr->usageTypeName != NULL && compResult == 0) { michael@0: fCapitalization[typeMapPtr->usageTypeEnumValue][0] = intVector[0]; michael@0: fCapitalization[typeMapPtr->usageTypeEnumValue][1] = intVector[1]; michael@0: } michael@0: } michael@0: } michael@0: tempStatus = U_ZERO_ERROR; michael@0: ures_close(contextTransformUsage); michael@0: } michael@0: ures_close(contextTransforms); michael@0: } michael@0: ures_close(localeBundle); michael@0: } michael@0: michael@0: UResourceBundle *weekdaysData = NULL; // Data closed by calData michael@0: UResourceBundle *abbrWeekdaysData = NULL; // Data closed by calData michael@0: UResourceBundle *shorterWeekdaysData = NULL; // Data closed by calData michael@0: UResourceBundle *narrowWeekdaysData = NULL; // Data closed by calData michael@0: UResourceBundle *standaloneWeekdaysData = NULL; // Data closed by calData michael@0: UResourceBundle *standaloneAbbrWeekdaysData = NULL; // Data closed by calData michael@0: UResourceBundle *standaloneShorterWeekdaysData = NULL; // Data closed by calData michael@0: UResourceBundle *standaloneNarrowWeekdaysData = NULL; // Data closed by calData michael@0: michael@0: U_LOCALE_BASED(locBased, *this); michael@0: if (U_FAILURE(status)) michael@0: { michael@0: if (useLastResortData) michael@0: { michael@0: // Handle the case in which there is no resource data present. michael@0: // We don't have to generate usable patterns in this situation; michael@0: // we just need to produce something that will be semi-intelligible michael@0: // in most locales. michael@0: michael@0: status = U_USING_FALLBACK_WARNING; michael@0: michael@0: initField(&fEras, fErasCount, (const UChar *)gLastResortEras, kEraNum, kEraLen, status); michael@0: initField(&fEraNames, fEraNamesCount, (const UChar *)gLastResortEras, kEraNum, kEraLen, status); michael@0: initField(&fNarrowEras, fNarrowErasCount, (const UChar *)gLastResortEras, kEraNum, kEraLen, status); michael@0: initField(&fMonths, fMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status); michael@0: initField(&fShortMonths, fShortMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status); michael@0: initField(&fNarrowMonths, fNarrowMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status); michael@0: initField(&fStandaloneMonths, fStandaloneMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status); michael@0: initField(&fStandaloneShortMonths, fStandaloneShortMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status); michael@0: initField(&fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status); michael@0: initField(&fWeekdays, fWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); michael@0: initField(&fShortWeekdays, fShortWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); michael@0: initField(&fShorterWeekdays, fShorterWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); michael@0: initField(&fNarrowWeekdays, fNarrowWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); michael@0: initField(&fStandaloneWeekdays, fStandaloneWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); michael@0: initField(&fStandaloneShortWeekdays, fStandaloneShortWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); michael@0: initField(&fStandaloneShorterWeekdays, fStandaloneShorterWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); michael@0: initField(&fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status); michael@0: initField(&fAmPms, fAmPmsCount, (const UChar *)gLastResortAmPmMarkers, kAmPmNum, kAmPmLen, status); michael@0: initField(&fQuarters, fQuartersCount, (const UChar *)gLastResortQuarters, kQuarterNum, kQuarterLen, status); michael@0: initField(&fShortQuarters, fShortQuartersCount, (const UChar *)gLastResortQuarters, kQuarterNum, kQuarterLen, status); michael@0: initField(&fStandaloneQuarters, fStandaloneQuartersCount, (const UChar *)gLastResortQuarters, kQuarterNum, kQuarterLen, status); michael@0: initField(&fStandaloneShortQuarters, fStandaloneShortQuartersCount, (const UChar *)gLastResortQuarters, kQuarterNum, kQuarterLen, status); michael@0: fLocalPatternChars.setTo(TRUE, gPatternChars, PATTERN_CHARS_LEN); michael@0: } michael@0: goto cleanup; michael@0: } michael@0: michael@0: // if we make it to here, the resource data is cool, and we can get everything out michael@0: // of it that we need except for the time-zone and localized-pattern data, which michael@0: // are stored in a separate file michael@0: locBased.setLocaleIDs(ures_getLocaleByType(eras, ULOC_VALID_LOCALE, &status), michael@0: ures_getLocaleByType(eras, ULOC_ACTUAL_LOCALE, &status)); michael@0: michael@0: initField(&fEras, fErasCount, eras, status); michael@0: initField(&fEraNames, fEraNamesCount, eraNames, status); michael@0: initField(&fNarrowEras, fNarrowErasCount, narrowEras, status); michael@0: michael@0: initField(&fMonths, fMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesWideTag, status), status); michael@0: initField(&fShortMonths, fShortMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesAbbrTag, status), status); michael@0: michael@0: initField(&fNarrowMonths, fNarrowMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesNarrowTag, status), status); michael@0: if(status == U_MISSING_RESOURCE_ERROR) { michael@0: status = U_ZERO_ERROR; michael@0: initField(&fNarrowMonths, fNarrowMonthsCount, calData.getByKey3(gMonthNamesTag, gNamesStandaloneTag, gNamesNarrowTag, status), status); michael@0: } michael@0: if ( status == U_MISSING_RESOURCE_ERROR ) { /* If format/narrow not available, use format/abbreviated */ michael@0: status = U_ZERO_ERROR; michael@0: initField(&fNarrowMonths, fNarrowMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesAbbrTag, status), status); michael@0: } michael@0: michael@0: initField(&fStandaloneMonths, fStandaloneMonthsCount, calData.getByKey3(gMonthNamesTag, gNamesStandaloneTag, gNamesWideTag, status), status); michael@0: if ( status == U_MISSING_RESOURCE_ERROR ) { /* If standalone/wide not available, use format/wide */ michael@0: status = U_ZERO_ERROR; michael@0: initField(&fStandaloneMonths, fStandaloneMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesWideTag, status), status); michael@0: } michael@0: initField(&fStandaloneShortMonths, fStandaloneShortMonthsCount, calData.getByKey3(gMonthNamesTag, gNamesStandaloneTag, gNamesAbbrTag, status), status); michael@0: if ( status == U_MISSING_RESOURCE_ERROR ) { /* If standalone/abbreviated not available, use format/abbreviated */ michael@0: status = U_ZERO_ERROR; michael@0: initField(&fStandaloneShortMonths, fStandaloneShortMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesAbbrTag, status), status); michael@0: } michael@0: initField(&fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, calData.getByKey3(gMonthNamesTag, gNamesStandaloneTag, gNamesNarrowTag, status), status); michael@0: if ( status == U_MISSING_RESOURCE_ERROR ) { /* if standalone/narrow not availabe, try format/narrow */ michael@0: status = U_ZERO_ERROR; michael@0: initField(&fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesNarrowTag, status), status); michael@0: if ( status == U_MISSING_RESOURCE_ERROR ) { /* if still not there, use format/abbreviated */ michael@0: status = U_ZERO_ERROR; michael@0: initField(&fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesAbbrTag, status), status); michael@0: } michael@0: } michael@0: initField(&fAmPms, fAmPmsCount, calData.getByKey(gAmPmMarkersTag, status), status); michael@0: michael@0: initField(&fQuarters, fQuartersCount, calData.getByKey2(gQuartersTag, gNamesWideTag, status), status); michael@0: initField(&fShortQuarters, fShortQuartersCount, calData.getByKey2(gQuartersTag, gNamesAbbrTag, status), status); michael@0: michael@0: initField(&fStandaloneQuarters, fStandaloneQuartersCount, calData.getByKey3(gQuartersTag, gNamesStandaloneTag, gNamesWideTag, status), status); michael@0: if(status == U_MISSING_RESOURCE_ERROR) { michael@0: status = U_ZERO_ERROR; michael@0: initField(&fStandaloneQuarters, fStandaloneQuartersCount, calData.getByKey2(gQuartersTag, gNamesWideTag, status), status); michael@0: } michael@0: michael@0: initField(&fStandaloneShortQuarters, fStandaloneShortQuartersCount, calData.getByKey3(gQuartersTag, gNamesStandaloneTag, gNamesAbbrTag, status), status); michael@0: if(status == U_MISSING_RESOURCE_ERROR) { michael@0: status = U_ZERO_ERROR; michael@0: initField(&fStandaloneShortQuarters, fStandaloneShortQuartersCount, calData.getByKey2(gQuartersTag, gNamesAbbrTag, status), status); michael@0: } michael@0: michael@0: // ICU 3.8 or later version no longer uses localized date-time pattern characters by default (ticket#5597) michael@0: /* michael@0: // fastCopyFrom()/setTo() - see assignArray comments michael@0: resStr = ures_getStringByKey(fResourceBundle, gLocalPatternCharsTag, &len, &status); michael@0: fLocalPatternChars.setTo(TRUE, resStr, len); michael@0: // If the locale data does not include new pattern chars, use the defaults michael@0: // TODO: Consider making this an error, since this may add conflicting characters. michael@0: if (len < PATTERN_CHARS_LEN) { michael@0: fLocalPatternChars.append(UnicodeString(TRUE, &gPatternChars[len], PATTERN_CHARS_LEN-len)); michael@0: } michael@0: */ michael@0: fLocalPatternChars.setTo(TRUE, gPatternChars, PATTERN_CHARS_LEN); michael@0: michael@0: // Format wide weekdays -> fWeekdays michael@0: // {sfb} fixed to handle 1-based weekdays michael@0: weekdaysData = calData.getByKey2(gDayNamesTag, gNamesWideTag, status); michael@0: fWeekdaysCount = ures_getSize(weekdaysData); michael@0: fWeekdays = new UnicodeString[fWeekdaysCount+1]; michael@0: /* pin the blame on system. If we cannot get a chunk of memory .. the system is dying!*/ michael@0: if (fWeekdays == NULL) { michael@0: status = U_MEMORY_ALLOCATION_ERROR; michael@0: goto cleanup; michael@0: } michael@0: // leave fWeekdays[0] empty michael@0: for(i = 0; i fShortWeekdays michael@0: abbrWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status); michael@0: fShortWeekdaysCount = ures_getSize(abbrWeekdaysData); michael@0: fShortWeekdays = new UnicodeString[fShortWeekdaysCount+1]; michael@0: /* test for NULL */ michael@0: if (fShortWeekdays == 0) { michael@0: status = U_MEMORY_ALLOCATION_ERROR; michael@0: goto cleanup; michael@0: } michael@0: // leave fShortWeekdays[0] empty michael@0: for(i = 0; i fShorterWeekdays (fall back to abbreviated) michael@0: shorterWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesShortTag, status); michael@0: if ( status == U_MISSING_RESOURCE_ERROR ) { michael@0: status = U_ZERO_ERROR; michael@0: shorterWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status); michael@0: } michael@0: fShorterWeekdaysCount = ures_getSize(shorterWeekdaysData); michael@0: fShorterWeekdays = new UnicodeString[fShorterWeekdaysCount+1]; michael@0: /* test for NULL */ michael@0: if (fShorterWeekdays == 0) { michael@0: status = U_MEMORY_ALLOCATION_ERROR; michael@0: goto cleanup; michael@0: } michael@0: // leave fShorterWeekdays[0] empty michael@0: for(i = 0; i fNarrowWeekdays michael@0: narrowWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesNarrowTag, status); michael@0: if(status == U_MISSING_RESOURCE_ERROR) { michael@0: status = U_ZERO_ERROR; michael@0: narrowWeekdaysData = calData.getByKey3(gDayNamesTag, gNamesStandaloneTag, gNamesNarrowTag, status); michael@0: } michael@0: if ( status == U_MISSING_RESOURCE_ERROR ) { michael@0: status = U_ZERO_ERROR; michael@0: narrowWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status); michael@0: } michael@0: fNarrowWeekdaysCount = ures_getSize(narrowWeekdaysData); michael@0: fNarrowWeekdays = new UnicodeString[fNarrowWeekdaysCount+1]; michael@0: /* test for NULL */ michael@0: if (fNarrowWeekdays == 0) { michael@0: status = U_MEMORY_ALLOCATION_ERROR; michael@0: goto cleanup; michael@0: } michael@0: // leave fNarrowWeekdays[0] empty michael@0: for(i = 0; i fStandaloneWeekdays michael@0: standaloneWeekdaysData = calData.getByKey3(gDayNamesTag, gNamesStandaloneTag, gNamesWideTag, status); michael@0: if ( status == U_MISSING_RESOURCE_ERROR ) { michael@0: status = U_ZERO_ERROR; michael@0: standaloneWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesWideTag, status); michael@0: } michael@0: fStandaloneWeekdaysCount = ures_getSize(standaloneWeekdaysData); michael@0: fStandaloneWeekdays = new UnicodeString[fStandaloneWeekdaysCount+1]; michael@0: /* test for NULL */ michael@0: if (fStandaloneWeekdays == 0) { michael@0: status = U_MEMORY_ALLOCATION_ERROR; michael@0: goto cleanup; michael@0: } michael@0: // leave fStandaloneWeekdays[0] empty michael@0: for(i = 0; i fStandaloneShortWeekdays michael@0: standaloneAbbrWeekdaysData = calData.getByKey3(gDayNamesTag, gNamesStandaloneTag, gNamesAbbrTag, status); michael@0: if ( status == U_MISSING_RESOURCE_ERROR ) { michael@0: status = U_ZERO_ERROR; michael@0: standaloneAbbrWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status); michael@0: } michael@0: fStandaloneShortWeekdaysCount = ures_getSize(standaloneAbbrWeekdaysData); michael@0: fStandaloneShortWeekdays = new UnicodeString[fStandaloneShortWeekdaysCount+1]; michael@0: /* test for NULL */ michael@0: if (fStandaloneShortWeekdays == 0) { michael@0: status = U_MEMORY_ALLOCATION_ERROR; michael@0: goto cleanup; michael@0: } michael@0: // leave fStandaloneShortWeekdays[0] empty michael@0: for(i = 0; i fStandaloneShorterWeekdays (fall back to format abbreviated) michael@0: standaloneShorterWeekdaysData = calData.getByKey3(gDayNamesTag, gNamesStandaloneTag, gNamesShortTag, status); michael@0: if ( status == U_MISSING_RESOURCE_ERROR ) { michael@0: status = U_ZERO_ERROR; michael@0: standaloneShorterWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status); michael@0: } michael@0: fStandaloneShorterWeekdaysCount = ures_getSize(standaloneShorterWeekdaysData); michael@0: fStandaloneShorterWeekdays = new UnicodeString[fStandaloneShorterWeekdaysCount+1]; michael@0: /* test for NULL */ michael@0: if (fStandaloneShorterWeekdays == 0) { michael@0: status = U_MEMORY_ALLOCATION_ERROR; michael@0: goto cleanup; michael@0: } michael@0: // leave fStandaloneShorterWeekdays[0] empty michael@0: for(i = 0; i fStandaloneNarrowWeekdays michael@0: standaloneNarrowWeekdaysData = calData.getByKey3(gDayNamesTag, gNamesStandaloneTag, gNamesNarrowTag, status); michael@0: if ( status == U_MISSING_RESOURCE_ERROR ) { michael@0: status = U_ZERO_ERROR; michael@0: standaloneNarrowWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesNarrowTag, status); michael@0: if ( status == U_MISSING_RESOURCE_ERROR ) { michael@0: status = U_ZERO_ERROR; michael@0: standaloneNarrowWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status); michael@0: } michael@0: } michael@0: fStandaloneNarrowWeekdaysCount = ures_getSize(standaloneNarrowWeekdaysData); michael@0: fStandaloneNarrowWeekdays = new UnicodeString[fStandaloneNarrowWeekdaysCount+1]; michael@0: /* test for NULL */ michael@0: if (fStandaloneNarrowWeekdays == 0) { michael@0: status = U_MEMORY_ALLOCATION_ERROR; michael@0: goto cleanup; michael@0: } michael@0: // leave fStandaloneNarrowWeekdays[0] empty michael@0: for(i = 0; i