/* ******************************************************************************* * Copyright (C) 1997-1999, 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 ******************************************************************************* */ #include "unicode/dtfmtsym.h" #include "unicode/resbund.h" #include "unicode/smpdtfmt.h" #include "mutex.h" // ***************************************************************************** // class DateFormatSymbols // ***************************************************************************** // generic date-format pattern symbols. For their meanings, see class docs // for SimpleDateFormat UnicodeString DateFormatSymbols::fgPatternChars = UNICODE_STRING("GyMdkHmsSEDFwWahKzYe", 20); //------------------------------------------------------ // Strings of last resort. These are only used if we have no resource // files. They aren't designed for actual use, just for backup. //============================================================ // To make the VC++ compiler happy these must occur before the // sizeof operations on the arrays occur below. //============================================================ // These are the month names and abbreviations of last resort. const UnicodeString DateFormatSymbols::fgLastResortMonthNames[] = { UNICODE_STRING("01", 2), UNICODE_STRING("02", 2), UNICODE_STRING("03", 2), UNICODE_STRING("04", 2), UNICODE_STRING("05", 2), UNICODE_STRING("06", 2), UNICODE_STRING("07", 2), UNICODE_STRING("08", 2), UNICODE_STRING("09", 2), UNICODE_STRING("10", 2), UNICODE_STRING("11", 2), UNICODE_STRING("12", 2), UNICODE_STRING("13", 2) }; // These are the weekday names and abbreviations of last resort. const UnicodeString DateFormatSymbols::fgLastResortDayNames[] = { UnicodeString(), UNICODE_STRING("1", 1), UNICODE_STRING("2", 1), UNICODE_STRING("3", 1), UNICODE_STRING("4", 1), UNICODE_STRING("5", 1), UNICODE_STRING("6", 1), UNICODE_STRING("7", 1) }; // These are the am/pm and BC/AD markers of last resort. const UnicodeString DateFormatSymbols::fgLastResortAmPmMarkers[] = { UNICODE_STRING("AM", 2), UNICODE_STRING("PM", 2) }; const UnicodeString DateFormatSymbols::fgLastResortEras[] = { UNICODE_STRING("BC", 2), UNICODE_STRING("AD", 2) }; // These are the zone strings of last resort. UnicodeString** DateFormatSymbols::fgLastResortZoneStringsH = 0; const UnicodeString DateFormatSymbols::fgLastResortZoneStrings[] = { UNICODE_STRING("GMT", 3), UNICODE_STRING("GMT", 3), UNICODE_STRING("GMT", 3), UNICODE_STRING("GMT", 3), UNICODE_STRING("GMT", 3) }; //------------------------------------------------------ DateFormatSymbols::DateFormatSymbols(const Locale& locale, UErrorCode& status) { initializeData(locale, status); } DateFormatSymbols::DateFormatSymbols(UErrorCode& status) { initializeData(Locale::getDefault(), status, TRUE); } DateFormatSymbols::DateFormatSymbols(const DateFormatSymbols& other) { fIsOwned = 0; // We own nothing (ignore existing pointers) *this = other; } void DateFormatSymbols::assignArray(UnicodeString*& dstArray, int32_t& dstCount, const UnicodeString* srcArray, int32_t srcCount, const DateFormatSymbols& other, int32_t which) { // duplicates or aliases the source array, depending on the status of // the appropriate isOwned flag bool_t owned = other.isOwned(which); setIsOwned(which, owned); dstCount = srcCount; if (owned) { dstArray = new UnicodeString[srcCount]; uprv_arrayCopy(srcArray, dstArray, srcCount); } else { dstArray = (UnicodeString*)srcArray; // Compiler requires cast } } /** * 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; } bool_t 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