/* ******************************************************************************* * Copyright (C) 1997-2001, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* * * File DTFMTSYM.CPP * * Modification History: * * Date Name Description * 02/19/97 aliu Converted from java. * 07/21/98 stephen Added getZoneIndex * Changed weekdays/short weekdays to be one-based * 06/14/99 stephen Removed SimpleDateFormat::fgTimeZoneDataSuffix * 11/16/99 weiv Added 'Y' and 'e' to fgPatternChars * 03/27/00 weiv Keeping resource bundle around! ******************************************************************************* */ #include "unicode/dtfmtsym.h" #include "unicode/resbund.h" #include "unicode/smpdtfmt.h" #include "ucln_in.h" #include "mutex.h" // ***************************************************************************** // class DateFormatSymbols // ***************************************************************************** /** * These are static arrays we use only in the case where we have no * resource data. */ #define PATTERN_CHARS_LEN 20 /** * Unlocalized date-time pattern characters. For example: 'y', 'd', etc. All * locales use the same these unlocalized pattern characters. */ static const UChar gPatternChars[] = { 0x47, 0x79, 0x4D, 0x64, 0x6B, 0x48, 0x6D, 0x73, 0x53, 0x45, 0x44, 0x46, 0x77, 0x57, 0x61, 0x68, 0x4B, 0x7A, 0x59, 0x65, 0 /* "GyMdkHmsSEDFwWahKzYe" */ }; //------------------------------------------------------ // Strings of last resort. These are only used if we have no resource // files. They aren't designed for actual use, just for backup. // These are the month names and abbreviations of last resort. static const UChar gLastResortMonthNames[13][3] = { {0x0030, 0x0031, 0x0000}, /* "01" */ {0x0030, 0x0032, 0x0000}, /* "02" */ {0x0030, 0x0033, 0x0000}, /* "03" */ {0x0030, 0x0034, 0x0000}, /* "04" */ {0x0030, 0x0035, 0x0000}, /* "05" */ {0x0030, 0x0036, 0x0000}, /* "06" */ {0x0030, 0x0037, 0x0000}, /* "07" */ {0x0030, 0x0038, 0x0000}, /* "08" */ {0x0030, 0x0039, 0x0000}, /* "09" */ {0x0031, 0x0030, 0x0000}, /* "10" */ {0x0031, 0x0031, 0x0000}, /* "11" */ {0x0031, 0x0032, 0x0000}, /* "12" */ {0x0031, 0x0033, 0x0000} /* "13" */ }; // These are the weekday names and abbreviations of last resort. static const UChar gLastResortDayNames[8][2] = { {0x0000, 0x0000}, /* "" */ {0x0031, 0x0000}, /* "1" */ {0x0032, 0x0000}, /* "2" */ {0x0033, 0x0000}, /* "3" */ {0x0034, 0x0000}, /* "4" */ {0x0035, 0x0000}, /* "5" */ {0x0036, 0x0000}, /* "6" */ {0x0037, 0x0000} /* "7" */ }; // These are the am/pm and BC/AD markers of last resort. static const UChar gLastResortAmPmMarkers[2][3] = { {0x0041, 0x004D, 0x0000}, /* "AM" */ {0x0050, 0x004D, 0x0000} /* "PM" */ }; static const UChar gLastResortEras[2][3] = { {0x0042, 0x0043, 0x0000}, /* "BC" */ {0x0041, 0x0044, 0x0000} /* "AD" */ }; // These are the zone strings of last resort. static const UChar gLastResortZoneStrings[5][4] = { {0x0047, 0x004D, 0x0054, 0x0000}, /* "GMT" */ {0x0047, 0x004D, 0x0054, 0x0000}, /* "GMT" */ {0x0047, 0x004D, 0x0054, 0x0000}, /* "GMT" */ {0x0047, 0x004D, 0x0054, 0x0000}, /* "GMT" */ {0x0047, 0x004D, 0x0054, 0x0000} /* "GMT" */ }; static UnicodeString *gPatternCharsStr = NULL; U_CFUNC UBool dateFormatSymbols_cleanup() { if (gPatternCharsStr != NULL) { delete gPatternCharsStr; } return TRUE; } U_NAMESPACE_BEGIN /** * These are the tags we expect to see in normal resource bundle files associated * with a locale. */ const char DateFormatSymbols::fgErasTag[]="Eras"; const char DateFormatSymbols::fgMonthNamesTag[]="MonthNames"; const char DateFormatSymbols::fgMonthAbbreviationsTag[]="MonthAbbreviations"; const char DateFormatSymbols::fgDayNamesTag[]="DayNames"; const char DateFormatSymbols::fgDayAbbreviationsTag[]="DayAbbreviations"; const char DateFormatSymbols::fgAmPmMarkersTag[]="AmPmMarkers"; /** * These are the tags we expect to see in time zone data resource bundle files * associated with a locale. */ const char DateFormatSymbols::fgZoneStringsTag[]="zoneStrings"; const char DateFormatSymbols::fgLocalPatternCharsTag[]="localPatternChars"; //------------------------------------------------------ DateFormatSymbols::DateFormatSymbols(const Locale& locale, UErrorCode& status) { initializeData(locale, status); } DateFormatSymbols::DateFormatSymbols(UErrorCode& status) { initializeData(Locale::getDefault(), status, TRUE); } DateFormatSymbols::DateFormatSymbols(const DateFormatSymbols& other) { copyData(other); } void DateFormatSymbols::assignArray(UnicodeString*& dstArray, int32_t& dstCount, const UnicodeString* srcArray, int32_t srcCount) { // duplicates or aliases the source array, depending on the status of // the appropriate isOwned flag dstCount = srcCount; dstArray = new UnicodeString[srcCount]; uprv_arrayCopy(srcArray, dstArray, srcCount); } /** * Create a copy, in fZoneStrings, of the given zone strings array. The * member variables fZoneStringsRowCount and fZoneStringsColCount should * be set already by the caller. The fIsOwned flags are not checked or set * by this method; that is the caller's responsibility. */ void DateFormatSymbols::createZoneStrings(const UnicodeString *const * otherStrings) { fZoneStrings = new UnicodeString*[fZoneStringsRowCount]; for (int32_t row=0; row0) { --count; if (array1[count] != array2[count]) return FALSE; } return TRUE; } UBool DateFormatSymbols::operator==(const DateFormatSymbols& other) const { // First do cheap comparisons if (fErasCount == other.fErasCount && fMonthsCount == other.fMonthsCount && fShortMonthsCount == other.fShortMonthsCount && fWeekdaysCount == other.fWeekdaysCount && fShortWeekdaysCount == other.fShortWeekdaysCount && fAmPmsCount == other.fAmPmsCount && fZoneStringsRowCount == other.fZoneStringsRowCount && fZoneStringsColCount == other.fZoneStringsColCount) { // Now compare the arrays themselves if (arrayCompare(fEras, other.fEras, fErasCount) && arrayCompare(fMonths, other.fMonths, fMonthsCount) && arrayCompare(fShortMonths, other.fShortMonths, fShortMonthsCount) && arrayCompare(fWeekdays, other.fWeekdays, fWeekdaysCount) && arrayCompare(fShortWeekdays, other.fShortWeekdays, fShortWeekdaysCount) && arrayCompare(fAmPms, other.fAmPms, fAmPmsCount)) { if (fZoneStrings == other.fZoneStrings) return TRUE; for (int32_t row=0; row= 0) { return result; } // Do a search through the equivalency group for the given ID int32_t n = TimeZone::countEquivalentIDs(ID); if (n > 1) { int32_t i; for (i=0; i= 0) { return equivResult; } } } } return -1; } /** * Lookup the given ID. Do NOT do an equivalency search. */ int32_t DateFormatSymbols::_getZoneIndex(const UnicodeString& ID) const { // {sfb} kludge to support case-insensitive comparison UnicodeString lcaseID(ID); lcaseID.toLower(); for(int32_t index = 0; index < fZoneStringsRowCount; index++) { UnicodeString lcase(fZoneStrings[index][0]); lcase.toLower(); if (lcaseID == lcase) { return index; } } return -1; } U_NAMESPACE_END //eof