1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
2005-03-08 22:49:59 +00:00
|
|
|
* Copyright (C) 1997-2005, International Business Machines Corporation and *
|
1999-11-22 20:25:35 +00:00
|
|
|
* others. All Rights Reserved. *
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* 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
|
1999-11-22 20:25:35 +00:00
|
|
|
* 11/16/99 weiv Added 'Y' and 'e' to fgPatternChars
|
2000-05-15 18:39:17 +00:00
|
|
|
* 03/27/00 weiv Keeping resource bundle around!
|
2005-07-01 17:22:22 +00:00
|
|
|
* 06/30/05 emmons Added eraNames, narrow month/day, standalone context
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/dtfmtsym.h"
|
|
|
|
#include "unicode/smpdtfmt.h"
|
2001-11-15 19:27:10 +00:00
|
|
|
#include "ucln_in.h"
|
|
|
|
#include "mutex.h"
|
2002-07-16 17:50:42 +00:00
|
|
|
#include "cmemory.h"
|
2003-05-16 22:05:41 +00:00
|
|
|
#include "cstring.h"
|
2004-01-20 23:06:38 +00:00
|
|
|
#include "locbased.h"
|
2004-05-18 02:06:28 +00:00
|
|
|
#include "gregoimp.h"
|
2005-08-26 21:55:55 +00:00
|
|
|
#include "hash.h"
|
|
|
|
#include "uresimp.h"
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// *****************************************************************************
|
|
|
|
// class DateFormatSymbols
|
|
|
|
// *****************************************************************************
|
2001-07-06 23:19:56 +00:00
|
|
|
/**
|
|
|
|
* These are static arrays we use only in the case where we have no
|
|
|
|
* resource data.
|
|
|
|
*/
|
|
|
|
|
2004-08-31 18:04:12 +00:00
|
|
|
#define PATTERN_CHARS_LEN 24
|
2000-01-25 02:08:22 +00:00
|
|
|
|
2001-07-06 23:19:56 +00:00
|
|
|
/**
|
|
|
|
* Unlocalized date-time pattern characters. For example: 'y', 'd', etc. All
|
|
|
|
* locales use the same these unlocalized pattern characters.
|
|
|
|
*/
|
2004-03-11 13:57:08 +00:00
|
|
|
static const UChar gPatternChars[] = {
|
2005-06-23 18:25:29 +00:00
|
|
|
// GyMdkHmsSEDFwWahKzYeugAZvcL
|
2004-08-31 18:04:12 +00:00
|
|
|
0x47, 0x79, 0x4D, 0x64, 0x6B, 0x48, 0x6D, 0x73, 0x53, 0x45,
|
|
|
|
0x44, 0x46, 0x77, 0x57, 0x61, 0x68, 0x4B, 0x7A, 0x59, 0x65,
|
2005-06-23 18:25:29 +00:00
|
|
|
0x75, 0x67, 0x41, 0x5A, 0x76, 0x63, 0x4c, 0
|
2001-07-06 23:19:56 +00:00
|
|
|
};
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2005-08-26 21:55:55 +00:00
|
|
|
/* length of an array */
|
|
|
|
#define ARRAY_LENGTH(array) (sizeof(array)/sizeof(array[0]))
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
//------------------------------------------------------
|
|
|
|
// 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.
|
2001-07-06 23:19:56 +00:00
|
|
|
static const UChar gLastResortMonthNames[13][3] =
|
2001-06-19 17:38:29 +00:00
|
|
|
{
|
|
|
|
{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" */
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// These are the weekday names and abbreviations of last resort.
|
2001-07-06 23:19:56 +00:00
|
|
|
static const UChar gLastResortDayNames[8][2] =
|
2001-06-19 17:38:29 +00:00
|
|
|
{
|
|
|
|
{0x0000, 0x0000}, /* "" */
|
|
|
|
{0x0031, 0x0000}, /* "1" */
|
|
|
|
{0x0032, 0x0000}, /* "2" */
|
|
|
|
{0x0033, 0x0000}, /* "3" */
|
|
|
|
{0x0034, 0x0000}, /* "4" */
|
|
|
|
{0x0035, 0x0000}, /* "5" */
|
|
|
|
{0x0036, 0x0000}, /* "6" */
|
|
|
|
{0x0037, 0x0000} /* "7" */
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// These are the am/pm and BC/AD markers of last resort.
|
2001-07-06 23:19:56 +00:00
|
|
|
static const UChar gLastResortAmPmMarkers[2][3] =
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-06-19 17:38:29 +00:00
|
|
|
{0x0041, 0x004D, 0x0000}, /* "AM" */
|
|
|
|
{0x0050, 0x004D, 0x0000} /* "PM" */
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2001-07-06 23:19:56 +00:00
|
|
|
static const UChar gLastResortEras[2][3] =
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-06-19 17:38:29 +00:00
|
|
|
{0x0042, 0x0043, 0x0000}, /* "BC" */
|
|
|
|
{0x0041, 0x0044, 0x0000} /* "AD" */
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-06-19 17:38:29 +00:00
|
|
|
// These are the zone strings of last resort.
|
2001-07-06 23:19:56 +00:00
|
|
|
static const UChar gLastResortZoneStrings[5][4] =
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-06-19 17:38:29 +00:00
|
|
|
{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" */
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2005-01-09 05:18:02 +00:00
|
|
|
/* Sizes for the last resort string arrays */
|
|
|
|
typedef enum LastResortSize {
|
|
|
|
kMonthNum = 13,
|
|
|
|
kMonthLen = 3,
|
|
|
|
|
|
|
|
kDayNum = 8,
|
|
|
|
kDayLen = 2,
|
|
|
|
|
|
|
|
kAmPmNum = 2,
|
|
|
|
kAmPmLen = 3,
|
|
|
|
|
|
|
|
kEraNum = 2,
|
|
|
|
kEraLen = 3,
|
|
|
|
|
|
|
|
kZoneNum = 5,
|
|
|
|
kZoneLen = 4
|
|
|
|
} LastResortSize;
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2003-10-07 15:49:47 +00:00
|
|
|
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateFormatSymbols)
|
2002-06-29 00:04:16 +00:00
|
|
|
|
2001-08-10 23:00:30 +00:00
|
|
|
/**
|
|
|
|
* These are the tags we expect to see in normal resource bundle files associated
|
2004-05-18 02:06:28 +00:00
|
|
|
* with a locale and calendar
|
2001-08-10 23:00:30 +00:00
|
|
|
*/
|
2004-05-18 02:06:28 +00:00
|
|
|
const char gErasTag[]="eras";
|
2004-08-20 23:12:31 +00:00
|
|
|
const char gAbbreviatedTag[] = "abbreviated";
|
2004-05-18 02:06:28 +00:00
|
|
|
const char gMonthNamesTag[]="monthNames";
|
|
|
|
const char gDayNamesTag[]="dayNames";
|
|
|
|
const char gNamesWideTag[]="wide";
|
|
|
|
const char gNamesAbbrTag[]="abbreviated";
|
2005-07-01 17:22:22 +00:00
|
|
|
const char gNamesNarrowTag[]="narrow";
|
|
|
|
const char gNamesStandaloneTag[]="stand-alone";
|
2003-10-07 15:49:47 +00:00
|
|
|
const char gAmPmMarkersTag[]="AmPmMarkers";
|
2001-08-10 23:00:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* These are the tags we expect to see in time zone data resource bundle files
|
|
|
|
* associated with a locale.
|
|
|
|
*/
|
2003-10-07 15:49:47 +00:00
|
|
|
const char gZoneStringsTag[]="zoneStrings";
|
|
|
|
const char gLocalPatternCharsTag[]="localPatternChars";
|
2001-08-10 23:00:30 +00:00
|
|
|
|
2005-08-26 21:55:55 +00:00
|
|
|
static UMTX LOCK;
|
|
|
|
static UnicodeString bogus;
|
|
|
|
/*
|
|
|
|
* Keep this variable in synch with max length of display strings
|
|
|
|
*/
|
|
|
|
#define UTZ_MAX_DISPLAY_STRINGS_LENGTH 7
|
|
|
|
#define UTZ_SHORT_GENERIC "sg"
|
|
|
|
#define UTZ_SHORT_STANDARD "ss"
|
|
|
|
#define UTZ_SHORT_DAYLIGHT "sd"
|
|
|
|
#define UTZ_LONG_GENERIC "lg"
|
|
|
|
#define UTZ_LONG_STANDARD "ls"
|
|
|
|
#define UTZ_LONG_DAYLIGHT "ld"
|
|
|
|
#define UTZ_EXEMPLAR_CITY "ec"
|
|
|
|
|
2003-06-05 17:19:03 +00:00
|
|
|
/**
|
|
|
|
* Jitterbug 2974: MSVC has a bug whereby new X[0] behaves badly.
|
|
|
|
* Work around this.
|
|
|
|
*/
|
|
|
|
static inline UnicodeString* newUnicodeStringArray(size_t count) {
|
|
|
|
return new UnicodeString[count ? count : 1];
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
//------------------------------------------------------
|
|
|
|
|
|
|
|
DateFormatSymbols::DateFormatSymbols(const Locale& locale,
|
|
|
|
UErrorCode& status)
|
2002-07-02 23:58:34 +00:00
|
|
|
: UObject()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-05-15 22:31:16 +00:00
|
|
|
initializeData(locale, NULL, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DateFormatSymbols::DateFormatSymbols(UErrorCode& status)
|
2002-07-02 23:58:34 +00:00
|
|
|
: UObject()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-05-15 22:31:16 +00:00
|
|
|
initializeData(Locale::getDefault(), NULL, status, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DateFormatSymbols::DateFormatSymbols(const Locale& locale,
|
|
|
|
const char *type,
|
|
|
|
UErrorCode& status)
|
|
|
|
: UObject()
|
|
|
|
{
|
|
|
|
initializeData(locale, type, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
DateFormatSymbols::DateFormatSymbols(const char *type, UErrorCode& status)
|
|
|
|
: UObject()
|
|
|
|
{
|
|
|
|
initializeData(Locale::getDefault(), type, status, TRUE);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DateFormatSymbols::DateFormatSymbols(const DateFormatSymbols& other)
|
2002-07-02 23:58:34 +00:00
|
|
|
: UObject(other)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-06-19 17:38:29 +00:00
|
|
|
copyData(other);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DateFormatSymbols::assignArray(UnicodeString*& dstArray,
|
|
|
|
int32_t& dstCount,
|
|
|
|
const UnicodeString* srcArray,
|
2001-06-19 17:38:29 +00:00
|
|
|
int32_t srcCount)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2002-10-15 00:36:11 +00:00
|
|
|
// assignArray() is only called by copyData(), which in turn implements the
|
|
|
|
// copy constructor and the assignment operator.
|
|
|
|
// All strings in a DateFormatSymbols object are created in one of the following
|
|
|
|
// three ways that all allow to safely use UnicodeString::fastCopyFrom():
|
|
|
|
// - readonly-aliases from resource bundles
|
|
|
|
// - readonly-aliases or allocated strings from constants
|
|
|
|
// - safely cloned strings (with owned buffers) from setXYZ() functions
|
|
|
|
//
|
|
|
|
// Note that this is true for as long as DateFormatSymbols can be constructed
|
|
|
|
// only from a locale bundle or set via the cloning API,
|
|
|
|
// *and* for as long as all the strings are in *private* fields, preventing
|
|
|
|
// a subclass from creating these strings in an "unsafe" way (with respect to fastCopyFrom()).
|
1999-08-16 21:50:52 +00:00
|
|
|
dstCount = srcCount;
|
2003-06-05 17:19:03 +00:00
|
|
|
dstArray = newUnicodeStringArray(srcCount);
|
2002-10-15 00:36:11 +00:00
|
|
|
if(dstArray != NULL) {
|
|
|
|
int32_t i;
|
|
|
|
for(i=0; i<srcCount; ++i) {
|
|
|
|
dstArray[i].fastCopyFrom(srcArray[i]);
|
|
|
|
}
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a copy, in fZoneStrings, of the given zone strings array. The
|
|
|
|
* member variables fZoneStringsRowCount and fZoneStringsColCount should
|
2002-10-15 00:36:11 +00:00
|
|
|
* be set already by the caller.
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
DateFormatSymbols::createZoneStrings(const UnicodeString *const * otherStrings)
|
|
|
|
{
|
2002-10-15 00:36:11 +00:00
|
|
|
int32_t row, col;
|
|
|
|
|
2002-07-16 17:50:42 +00:00
|
|
|
fZoneStrings = (UnicodeString **)uprv_malloc(fZoneStringsRowCount * sizeof(UnicodeString *));
|
2002-10-15 00:36:11 +00:00
|
|
|
for (row=0; row<fZoneStringsRowCount; ++row)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-06-05 17:19:03 +00:00
|
|
|
fZoneStrings[row] = newUnicodeStringArray(fZoneStringsColCount);
|
2002-10-15 00:36:11 +00:00
|
|
|
for (col=0; col<fZoneStringsColCount; ++col) {
|
|
|
|
// fastCopyFrom() - see assignArray comments
|
|
|
|
fZoneStrings[row][col].fastCopyFrom(otherStrings[row][col]);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-19 17:38:29 +00:00
|
|
|
/**
|
|
|
|
* Copy all of the other's data to this.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
DateFormatSymbols::copyData(const DateFormatSymbols& other) {
|
|
|
|
assignArray(fEras, fErasCount, other.fEras, other.fErasCount);
|
2005-07-01 17:22:22 +00:00
|
|
|
assignArray(fEraNames, fEraNamesCount, other.fEraNames, other.fEraNamesCount);
|
2001-06-19 17:38:29 +00:00
|
|
|
assignArray(fMonths, fMonthsCount, other.fMonths, other.fMonthsCount);
|
|
|
|
assignArray(fShortMonths, fShortMonthsCount, other.fShortMonths, other.fShortMonthsCount);
|
2005-07-01 17:22:22 +00:00
|
|
|
assignArray(fNarrowMonths, fNarrowMonthsCount, other.fNarrowMonths, other.fNarrowMonthsCount);
|
|
|
|
assignArray(fStandaloneMonths, fStandaloneMonthsCount, other.fStandaloneMonths, other.fStandaloneMonthsCount);
|
|
|
|
assignArray(fStandaloneShortMonths, fStandaloneShortMonthsCount, other.fStandaloneShortMonths, other.fStandaloneShortMonthsCount);
|
|
|
|
assignArray(fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, other.fStandaloneNarrowMonths, other.fStandaloneNarrowMonthsCount);
|
2001-06-19 17:38:29 +00:00
|
|
|
assignArray(fWeekdays, fWeekdaysCount, other.fWeekdays, other.fWeekdaysCount);
|
|
|
|
assignArray(fShortWeekdays, fShortWeekdaysCount, other.fShortWeekdays, other.fShortWeekdaysCount);
|
2005-07-01 17:22:22 +00:00
|
|
|
assignArray(fNarrowWeekdays, fNarrowWeekdaysCount, other.fNarrowWeekdays, other.fNarrowWeekdaysCount);
|
|
|
|
assignArray(fStandaloneWeekdays, fStandaloneWeekdaysCount, other.fStandaloneWeekdays, other.fStandaloneWeekdaysCount);
|
|
|
|
assignArray(fStandaloneShortWeekdays, fStandaloneShortWeekdaysCount, other.fStandaloneShortWeekdays, other.fStandaloneShortWeekdaysCount);
|
|
|
|
assignArray(fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount, other.fStandaloneNarrowWeekdays, other.fStandaloneNarrowWeekdaysCount);
|
2001-06-19 17:38:29 +00:00
|
|
|
assignArray(fAmPms, fAmPmsCount, other.fAmPms, other.fAmPmsCount);
|
2005-08-26 21:55:55 +00:00
|
|
|
// the zoneStrings data is initialized on demand
|
|
|
|
//fZoneStringsRowCount = other.fZoneStringsRowCount;
|
|
|
|
//fZoneStringsColCount = other.fZoneStringsColCount;
|
|
|
|
//createZoneStrings((const UnicodeString**)other.fZoneStrings);
|
|
|
|
// initialize on demand
|
|
|
|
fZoneStringsHash = NULL;
|
|
|
|
fZoneIDEnumeration = NULL;
|
|
|
|
fZoneStrings = NULL;
|
|
|
|
fZoneStringsColCount = 0;
|
|
|
|
fZoneStringsRowCount = 0;
|
|
|
|
fZoneArrayBundle = NULL;
|
|
|
|
if(other.fZoneStringsHash!=NULL){
|
|
|
|
fZoneStringsHash = createZoneStringsHash(other.fZoneStringsHash);
|
|
|
|
fZoneIDEnumeration = other.fZoneIDEnumeration->clone();
|
|
|
|
}else{
|
|
|
|
UErrorCode status =U_ZERO_ERROR;
|
|
|
|
fZoneArrayBundle = ures_clone(other.fZoneArrayBundle, &status);
|
|
|
|
// TODO: what should be done in case of error?
|
|
|
|
}
|
2001-06-19 17:38:29 +00:00
|
|
|
|
2002-10-15 00:36:11 +00:00
|
|
|
// fastCopyFrom() - see assignArray comments
|
|
|
|
fLocalPatternChars.fastCopyFrom(other.fLocalPatternChars);
|
2001-06-19 17:38:29 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/**
|
2002-10-15 00:36:11 +00:00
|
|
|
* Assignment operator.
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
|
|
|
DateFormatSymbols& DateFormatSymbols::operator=(const DateFormatSymbols& other)
|
|
|
|
{
|
|
|
|
dispose();
|
2001-06-19 17:38:29 +00:00
|
|
|
copyData(other);
|
2000-05-15 18:39:17 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
DateFormatSymbols::~DateFormatSymbols()
|
|
|
|
{
|
|
|
|
dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DateFormatSymbols::dispose()
|
|
|
|
{
|
2005-07-01 17:22:22 +00:00
|
|
|
if (fEras) delete[] fEras;
|
|
|
|
if (fEraNames) delete[] fEraNames;
|
|
|
|
if (fMonths) delete[] fMonths;
|
|
|
|
if (fShortMonths) delete[] fShortMonths;
|
|
|
|
if (fNarrowMonths) delete[] fNarrowMonths;
|
|
|
|
if (fStandaloneMonths) delete[] fStandaloneMonths;
|
|
|
|
if (fStandaloneShortMonths) delete[] fStandaloneShortMonths;
|
|
|
|
if (fStandaloneNarrowMonths) delete[] fStandaloneNarrowMonths;
|
|
|
|
if (fWeekdays) delete[] fWeekdays;
|
|
|
|
if (fShortWeekdays) delete[] fShortWeekdays;
|
|
|
|
if (fNarrowWeekdays) delete[] fNarrowWeekdays;
|
|
|
|
if (fStandaloneWeekdays) delete[] fStandaloneWeekdays;
|
|
|
|
if (fStandaloneShortWeekdays) delete[] fStandaloneShortWeekdays;
|
|
|
|
if (fStandaloneNarrowWeekdays) delete[] fStandaloneNarrowWeekdays;
|
|
|
|
if (fAmPms) delete[] fAmPms;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
disposeZoneStrings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DateFormatSymbols::disposeZoneStrings()
|
|
|
|
{
|
2001-06-19 17:38:29 +00:00
|
|
|
if (fZoneStrings) {
|
1999-08-16 21:50:52 +00:00
|
|
|
for (int32_t row=0; row<fZoneStringsRowCount; ++row)
|
|
|
|
delete[] fZoneStrings[row];
|
2002-07-16 17:50:42 +00:00
|
|
|
uprv_free(fZoneStrings);
|
2005-08-26 21:55:55 +00:00
|
|
|
}
|
|
|
|
if(fZoneStringsHash){
|
|
|
|
for(int32_t i=0; i<fZoneStringsHash->count(); i++){
|
|
|
|
const UHashElement* elem = fZoneStringsHash->nextElement(i);
|
|
|
|
UnicodeString* array = (UnicodeString*)(elem->value.pointer);
|
|
|
|
delete[] array;
|
|
|
|
}
|
|
|
|
delete fZoneStringsHash;
|
|
|
|
fZoneStringsHash = NULL;
|
|
|
|
}
|
|
|
|
if(fZoneIDEnumeration){
|
|
|
|
delete fZoneIDEnumeration;
|
|
|
|
fZoneIDEnumeration = NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2005-08-26 21:55:55 +00:00
|
|
|
ures_close(fZoneArrayBundle);
|
|
|
|
fZoneArrayBundle = NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool
|
1999-08-16 21:50:52 +00:00
|
|
|
DateFormatSymbols::arrayCompare(const UnicodeString* array1,
|
|
|
|
const UnicodeString* array2,
|
|
|
|
int32_t count)
|
|
|
|
{
|
|
|
|
if (array1 == array2) return TRUE;
|
|
|
|
while (count>0)
|
|
|
|
{
|
|
|
|
--count;
|
|
|
|
if (array1[count] != array2[count]) return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool
|
1999-08-16 21:50:52 +00:00
|
|
|
DateFormatSymbols::operator==(const DateFormatSymbols& other) const
|
|
|
|
{
|
|
|
|
// First do cheap comparisons
|
2002-10-15 00:36:11 +00:00
|
|
|
if (this == &other) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
if (fErasCount == other.fErasCount &&
|
2005-07-01 17:22:22 +00:00
|
|
|
fEraNamesCount == other.fEraNamesCount &&
|
1999-08-16 21:50:52 +00:00
|
|
|
fMonthsCount == other.fMonthsCount &&
|
|
|
|
fShortMonthsCount == other.fShortMonthsCount &&
|
2005-07-01 17:22:22 +00:00
|
|
|
fNarrowMonthsCount == other.fNarrowMonthsCount &&
|
|
|
|
fStandaloneMonthsCount == other.fStandaloneMonthsCount &&
|
|
|
|
fStandaloneShortMonthsCount == other.fStandaloneShortMonthsCount &&
|
|
|
|
fStandaloneNarrowMonthsCount == other.fStandaloneNarrowMonthsCount &&
|
1999-08-16 21:50:52 +00:00
|
|
|
fWeekdaysCount == other.fWeekdaysCount &&
|
|
|
|
fShortWeekdaysCount == other.fShortWeekdaysCount &&
|
2005-07-01 17:22:22 +00:00
|
|
|
fNarrowWeekdaysCount == other.fNarrowWeekdaysCount &&
|
|
|
|
fStandaloneWeekdaysCount == other.fStandaloneWeekdaysCount &&
|
|
|
|
fStandaloneShortWeekdaysCount == other.fStandaloneShortWeekdaysCount &&
|
|
|
|
fStandaloneNarrowWeekdaysCount == other.fStandaloneNarrowWeekdaysCount &&
|
2005-08-26 21:55:55 +00:00
|
|
|
fAmPmsCount == other.fAmPmsCount)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
// Now compare the arrays themselves
|
|
|
|
if (arrayCompare(fEras, other.fEras, fErasCount) &&
|
2005-07-01 17:22:22 +00:00
|
|
|
arrayCompare(fEraNames, other.fEraNames, fEraNamesCount) &&
|
1999-08-16 21:50:52 +00:00
|
|
|
arrayCompare(fMonths, other.fMonths, fMonthsCount) &&
|
|
|
|
arrayCompare(fShortMonths, other.fShortMonths, fShortMonthsCount) &&
|
2005-07-01 17:22:22 +00:00
|
|
|
arrayCompare(fNarrowMonths, other.fNarrowMonths, fNarrowMonthsCount) &&
|
|
|
|
arrayCompare(fStandaloneMonths, other.fStandaloneMonths, fStandaloneMonthsCount) &&
|
|
|
|
arrayCompare(fStandaloneShortMonths, other.fStandaloneShortMonths, fStandaloneShortMonthsCount) &&
|
|
|
|
arrayCompare(fStandaloneNarrowMonths, other.fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount) &&
|
1999-08-16 21:50:52 +00:00
|
|
|
arrayCompare(fWeekdays, other.fWeekdays, fWeekdaysCount) &&
|
|
|
|
arrayCompare(fShortWeekdays, other.fShortWeekdays, fShortWeekdaysCount) &&
|
2005-07-01 17:22:22 +00:00
|
|
|
arrayCompare(fNarrowWeekdays, other.fNarrowWeekdays, fNarrowWeekdaysCount) &&
|
|
|
|
arrayCompare(fStandaloneWeekdays, other.fStandaloneWeekdays, fStandaloneWeekdaysCount) &&
|
|
|
|
arrayCompare(fStandaloneShortWeekdays, other.fStandaloneShortWeekdays, fStandaloneShortWeekdaysCount) &&
|
|
|
|
arrayCompare(fStandaloneNarrowWeekdays, other.fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount) &&
|
1999-08-16 21:50:52 +00:00
|
|
|
arrayCompare(fAmPms, other.fAmPms, fAmPmsCount))
|
|
|
|
{
|
2005-08-26 21:55:55 +00:00
|
|
|
|
|
|
|
if(fZoneStringsHash == NULL || other.fZoneStringsHash == NULL){
|
|
|
|
// fZoneStringsHash is not initialized compare the resource bundles
|
|
|
|
if(ures_equal(fZoneArrayBundle, other.fZoneArrayBundle)== FALSE){
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if(hashCompare(fZoneStringsHash, other.fZoneStringsHash) == FALSE){
|
1999-08-16 21:50:52 +00:00
|
|
|
return FALSE;
|
2005-08-26 21:55:55 +00:00
|
|
|
}
|
|
|
|
// we always make sure that we update the enumeration when the hash is
|
|
|
|
// updated. So we can be sure that once we compare the hashes the
|
|
|
|
// enumerations are also equal
|
|
|
|
//if(stringEnumCompare(fZoneIDEnumeration, other.fZoneIDEnumeration)==FALSE){
|
|
|
|
// return FALSE;
|
|
|
|
//}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2005-08-26 21:55:55 +00:00
|
|
|
// since fZoneStrings data member is deprecated .. and may not be initialized
|
|
|
|
// so don't compare them
|
|
|
|
// fZoneStringsRowCount == other.fZoneStringsRowCount &&
|
|
|
|
//fZoneStringsColCount == other.fZoneStringsColCount
|
|
|
|
//if (fZoneStrings == other.fZoneStrings) return TRUE;
|
|
|
|
//
|
|
|
|
//for (int32_t row=0; row<fZoneStringsRowCount; ++row)
|
|
|
|
//{
|
|
|
|
// if (!arrayCompare(fZoneStrings[row], other.fZoneStrings[row], fZoneStringsColCount))
|
|
|
|
// return FALSE;
|
|
|
|
//}
|
1999-08-16 21:50:52 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------
|
|
|
|
|
|
|
|
const UnicodeString*
|
|
|
|
DateFormatSymbols::getEras(int32_t &count) const
|
|
|
|
{
|
|
|
|
count = fErasCount;
|
|
|
|
return fEras;
|
|
|
|
}
|
|
|
|
|
2005-06-24 21:39:08 +00:00
|
|
|
const UnicodeString*
|
|
|
|
DateFormatSymbols::getEraNames(int32_t &count) const
|
|
|
|
{
|
|
|
|
count = fEraNamesCount;
|
|
|
|
return fEraNames;
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
const UnicodeString*
|
|
|
|
DateFormatSymbols::getMonths(int32_t &count) const
|
|
|
|
{
|
|
|
|
count = fMonthsCount;
|
|
|
|
return fMonths;
|
|
|
|
}
|
|
|
|
|
|
|
|
const UnicodeString*
|
|
|
|
DateFormatSymbols::getShortMonths(int32_t &count) const
|
|
|
|
{
|
|
|
|
count = fShortMonthsCount;
|
|
|
|
return fShortMonths;
|
|
|
|
}
|
|
|
|
|
2005-06-24 21:39:08 +00:00
|
|
|
const UnicodeString*
|
|
|
|
DateFormatSymbols::getMonths(int32_t &count, DtContextType context, DtWidthType width ) const
|
|
|
|
{
|
2005-07-12 03:02:06 +00:00
|
|
|
UnicodeString *returnValue = NULL;
|
2005-07-01 17:22:22 +00:00
|
|
|
|
|
|
|
switch (context) {
|
|
|
|
case FORMAT :
|
|
|
|
switch(width) {
|
|
|
|
case WIDE :
|
|
|
|
count = fMonthsCount;
|
|
|
|
returnValue = fMonths;
|
|
|
|
break;
|
|
|
|
case ABBREVIATED :
|
|
|
|
count = fShortMonthsCount;
|
|
|
|
returnValue = fShortMonths;
|
|
|
|
break;
|
|
|
|
case NARROW :
|
|
|
|
count = fNarrowMonthsCount;
|
|
|
|
returnValue = fNarrowMonths;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STANDALONE :
|
|
|
|
switch(width) {
|
|
|
|
case WIDE :
|
|
|
|
count = fStandaloneMonthsCount;
|
|
|
|
returnValue = fStandaloneMonths;
|
|
|
|
break;
|
|
|
|
case ABBREVIATED :
|
|
|
|
count = fStandaloneShortMonthsCount;
|
|
|
|
returnValue = fStandaloneShortMonths;
|
|
|
|
break;
|
|
|
|
case NARROW :
|
|
|
|
count = fStandaloneNarrowMonthsCount;
|
|
|
|
returnValue = fStandaloneNarrowMonths;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return returnValue;
|
2005-06-24 21:39:08 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
const UnicodeString*
|
|
|
|
DateFormatSymbols::getWeekdays(int32_t &count) const
|
|
|
|
{
|
|
|
|
count = fWeekdaysCount;
|
|
|
|
return fWeekdays;
|
|
|
|
}
|
|
|
|
|
|
|
|
const UnicodeString*
|
|
|
|
DateFormatSymbols::getShortWeekdays(int32_t &count) const
|
|
|
|
{
|
|
|
|
count = fShortWeekdaysCount;
|
|
|
|
return fShortWeekdays;
|
|
|
|
}
|
|
|
|
|
2005-06-24 21:39:08 +00:00
|
|
|
const UnicodeString*
|
|
|
|
DateFormatSymbols::getWeekdays(int32_t &count, DtContextType context, DtWidthType width) const
|
|
|
|
{
|
2005-07-12 03:02:06 +00:00
|
|
|
UnicodeString *returnValue = NULL;
|
2005-07-01 17:22:22 +00:00
|
|
|
switch (context) {
|
|
|
|
case FORMAT :
|
|
|
|
switch(width) {
|
|
|
|
case WIDE :
|
|
|
|
count = fWeekdaysCount;
|
|
|
|
returnValue = fWeekdays;
|
|
|
|
break;
|
|
|
|
case ABBREVIATED :
|
|
|
|
count = fShortWeekdaysCount;
|
|
|
|
returnValue = fShortWeekdays;
|
|
|
|
break;
|
|
|
|
case NARROW :
|
|
|
|
count = fNarrowWeekdaysCount;
|
|
|
|
returnValue = fNarrowWeekdays;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STANDALONE :
|
|
|
|
switch(width) {
|
|
|
|
case WIDE :
|
|
|
|
count = fStandaloneWeekdaysCount;
|
|
|
|
returnValue = fStandaloneWeekdays;
|
|
|
|
break;
|
|
|
|
case ABBREVIATED :
|
|
|
|
count = fStandaloneShortWeekdaysCount;
|
|
|
|
returnValue = fStandaloneShortWeekdays;
|
|
|
|
break;
|
|
|
|
case NARROW :
|
|
|
|
count = fStandaloneNarrowWeekdaysCount;
|
|
|
|
returnValue = fStandaloneNarrowWeekdays;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return returnValue;
|
2005-06-24 21:39:08 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
const UnicodeString*
|
|
|
|
DateFormatSymbols::getAmPmStrings(int32_t &count) const
|
|
|
|
{
|
|
|
|
count = fAmPmsCount;
|
|
|
|
return fAmPms;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------
|
|
|
|
|
|
|
|
void
|
|
|
|
DateFormatSymbols::setEras(const UnicodeString* erasArray, int32_t count)
|
|
|
|
{
|
|
|
|
// delete the old list if we own it
|
2001-06-19 17:38:29 +00:00
|
|
|
if (fEras) delete[] fEras;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// we always own the new list, which we create here (we duplicate rather
|
|
|
|
// than adopting the list passed in)
|
2003-06-05 17:19:03 +00:00
|
|
|
fEras = newUnicodeStringArray(count);
|
1999-12-28 23:57:50 +00:00
|
|
|
uprv_arrayCopy(erasArray,fEras, count);
|
1999-08-16 21:50:52 +00:00
|
|
|
fErasCount = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DateFormatSymbols::setMonths(const UnicodeString* monthsArray, int32_t count)
|
|
|
|
{
|
|
|
|
// delete the old list if we own it
|
2001-06-19 17:38:29 +00:00
|
|
|
if (fMonths) delete[] fMonths;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// we always own the new list, which we create here (we duplicate rather
|
|
|
|
// than adopting the list passed in)
|
2003-06-05 17:19:03 +00:00
|
|
|
fMonths = newUnicodeStringArray(count);
|
1999-12-28 23:57:50 +00:00
|
|
|
uprv_arrayCopy( monthsArray,fMonths,count);
|
1999-08-16 21:50:52 +00:00
|
|
|
fMonthsCount = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DateFormatSymbols::setShortMonths(const UnicodeString* shortMonthsArray, int32_t count)
|
|
|
|
{
|
|
|
|
// delete the old list if we own it
|
2001-06-19 17:38:29 +00:00
|
|
|
if (fShortMonths) delete[] fShortMonths;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// we always own the new list, which we create here (we duplicate rather
|
|
|
|
// than adopting the list passed in)
|
2003-06-05 17:19:03 +00:00
|
|
|
fShortMonths = newUnicodeStringArray(count);
|
1999-12-28 23:57:50 +00:00
|
|
|
uprv_arrayCopy(shortMonthsArray,fShortMonths, count);
|
1999-08-16 21:50:52 +00:00
|
|
|
fShortMonthsCount = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DateFormatSymbols::setWeekdays(const UnicodeString* weekdaysArray, int32_t count)
|
|
|
|
{
|
|
|
|
// delete the old list if we own it
|
2001-06-19 17:38:29 +00:00
|
|
|
if (fWeekdays) delete[] fWeekdays;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// we always own the new list, which we create here (we duplicate rather
|
|
|
|
// than adopting the list passed in)
|
2003-06-05 17:19:03 +00:00
|
|
|
fWeekdays = newUnicodeStringArray(count);
|
1999-12-28 23:57:50 +00:00
|
|
|
uprv_arrayCopy(weekdaysArray,fWeekdays,count);
|
1999-08-16 21:50:52 +00:00
|
|
|
fWeekdaysCount = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DateFormatSymbols::setShortWeekdays(const UnicodeString* shortWeekdaysArray, int32_t count)
|
|
|
|
{
|
|
|
|
// delete the old list if we own it
|
2001-06-19 17:38:29 +00:00
|
|
|
if (fShortWeekdays) delete[] fShortWeekdays;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// we always own the new list, which we create here (we duplicate rather
|
|
|
|
// than adopting the list passed in)
|
2003-06-05 17:19:03 +00:00
|
|
|
fShortWeekdays = newUnicodeStringArray(count);
|
1999-12-28 23:57:50 +00:00
|
|
|
uprv_arrayCopy( shortWeekdaysArray,fShortWeekdays,count);
|
1999-08-16 21:50:52 +00:00
|
|
|
fShortWeekdaysCount = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DateFormatSymbols::setAmPmStrings(const UnicodeString* amPmsArray, int32_t count)
|
|
|
|
{
|
|
|
|
// delete the old list if we own it
|
2001-06-19 17:38:29 +00:00
|
|
|
if (fAmPms) delete[] fAmPms;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
// we always own the new list, which we create here (we duplicate rather
|
|
|
|
// than adopting the list passed in)
|
2003-06-05 17:19:03 +00:00
|
|
|
fAmPms = newUnicodeStringArray(count);
|
1999-12-28 23:57:50 +00:00
|
|
|
uprv_arrayCopy(amPmsArray,fAmPms,count);
|
1999-08-16 21:50:52 +00:00
|
|
|
fAmPmsCount = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------
|
|
|
|
|
|
|
|
const UnicodeString**
|
|
|
|
DateFormatSymbols::getZoneStrings(int32_t& rowCount, int32_t& columnCount) const
|
|
|
|
{
|
2005-08-26 21:55:55 +00:00
|
|
|
umtx_lock(&LOCK);
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
if(fZoneStrings==NULL){
|
|
|
|
// cast away const to get around the problem for lazy initialization
|
|
|
|
((DateFormatSymbols*)this)->initZoneStringsArray(status);
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
rowCount = fZoneStringsRowCount;
|
|
|
|
columnCount = fZoneStringsColCount;
|
2005-08-26 21:55:55 +00:00
|
|
|
umtx_unlock(&LOCK);
|
1999-08-16 21:50:52 +00:00
|
|
|
return (const UnicodeString**)fZoneStrings; // Compiler requires cast
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DateFormatSymbols::setZoneStrings(const UnicodeString* const *strings, int32_t rowCount, int32_t columnCount)
|
|
|
|
{
|
|
|
|
// since deleting a 2-d array is a pain in the butt, we offload that task to
|
|
|
|
// a separate function
|
|
|
|
disposeZoneStrings();
|
|
|
|
|
|
|
|
// we always own the new list, which we create here (we duplicate rather
|
|
|
|
// than adopting the list passed in)
|
|
|
|
fZoneStringsRowCount = rowCount;
|
|
|
|
fZoneStringsColCount = columnCount;
|
|
|
|
createZoneStrings((const UnicodeString**)strings);
|
2005-08-26 21:55:55 +00:00
|
|
|
initZoneStrings((const UnicodeString**)strings, rowCount,columnCount);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------
|
|
|
|
|
2004-08-24 17:38:33 +00:00
|
|
|
const UChar * U_EXPORT2
|
2001-09-18 21:36:45 +00:00
|
|
|
DateFormatSymbols::getPatternUChars(void)
|
|
|
|
{
|
|
|
|
return gPatternChars;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
UnicodeString&
|
|
|
|
DateFormatSymbols::getLocalPatternChars(UnicodeString& result) const
|
|
|
|
{
|
2002-10-15 00:36:11 +00:00
|
|
|
// fastCopyFrom() - see assignArray comments
|
|
|
|
return result.fastCopyFrom(fLocalPatternChars);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------
|
|
|
|
|
|
|
|
void
|
|
|
|
DateFormatSymbols::setLocalPatternChars(const UnicodeString& newLocalPatternChars)
|
|
|
|
{
|
|
|
|
fLocalPatternChars = newLocalPatternChars;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------
|
|
|
|
|
2005-01-09 05:18:02 +00:00
|
|
|
static void
|
|
|
|
initField(UnicodeString **field, int32_t& length, const UResourceBundle *data, UErrorCode &status) {
|
2001-06-19 17:38:29 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
2004-08-31 18:04:12 +00:00
|
|
|
int32_t strLen = 0;
|
|
|
|
length = ures_getSize(data);
|
2003-06-05 17:19:03 +00:00
|
|
|
*field = newUnicodeStringArray(length);
|
2001-06-19 17:38:29 +00:00
|
|
|
if (*field) {
|
|
|
|
for(int32_t i = 0; i<length; i++) {
|
2004-08-31 18:04:12 +00:00
|
|
|
const UChar *resStr = ures_getStringByIndex(data, i, &strLen, &status);
|
|
|
|
// setTo() - see assignArray comments
|
|
|
|
(*(field)+i)->setTo(TRUE, resStr, strLen);
|
2001-06-19 17:38:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
length = 0;
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-09 05:18:02 +00:00
|
|
|
static void
|
|
|
|
initField(UnicodeString **field, int32_t& length, const UChar *data, LastResortSize numStr, LastResortSize strLen, UErrorCode &status) {
|
2001-06-19 17:38:29 +00:00
|
|
|
if (U_SUCCESS(status)) {
|
|
|
|
length = numStr;
|
2003-06-05 17:19:03 +00:00
|
|
|
*field = newUnicodeStringArray((size_t)numStr);
|
2001-06-19 17:38:29 +00:00
|
|
|
if (*field) {
|
|
|
|
for(int32_t i = 0; i<length; i++) {
|
2002-10-15 00:36:11 +00:00
|
|
|
// readonly aliases - all "data" strings are constant
|
|
|
|
// -1 as length for variable-length strings (gLastResortDayNames[0] is empty)
|
|
|
|
(*(field)+i)->setTo(TRUE, data+(i*((int32_t)strLen)), -1);
|
2001-06-19 17:38:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
length = 0;
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
void
|
2003-05-16 22:05:41 +00:00
|
|
|
DateFormatSymbols::initializeData(const Locale& locale, const char *type, UErrorCode& status, UBool useLastResortData)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2000-05-24 20:58:31 +00:00
|
|
|
int32_t i;
|
2004-08-31 00:35:04 +00:00
|
|
|
int32_t len = 0;
|
|
|
|
const UChar *resStr;
|
2005-08-26 21:55:55 +00:00
|
|
|
static const UnicodeString colon((UChar)0x003a);
|
|
|
|
static const UnicodeString solidus((UChar)0x002f);
|
2002-08-23 17:39:22 +00:00
|
|
|
/* In case something goes wrong, initialize all of the data to NULL. */
|
|
|
|
fEras = NULL;
|
2003-06-05 00:00:07 +00:00
|
|
|
fErasCount = 0;
|
2005-06-24 21:39:08 +00:00
|
|
|
fEraNames = NULL;
|
|
|
|
fEraNamesCount = 0;
|
2002-08-23 17:39:22 +00:00
|
|
|
fMonths = NULL;
|
2003-06-05 00:00:07 +00:00
|
|
|
fMonthsCount=0;
|
2002-08-23 17:39:22 +00:00
|
|
|
fShortMonths = NULL;
|
2003-06-05 00:00:07 +00:00
|
|
|
fShortMonthsCount=0;
|
2005-06-24 21:39:08 +00:00
|
|
|
fNarrowMonths = NULL;
|
|
|
|
fNarrowMonthsCount=0;
|
|
|
|
fStandaloneMonths = NULL;
|
|
|
|
fStandaloneMonthsCount=0;
|
|
|
|
fStandaloneShortMonths = NULL;
|
|
|
|
fStandaloneShortMonthsCount=0;
|
|
|
|
fStandaloneNarrowMonths = NULL;
|
|
|
|
fStandaloneNarrowMonthsCount=0;
|
2002-08-23 17:39:22 +00:00
|
|
|
fWeekdays = NULL;
|
2003-06-05 00:00:07 +00:00
|
|
|
fWeekdaysCount=0;
|
2002-08-23 17:39:22 +00:00
|
|
|
fShortWeekdays = NULL;
|
2003-06-05 00:00:07 +00:00
|
|
|
fShortWeekdaysCount=0;
|
2005-06-24 21:39:08 +00:00
|
|
|
fNarrowWeekdays = NULL;
|
|
|
|
fNarrowWeekdaysCount=0;
|
|
|
|
fStandaloneWeekdays = NULL;
|
|
|
|
fStandaloneWeekdaysCount=0;
|
|
|
|
fStandaloneShortWeekdays = NULL;
|
|
|
|
fStandaloneShortWeekdaysCount=0;
|
|
|
|
fStandaloneNarrowWeekdays = NULL;
|
|
|
|
fStandaloneNarrowWeekdaysCount=0;
|
2002-08-23 17:39:22 +00:00
|
|
|
fAmPms = NULL;
|
2003-06-05 00:00:07 +00:00
|
|
|
fAmPmsCount=0;
|
2002-08-23 17:39:22 +00:00
|
|
|
fZoneStringsRowCount = 0;
|
|
|
|
fZoneStringsColCount = 0;
|
|
|
|
fZoneStrings = NULL;
|
2005-08-26 21:55:55 +00:00
|
|
|
fZoneStringsHash = NULL;
|
|
|
|
fZoneIDEnumeration = NULL;
|
|
|
|
fZoneArrayBundle = NULL;
|
|
|
|
|
|
|
|
|
2001-06-19 17:38:29 +00:00
|
|
|
if (U_FAILURE(status)) return;
|
2000-05-24 20:58:31 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/**
|
|
|
|
* Retrieve the string arrays we need from the resource bundle file.
|
|
|
|
* We cast away const here, but that's okay; we won't delete any of
|
|
|
|
* these.
|
|
|
|
*/
|
2004-05-18 02:06:28 +00:00
|
|
|
CalendarData calData(locale, type, status);
|
2004-08-31 00:35:04 +00:00
|
|
|
UResourceBundle *nonCalendarData = ures_open((char*)0, locale.getName(), &status);
|
2004-05-18 02:06:28 +00:00
|
|
|
|
2004-08-31 00:35:04 +00:00
|
|
|
// load the first data item
|
2004-08-31 18:04:12 +00:00
|
|
|
UResourceBundle *erasMain = calData.getByKey(gErasTag, status);
|
|
|
|
UResourceBundle *eras = ures_getByKeyWithFallback(erasMain, gAbbreviatedTag, NULL, &status);
|
2005-07-02 02:57:07 +00:00
|
|
|
UErrorCode oldStatus = status;
|
2005-07-01 17:22:22 +00:00
|
|
|
UResourceBundle *eraNames = ures_getByKeyWithFallback(erasMain, gNamesWideTag, NULL, &status);
|
2005-07-02 02:57:07 +00:00
|
|
|
if ( status == U_MISSING_RESOURCE_ERROR ) { // Workaround because eras/wide was omitted from CLDR 1.3
|
|
|
|
status = oldStatus;
|
|
|
|
eraNames = ures_getByKeyWithFallback(erasMain, gAbbreviatedTag, NULL, &status);
|
|
|
|
}
|
|
|
|
|
2004-08-31 18:04:12 +00:00
|
|
|
UResourceBundle *lsweekdaysData = NULL; // Data closed by calData
|
|
|
|
UResourceBundle *weekdaysData = NULL; // Data closed by calData
|
2005-07-01 17:22:22 +00:00
|
|
|
UResourceBundle *narrowWeekdaysData = NULL; // Data closed by calData
|
|
|
|
UResourceBundle *standaloneWeekdaysData = NULL; // Data closed by calData
|
|
|
|
UResourceBundle *standaloneShortWeekdaysData = NULL; // Data closed by calData
|
|
|
|
UResourceBundle *standaloneNarrowWeekdaysData = NULL; // Data closed by calData
|
2005-08-26 21:55:55 +00:00
|
|
|
fZoneArrayBundle = ures_getByKey(nonCalendarData, gZoneStringsTag, NULL, &status);
|
|
|
|
|
2004-08-31 00:35:04 +00:00
|
|
|
U_LOCALE_BASED(locBased, *this);
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
if (useLastResortData)
|
|
|
|
{
|
|
|
|
// Handle the case in which there is no resource data present.
|
|
|
|
// We don't have to generate usable patterns in this situation;
|
|
|
|
// we just need to produce something that will be semi-intelligible
|
|
|
|
// in most locales.
|
|
|
|
|
2002-08-21 19:12:24 +00:00
|
|
|
status = U_USING_FALLBACK_WARNING;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-07-06 23:19:56 +00:00
|
|
|
initField(&fEras, fErasCount, (const UChar *)gLastResortEras, kEraNum, kEraLen, status);
|
2005-07-01 17:22:22 +00:00
|
|
|
initField(&fEraNames, fEraNamesCount, (const UChar *)gLastResortEras, kEraNum, kEraLen, status);
|
2001-07-06 23:19:56 +00:00
|
|
|
initField(&fMonths, fMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status);
|
|
|
|
initField(&fShortMonths, fShortMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status);
|
2005-07-01 17:22:22 +00:00
|
|
|
initField(&fNarrowMonths, fNarrowMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status);
|
|
|
|
initField(&fStandaloneMonths, fStandaloneMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status);
|
|
|
|
initField(&fStandaloneShortMonths, fStandaloneShortMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status);
|
|
|
|
initField(&fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, (const UChar *)gLastResortMonthNames, kMonthNum, kMonthLen, status);
|
2001-07-06 23:19:56 +00:00
|
|
|
initField(&fWeekdays, fWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status);
|
|
|
|
initField(&fShortWeekdays, fShortWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status);
|
2005-07-01 17:22:22 +00:00
|
|
|
initField(&fNarrowWeekdays, fNarrowWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status);
|
|
|
|
initField(&fStandaloneWeekdays, fStandaloneWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status);
|
|
|
|
initField(&fStandaloneShortWeekdays, fStandaloneShortWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status);
|
|
|
|
initField(&fStandaloneNarrowWeekdays, fStandaloneNarrowWeekdaysCount, (const UChar *)gLastResortDayNames, kDayNum, kDayLen, status);
|
2001-07-06 23:19:56 +00:00
|
|
|
initField(&fAmPms, fAmPmsCount, (const UChar *)gLastResortAmPmMarkers, kAmPmNum, kAmPmLen, status);
|
|
|
|
fLocalPatternChars = gPatternChars;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2004-08-31 00:35:04 +00:00
|
|
|
goto cleanup;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if we make it to here, the resource data is cool, and we can get everything out
|
|
|
|
// of it that we need except for the time-zone and localized-pattern data, which
|
2004-01-20 23:06:38 +00:00
|
|
|
// are stored in a separate file
|
2004-08-31 18:04:12 +00:00
|
|
|
locBased.setLocaleIDs(ures_getLocaleByType(eras, ULOC_VALID_LOCALE, &status),
|
|
|
|
ures_getLocaleByType(eras, ULOC_ACTUAL_LOCALE, &status));
|
2004-08-31 00:35:04 +00:00
|
|
|
initField(&fEras, fErasCount, eras, status);
|
2005-07-01 17:22:22 +00:00
|
|
|
initField(&fEraNames, fEraNamesCount, eraNames, status);
|
2004-08-31 18:04:12 +00:00
|
|
|
initField(&fMonths, fMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesWideTag, status), status);
|
|
|
|
initField(&fShortMonths, fShortMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesAbbrTag, status), status);
|
2005-07-01 17:22:22 +00:00
|
|
|
initField(&fNarrowMonths, fNarrowMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesNarrowTag, status), status);
|
|
|
|
if ( status == U_MISSING_RESOURCE_ERROR ) { /* If format/narrow not available, use format/abbreviated */
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
initField(&fNarrowMonths, fNarrowMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesAbbrTag, status), status);
|
|
|
|
}
|
|
|
|
initField(&fStandaloneMonths, fStandaloneMonthsCount, calData.getByKey3(gMonthNamesTag, gNamesStandaloneTag, gNamesWideTag, status), status);
|
|
|
|
if ( status == U_MISSING_RESOURCE_ERROR ) { /* If standalone/wide not available, use format/wide */
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
initField(&fStandaloneMonths, fStandaloneMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesWideTag, status), status);
|
|
|
|
}
|
|
|
|
initField(&fStandaloneShortMonths, fStandaloneShortMonthsCount, calData.getByKey3(gMonthNamesTag, gNamesStandaloneTag, gNamesAbbrTag, status), status);
|
|
|
|
if ( status == U_MISSING_RESOURCE_ERROR ) { /* If standalone/abbreviated not available, use format/abbreviated */
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
initField(&fStandaloneShortMonths, fStandaloneShortMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesAbbrTag, status), status);
|
|
|
|
}
|
|
|
|
initField(&fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, calData.getByKey3(gMonthNamesTag, gNamesStandaloneTag, gNamesNarrowTag, status), status);
|
|
|
|
if ( status == U_MISSING_RESOURCE_ERROR ) { /* if standalone/narrow not availabe, try format/narrow */
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
initField(&fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesNarrowTag, status), status);
|
|
|
|
if ( status == U_MISSING_RESOURCE_ERROR ) { /* if still not there, use format/abbreviated */
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
initField(&fStandaloneNarrowMonths, fStandaloneNarrowMonthsCount, calData.getByKey2(gMonthNamesTag, gNamesAbbrTag, status), status);
|
|
|
|
}
|
|
|
|
}
|
2004-08-31 18:04:12 +00:00
|
|
|
initField(&fAmPms, fAmPmsCount, calData.getByKey(gAmPmMarkersTag, status), status);
|
2004-05-18 02:06:28 +00:00
|
|
|
|
2004-08-31 00:35:04 +00:00
|
|
|
// fastCopyFrom()/setTo() - see assignArray comments
|
|
|
|
resStr = ures_getStringByKey(nonCalendarData, gLocalPatternCharsTag, &len, &status);
|
|
|
|
fLocalPatternChars.setTo(TRUE, resStr, len);
|
2004-08-31 18:04:12 +00:00
|
|
|
// If the locale data does not include new pattern chars, use the defaults
|
|
|
|
// TODO: Consider making this an error, since this may add conflicting characters.
|
|
|
|
if (len < PATTERN_CHARS_LEN) {
|
|
|
|
fLocalPatternChars.append(UnicodeString(TRUE, &gPatternChars[len], PATTERN_CHARS_LEN-len));
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
// {sfb} fixed to handle 1-based weekdays
|
2004-08-31 18:04:12 +00:00
|
|
|
weekdaysData = calData.getByKey2(gDayNamesTag, gNamesWideTag, status);
|
|
|
|
fWeekdaysCount = ures_getSize(weekdaysData);
|
2000-05-15 18:39:17 +00:00
|
|
|
fWeekdays = new UnicodeString[fWeekdaysCount+1];
|
2002-07-02 15:10:30 +00:00
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
if (fWeekdays == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
2004-08-31 00:35:04 +00:00
|
|
|
goto cleanup;
|
2002-06-29 09:31:05 +00:00
|
|
|
}
|
2002-10-15 00:36:11 +00:00
|
|
|
// leave fWeekdays[0] empty
|
2000-05-15 18:39:17 +00:00
|
|
|
for(i = 0; i<fWeekdaysCount; i++) {
|
2004-08-31 18:04:12 +00:00
|
|
|
resStr = ures_getStringByIndex(weekdaysData, i, &len, &status);
|
|
|
|
// setTo() - see assignArray comments
|
|
|
|
fWeekdays[i+1].setTo(TRUE, resStr, len);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2003-11-19 05:39:21 +00:00
|
|
|
fWeekdaysCount++;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-08-31 18:04:12 +00:00
|
|
|
lsweekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status);
|
|
|
|
fShortWeekdaysCount = ures_getSize(lsweekdaysData);
|
2000-05-15 18:39:17 +00:00
|
|
|
fShortWeekdays = new UnicodeString[fShortWeekdaysCount+1];
|
2002-07-02 15:10:30 +00:00
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
if (fShortWeekdays == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
2004-08-31 00:35:04 +00:00
|
|
|
goto cleanup;
|
2002-06-29 09:31:05 +00:00
|
|
|
}
|
2002-10-15 00:36:11 +00:00
|
|
|
// leave fShortWeekdays[0] empty
|
2000-05-15 18:39:17 +00:00
|
|
|
for(i = 0; i<fShortWeekdaysCount; i++) {
|
2004-08-31 18:04:12 +00:00
|
|
|
resStr = ures_getStringByIndex(lsweekdaysData, i, &len, &status);
|
|
|
|
// setTo() - see assignArray comments
|
|
|
|
fShortWeekdays[i+1].setTo(TRUE, resStr, len);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2003-11-19 05:39:21 +00:00
|
|
|
fShortWeekdaysCount++;
|
2005-07-01 17:22:22 +00:00
|
|
|
|
|
|
|
narrowWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesNarrowTag, status);
|
|
|
|
if ( status == U_MISSING_RESOURCE_ERROR ) {
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
narrowWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status);
|
|
|
|
}
|
|
|
|
fNarrowWeekdaysCount = ures_getSize(narrowWeekdaysData);
|
|
|
|
fNarrowWeekdays = new UnicodeString[fNarrowWeekdaysCount+1];
|
|
|
|
/* test for NULL */
|
|
|
|
if (fNarrowWeekdays == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
// leave fNarrowWeekdays[0] empty
|
|
|
|
for(i = 0; i<fNarrowWeekdaysCount; i++) {
|
|
|
|
resStr = ures_getStringByIndex(narrowWeekdaysData, i, &len, &status);
|
|
|
|
// setTo() - see assignArray comments
|
|
|
|
fNarrowWeekdays[i+1].setTo(TRUE, resStr, len);
|
|
|
|
}
|
|
|
|
fNarrowWeekdaysCount++;
|
|
|
|
|
|
|
|
standaloneWeekdaysData = calData.getByKey3(gDayNamesTag, gNamesStandaloneTag, gNamesWideTag, status);
|
|
|
|
if ( status == U_MISSING_RESOURCE_ERROR ) {
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
standaloneWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesWideTag, status);
|
|
|
|
}
|
|
|
|
fStandaloneWeekdaysCount = ures_getSize(standaloneWeekdaysData);
|
|
|
|
fStandaloneWeekdays = new UnicodeString[fStandaloneWeekdaysCount+1];
|
|
|
|
/* test for NULL */
|
|
|
|
if (fStandaloneWeekdays == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
// leave fStandaloneWeekdays[0] empty
|
|
|
|
for(i = 0; i<fStandaloneWeekdaysCount; i++) {
|
|
|
|
resStr = ures_getStringByIndex(standaloneWeekdaysData, i, &len, &status);
|
|
|
|
// setTo() - see assignArray comments
|
|
|
|
fStandaloneWeekdays[i+1].setTo(TRUE, resStr, len);
|
|
|
|
}
|
|
|
|
fStandaloneWeekdaysCount++;
|
|
|
|
|
|
|
|
standaloneShortWeekdaysData = calData.getByKey3(gDayNamesTag, gNamesStandaloneTag, gNamesAbbrTag, status);
|
|
|
|
if ( status == U_MISSING_RESOURCE_ERROR ) {
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
standaloneShortWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status);
|
|
|
|
}
|
|
|
|
fStandaloneShortWeekdaysCount = ures_getSize(standaloneShortWeekdaysData);
|
|
|
|
fStandaloneShortWeekdays = new UnicodeString[fStandaloneShortWeekdaysCount+1];
|
|
|
|
/* test for NULL */
|
|
|
|
if (fStandaloneShortWeekdays == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
// leave fStandaloneShortWeekdays[0] empty
|
|
|
|
for(i = 0; i<fStandaloneShortWeekdaysCount; i++) {
|
|
|
|
resStr = ures_getStringByIndex(standaloneShortWeekdaysData, i, &len, &status);
|
|
|
|
// setTo() - see assignArray comments
|
|
|
|
fStandaloneShortWeekdays[i+1].setTo(TRUE, resStr, len);
|
|
|
|
}
|
|
|
|
fStandaloneShortWeekdaysCount++;
|
|
|
|
|
|
|
|
standaloneNarrowWeekdaysData = calData.getByKey3(gDayNamesTag, gNamesStandaloneTag, gNamesNarrowTag, status);
|
|
|
|
if ( status == U_MISSING_RESOURCE_ERROR ) {
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
standaloneNarrowWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesNarrowTag, status);
|
|
|
|
if ( status == U_MISSING_RESOURCE_ERROR ) {
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
standaloneNarrowWeekdaysData = calData.getByKey2(gDayNamesTag, gNamesAbbrTag, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fStandaloneNarrowWeekdaysCount = ures_getSize(standaloneNarrowWeekdaysData);
|
|
|
|
fStandaloneNarrowWeekdays = new UnicodeString[fStandaloneNarrowWeekdaysCount+1];
|
|
|
|
/* test for NULL */
|
|
|
|
if (fStandaloneNarrowWeekdays == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
// leave fStandaloneNarrowWeekdays[0] empty
|
|
|
|
for(i = 0; i<fStandaloneNarrowWeekdaysCount; i++) {
|
|
|
|
resStr = ures_getStringByIndex(standaloneNarrowWeekdaysData, i, &len, &status);
|
|
|
|
// setTo() - see assignArray comments
|
|
|
|
fStandaloneNarrowWeekdays[i+1].setTo(TRUE, resStr, len);
|
|
|
|
}
|
|
|
|
fStandaloneNarrowWeekdaysCount++;
|
|
|
|
|
2004-08-31 00:35:04 +00:00
|
|
|
cleanup:
|
2004-08-31 20:31:03 +00:00
|
|
|
ures_close(eras);
|
2005-07-01 17:22:22 +00:00
|
|
|
ures_close(eraNames);
|
2004-08-31 00:35:04 +00:00
|
|
|
ures_close(nonCalendarData);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Package private: used by SimpleDateFormat
|
|
|
|
* Gets the index for the given time zone ID to obtain the timezone
|
|
|
|
* strings for formatting. The time zone ID is just for programmatic
|
|
|
|
* lookup. NOT LOCALIZED!!!
|
|
|
|
* @param ID the given time zone ID.
|
|
|
|
* @return the index of the given time zone ID. Returns -1 if
|
|
|
|
* the given time zone ID can't be located in the DateFormatSymbols object.
|
|
|
|
* @see java.util.SimpleTimeZone
|
|
|
|
*/
|
|
|
|
int32_t DateFormatSymbols::getZoneIndex(const UnicodeString& ID) const
|
2000-09-27 19:16:54 +00:00
|
|
|
{
|
|
|
|
int32_t result = _getZoneIndex(ID);
|
|
|
|
if (result >= 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<n; ++i) {
|
|
|
|
UnicodeString equivID = TimeZone::getEquivalentID(ID, i);
|
|
|
|
if (equivID != ID) {
|
|
|
|
int32_t equivResult = _getZoneIndex(equivID);
|
|
|
|
if (equivResult >= 0) {
|
|
|
|
return equivResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup the given ID. Do NOT do an equivalency search.
|
|
|
|
*/
|
|
|
|
int32_t DateFormatSymbols::_getZoneIndex(const UnicodeString& ID) const
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
for(int32_t index = 0; index < fZoneStringsRowCount; index++) {
|
2002-10-12 01:09:00 +00:00
|
|
|
if (0 == ID.caseCompare(fZoneStrings[index][0], 0)) {
|
1999-08-16 21:50:52 +00:00
|
|
|
return index;
|
2000-09-27 19:16:54 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-01-20 23:06:38 +00:00
|
|
|
Locale
|
|
|
|
DateFormatSymbols::getLocale(ULocDataLocaleType type, UErrorCode& status) const {
|
|
|
|
U_LOCALE_BASED(locBased, *this);
|
|
|
|
return locBased.getLocale(type, status);
|
|
|
|
}
|
|
|
|
|
2005-08-26 21:55:55 +00:00
|
|
|
|
|
|
|
class TimeZoneKeysEnumeration : public StringEnumeration {
|
|
|
|
private:
|
|
|
|
UnicodeString* strings;
|
|
|
|
int32_t length;
|
|
|
|
int32_t current;
|
|
|
|
int32_t capacity;
|
|
|
|
TimeZoneKeysEnumeration(UnicodeString* oldStrs, int32_t count){
|
|
|
|
strings = newUnicodeStringArray(count);
|
|
|
|
if(strings==NULL){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
capacity = count;
|
|
|
|
current = 0;
|
|
|
|
for(length = 0; length<capacity; length++){
|
|
|
|
strings[length].setTo(oldStrs[length]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
static UClassID U_EXPORT2 getStaticClassID(void);
|
|
|
|
virtual UClassID getDynamicClassID(void) const;
|
|
|
|
|
|
|
|
TimeZoneKeysEnumeration(int32_t count, UErrorCode status){
|
|
|
|
strings = newUnicodeStringArray(count);
|
|
|
|
if(strings == NULL){
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
}
|
|
|
|
length = 0;
|
|
|
|
current = 0;
|
|
|
|
capacity = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void put(const UnicodeString& str, UErrorCode& status){
|
|
|
|
if(length < capacity){
|
|
|
|
strings[length++].setTo(str);
|
|
|
|
}else{
|
|
|
|
status = U_INDEX_OUTOFBOUNDS_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virtual ~TimeZoneKeysEnumeration() {
|
|
|
|
delete[] strings;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual StringEnumeration * clone() const
|
|
|
|
{
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
return new TimeZoneKeysEnumeration(strings, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int32_t count(UErrorCode &/*status*/) const {
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
virtual const UChar* unext(int32_t *resultLength, UErrorCode& status){
|
|
|
|
if(current < length){
|
|
|
|
const UChar* ret = strings[current].getBuffer();
|
|
|
|
*resultLength = strings[current].length();
|
|
|
|
current++;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual const UnicodeString* snext(UErrorCode& status) {
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(current < length){
|
|
|
|
return &strings[current++];
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* this method is for thread safe iteration */
|
|
|
|
const UnicodeString* snext(int32_t& pos, UErrorCode& status) {
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(pos < length){
|
|
|
|
return &strings[pos++];
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void reset(UErrorCode& /*status*/) {
|
|
|
|
current = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TimeZoneKeysEnumeration);
|
|
|
|
|
|
|
|
void
|
|
|
|
DateFormatSymbols::initZoneStringsArray(UErrorCode& status){
|
|
|
|
if(fZoneStringsHash == NULL){
|
|
|
|
initZoneStrings(fZoneArrayBundle, (const UChar *)gLastResortZoneStrings, ARRAY_LENGTH(gLastResortZoneStrings), status);
|
|
|
|
}
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fZoneStringsRowCount = fZoneIDEnumeration->count(status);
|
|
|
|
fZoneStringsColCount = 8;
|
|
|
|
fZoneStrings = (UnicodeString **)uprv_malloc(fZoneStringsRowCount * sizeof(UnicodeString *));
|
|
|
|
/* test for NULL */
|
|
|
|
if (fZoneStrings == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const UnicodeString *zid = NULL;
|
|
|
|
TimeZoneKeysEnumeration *keys = (TimeZoneKeysEnumeration*) fZoneIDEnumeration;
|
|
|
|
int32_t pos = 0;
|
|
|
|
int32_t i = 0;
|
|
|
|
while((zid=keys->snext(pos,status))!=NULL){
|
|
|
|
*(fZoneStrings+i) = newUnicodeStringArray(fZoneStringsColCount);
|
|
|
|
/* test for NULL */
|
|
|
|
if ((*(fZoneStrings+i)) == 0) {
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
UnicodeString* strings = (UnicodeString*)fZoneStringsHash->get(*zid);
|
|
|
|
fZoneStrings[i][0].setTo(*zid);
|
|
|
|
fZoneStrings[i][1].setTo(strings[TIMEZONE_LONG_STANDARD]);
|
|
|
|
fZoneStrings[i][2].setTo(strings[TIMEZONE_SHORT_STANDARD]);
|
|
|
|
fZoneStrings[i][3].setTo(strings[TIMEZONE_LONG_DAYLIGHT]);
|
|
|
|
fZoneStrings[i][4].setTo(strings[TIMEZONE_SHORT_DAYLIGHT]);
|
|
|
|
fZoneStrings[i][5].setTo(strings[TIMEZONE_EXEMPLAR_CITY]);
|
|
|
|
if(fZoneStrings[i][5].length()==0){
|
|
|
|
fZoneStrings[i][5].setTo(strings[TIMEZONE_LONG_GENERIC]);
|
|
|
|
}else{
|
|
|
|
fZoneStrings[i][6].setTo(strings[TIMEZONE_LONG_GENERIC]);
|
|
|
|
}
|
|
|
|
if(fZoneStrings[i][6].length()==0){
|
|
|
|
fZoneStrings[i][6].setTo(strings[TIMEZONE_LONG_GENERIC]);
|
|
|
|
}else{
|
|
|
|
fZoneStrings[i][7].setTo(strings[TIMEZONE_LONG_GENERIC]);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DateFormatSymbols::initZoneStrings(UResourceBundle* bundle, const UChar* lastResortStrings,
|
|
|
|
int32_t length, UErrorCode &status){
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(fZoneStringsHash != NULL){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int32_t i;
|
|
|
|
if(bundle != NULL){
|
|
|
|
static const UnicodeString solidus("/");
|
|
|
|
static const UnicodeString colon(":");
|
|
|
|
UResourceBundle zoneItem;
|
|
|
|
ures_initStackObject(&zoneItem);
|
|
|
|
fZoneStringsHash = new Hashtable(status);
|
|
|
|
if(fZoneStringsHash==NULL){
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TimeZoneKeysEnumeration* keysEnum = new TimeZoneKeysEnumeration(ures_getSize(bundle),status);
|
|
|
|
fZoneIDEnumeration = keysEnum;
|
|
|
|
if(fZoneIDEnumeration==NULL){
|
|
|
|
delete fZoneStringsHash;
|
|
|
|
fZoneStringsHash = NULL;
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
while(ures_hasNext(bundle)){
|
|
|
|
UErrorCode tempStatus = U_ZERO_ERROR;
|
|
|
|
UnicodeString* array = newUnicodeStringArray(UTZ_MAX_DISPLAY_STRINGS_LENGTH);
|
|
|
|
ures_getNextResource(bundle, &zoneItem, &status);
|
|
|
|
UnicodeString key(ures_getKey(&zoneItem));
|
|
|
|
key.findAndReplace(colon, solidus);
|
|
|
|
keysEnum->put(key, status);
|
|
|
|
int32_t len = 0;
|
|
|
|
//fetch the strings with fine grained fallback
|
|
|
|
const UChar* str = ures_getStringByKeyWithFallback(&zoneItem,UTZ_SHORT_STANDARD, &len, &tempStatus);
|
|
|
|
if(U_SUCCESS(tempStatus)){
|
|
|
|
array[TIMEZONE_SHORT_STANDARD].setTo(str, len);
|
|
|
|
}else{
|
|
|
|
tempStatus = U_ZERO_ERROR;
|
|
|
|
}
|
|
|
|
str = ures_getStringByKeyWithFallback(&zoneItem,UTZ_SHORT_GENERIC, &len, &tempStatus);
|
|
|
|
if(U_SUCCESS(tempStatus)){
|
|
|
|
array[TIMEZONE_SHORT_GENERIC].setTo(str, len);
|
|
|
|
}else{
|
|
|
|
tempStatus = U_ZERO_ERROR;
|
|
|
|
}
|
|
|
|
str = ures_getStringByKeyWithFallback(&zoneItem,UTZ_SHORT_DAYLIGHT, &len, &tempStatus);
|
|
|
|
if(U_SUCCESS(tempStatus)){
|
|
|
|
array[TIMEZONE_SHORT_DAYLIGHT].setTo(str, len);
|
|
|
|
}else{
|
|
|
|
tempStatus = U_ZERO_ERROR;
|
|
|
|
}
|
|
|
|
str = ures_getStringByKeyWithFallback(&zoneItem,UTZ_LONG_STANDARD, &len, &tempStatus);
|
|
|
|
if(U_SUCCESS(tempStatus)){
|
|
|
|
array[TIMEZONE_LONG_STANDARD].setTo(str, len);
|
|
|
|
}else{
|
|
|
|
tempStatus = U_ZERO_ERROR;
|
|
|
|
}
|
|
|
|
str = ures_getStringByKeyWithFallback(&zoneItem,UTZ_LONG_GENERIC, &len, &tempStatus);
|
|
|
|
if(U_SUCCESS(tempStatus)){
|
|
|
|
array[TIMEZONE_LONG_GENERIC].setTo(str, len);
|
|
|
|
}else{
|
|
|
|
tempStatus = U_ZERO_ERROR;
|
|
|
|
}
|
|
|
|
str = ures_getStringByKeyWithFallback(&zoneItem,UTZ_LONG_DAYLIGHT, &len, &tempStatus);
|
|
|
|
if(U_SUCCESS(tempStatus)){
|
|
|
|
array[TIMEZONE_LONG_DAYLIGHT].setTo(str, len);
|
|
|
|
}else{
|
|
|
|
tempStatus = U_ZERO_ERROR;
|
|
|
|
}
|
|
|
|
str = ures_getStringByKeyWithFallback(&zoneItem,UTZ_EXEMPLAR_CITY, &len, &tempStatus);
|
|
|
|
if(U_SUCCESS(tempStatus)){
|
|
|
|
array[TIMEZONE_EXEMPLAR_CITY].setTo(str, len);
|
|
|
|
}else{
|
|
|
|
tempStatus = U_ZERO_ERROR;
|
|
|
|
}
|
|
|
|
// store the strings in hash
|
|
|
|
fZoneStringsHash->put(key, array, status);
|
|
|
|
}
|
|
|
|
ures_close(&zoneItem);
|
|
|
|
}else{
|
|
|
|
//last resort strings
|
|
|
|
fZoneStringsHash = new Hashtable(status);
|
|
|
|
if(fZoneStringsHash==NULL){
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
UnicodeString* array = newUnicodeStringArray(UTZ_MAX_DISPLAY_STRINGS_LENGTH);
|
|
|
|
if(fZoneStringsHash==NULL){
|
|
|
|
delete fZoneStringsHash;
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString key(lastResortStrings[0]);
|
|
|
|
TimeZoneKeysEnumeration* keysEnum = new TimeZoneKeysEnumeration(ures_getSize(bundle),status);
|
|
|
|
fZoneIDEnumeration = keysEnum;
|
|
|
|
if(fZoneIDEnumeration==NULL){
|
|
|
|
delete fZoneStringsHash;
|
|
|
|
delete[] array;
|
|
|
|
fZoneStringsHash = NULL;
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
keysEnum->put(key, status);
|
|
|
|
int32_t j=1;
|
|
|
|
for(i=0; i< length; ){
|
|
|
|
array[i++].setTo(lastResortStrings[j++]);
|
|
|
|
}
|
|
|
|
fZoneStringsHash->put(key, array, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void
|
|
|
|
DateFormatSymbols::initZoneStrings(const UnicodeString** strings, int32_t rowCount, int32_t columnCount){
|
|
|
|
// This method should have a status parameter
|
|
|
|
// but setZoneStrings API that calls this method does not have one
|
|
|
|
// setZoneStrings API is unsafe and should be deprecated!!
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
if(strings==NULL || rowCount<0 || columnCount<0){
|
|
|
|
status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TimeZoneKeysEnumeration* keysEnum = new TimeZoneKeysEnumeration(rowCount, status);
|
|
|
|
fZoneIDEnumeration = keysEnum;
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(fZoneIDEnumeration==NULL){
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fZoneStringsHash = new Hashtable(status);
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(fZoneStringsHash==NULL){
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (int32_t row=0; row<rowCount; ++row){
|
|
|
|
// the first string in the array is the key.
|
|
|
|
UnicodeString key = strings[row][0];
|
|
|
|
keysEnum->put(key, status);
|
|
|
|
UnicodeString* array = newUnicodeStringArray(UTZ_MAX_DISPLAY_STRINGS_LENGTH);
|
|
|
|
if(array==NULL){
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (int32_t col=1; col<columnCount; ++col) {
|
|
|
|
// fastCopyFrom() - see assignArray comments
|
|
|
|
switch (col){
|
|
|
|
case 1:
|
|
|
|
array[TIMEZONE_LONG_STANDARD].setTo(strings[row][col]);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
array[TIMEZONE_SHORT_STANDARD].setTo(strings[row][col]);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
array[TIMEZONE_LONG_DAYLIGHT].setTo(strings[row][col]);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
array[TIMEZONE_LONG_DAYLIGHT].setTo(strings[row][col]);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
if(fZoneStringsColCount==6 || fZoneStringsColCount==8){
|
|
|
|
array[TIMEZONE_EXEMPLAR_CITY].setTo(strings[row][col]);
|
|
|
|
}else{
|
|
|
|
array[TIMEZONE_LONG_GENERIC].setTo(strings[row][col]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
if(fZoneStringsColCount==8){
|
|
|
|
array[TIMEZONE_LONG_GENERIC].setTo(strings[row][col]);
|
|
|
|
}else{
|
|
|
|
array[TIMEZONE_SHORT_GENERIC].setTo(strings[row][col]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
array[TIMEZONE_SHORT_GENERIC].setTo(strings[row][col]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
}
|
|
|
|
// populate the hash table
|
|
|
|
fZoneStringsHash->put(strings[row][0], array, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString&
|
|
|
|
DateFormatSymbols::getZoneString(const UnicodeString &zid, const TimeZoneTranslationType type,
|
|
|
|
UnicodeString &result, UErrorCode &status){
|
|
|
|
|
|
|
|
if(fZoneStringsHash == NULL){
|
|
|
|
//lazy initialization
|
|
|
|
initZoneStrings(fZoneArrayBundle, (const UChar *)gLastResortZoneStrings, ARRAY_LENGTH(gLastResortZoneStrings), status);
|
|
|
|
}
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
UnicodeString* stringsArray = (UnicodeString*)fZoneStringsHash->get(zid);
|
|
|
|
if(stringsArray != NULL){
|
|
|
|
result.setTo(stringsArray[type],0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringEnumeration*
|
|
|
|
DateFormatSymbols::createZoneStringIDs(UErrorCode &status){
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(fZoneStringsHash == NULL){
|
|
|
|
//lazy initialization
|
|
|
|
initZoneStrings(fZoneArrayBundle, (const UChar *)gLastResortZoneStrings, ARRAY_LENGTH(gLastResortZoneStrings), status);
|
|
|
|
}
|
|
|
|
return fZoneIDEnumeration->clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets timezone strings.
|
|
|
|
* @draft ICU 3.6
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
DateFormatSymbols::setZoneString(const UnicodeString &zid, const TimeZoneTranslationType type,
|
|
|
|
const UnicodeString &value, UErrorCode &status){
|
|
|
|
if(fZoneStringsHash == NULL){
|
|
|
|
//lazy initialization
|
|
|
|
initZoneStrings(fZoneArrayBundle, (const UChar *)gLastResortZoneStrings, ARRAY_LENGTH(gLastResortZoneStrings), status);
|
|
|
|
}
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
UnicodeString* stringsArray = (UnicodeString*)fZoneStringsHash->get(zid);
|
|
|
|
if(stringsArray != NULL){
|
|
|
|
stringsArray[type].setTo(value);
|
|
|
|
}else{
|
|
|
|
stringsArray = newUnicodeStringArray(UTZ_MAX_DISPLAY_STRINGS_LENGTH);
|
|
|
|
if(stringsArray==NULL){
|
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
stringsArray[type].setTo(value);
|
|
|
|
fZoneStringsHash->put(zid, stringsArray, status);
|
|
|
|
TimeZoneKeysEnumeration* keys = (TimeZoneKeysEnumeration*) fZoneIDEnumeration;
|
|
|
|
keys->put(zid, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Hashtable*
|
|
|
|
DateFormatSymbols::createZoneStringsHash(const Hashtable* otherHash){
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
Hashtable* hash = new Hashtable(status);
|
|
|
|
if(hash==NULL){
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
int32_t pos = -1;
|
|
|
|
const UHashElement* elem = NULL;
|
|
|
|
// walk through the hash table and create a deep clone
|
|
|
|
while((elem = otherHash->nextElement(pos))!= NULL){
|
|
|
|
const UHashTok otherKeyTok = elem->key;
|
|
|
|
const UHashTok otherValueTok = elem->value;
|
|
|
|
UnicodeString* otherKey = (UnicodeString*)otherKeyTok.pointer;
|
|
|
|
UnicodeString* otherArray = (UnicodeString*)otherValueTok.pointer;
|
|
|
|
UnicodeString* array = newUnicodeStringArray(UTZ_MAX_DISPLAY_STRINGS_LENGTH);
|
|
|
|
if(array==NULL){
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
UnicodeString key(*otherKey);
|
|
|
|
for(int32_t i=0; i<UTZ_MAX_DISPLAY_STRINGS_LENGTH; i++){
|
|
|
|
array[i].setTo(otherArray[i]);
|
|
|
|
}
|
|
|
|
hash->put(key, array, status);
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
delete[] array;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* compares 2 StringEnumerations
|
|
|
|
*/
|
|
|
|
UBool
|
|
|
|
DateFormatSymbols::stringEnumCompare(StringEnumeration* e1,
|
|
|
|
StringEnumeration* e2){
|
|
|
|
TimeZoneKeysEnumeration *enum1 = (TimeZoneKeysEnumeration*)e1;
|
|
|
|
TimeZoneKeysEnumeration *enum2 = (TimeZoneKeysEnumeration*)e2;
|
|
|
|
if(enum1==NULL || enum2==NULL){
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
int32_t count1 = enum1->count(status);
|
|
|
|
int32_t count2 = enum2->count(status);
|
|
|
|
if(count1 != count2){
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
int32_t pos1 = 0;
|
|
|
|
int32_t pos2 = 0;
|
|
|
|
const UnicodeString* str1 = NULL;
|
|
|
|
const UnicodeString* str2 = NULL;
|
|
|
|
|
|
|
|
while((str1 = enum1->snext(pos1, status))!=NULL){
|
|
|
|
str2 = enum2->snext(pos2, status);
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(*str1 != *str2){
|
|
|
|
// bail out at the first failure
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// if we reached here that means that the enumerations are equal
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* compares 2 Hashtables
|
|
|
|
*/
|
|
|
|
UBool
|
|
|
|
DateFormatSymbols::hashCompare(Hashtable* hash1,
|
|
|
|
Hashtable* hash2){
|
|
|
|
|
|
|
|
if(hash1==NULL || hash2==NULL){
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
int32_t count1 = hash1->count();
|
|
|
|
int32_t count2 = hash2->count();
|
|
|
|
if(count1!=count2){
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
int32_t pos1=-1;
|
|
|
|
for(int32_t i=0; i<count1; i++){
|
|
|
|
const UHashElement* elem1 = hash1->nextElement(pos1);
|
|
|
|
UnicodeString* key1 = (UnicodeString*) elem1->key.pointer;
|
|
|
|
UnicodeString* array1 = (UnicodeString*) elem1->value.pointer;
|
|
|
|
UnicodeString* array2 = (UnicodeString*)hash2->get(*key1);
|
|
|
|
if(array1==NULL || array2==NULL){
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
for(int32_t j=0; j< UTZ_MAX_DISPLAY_STRINGS_LENGTH; j++){
|
|
|
|
if(array1[j] != array2[j]){
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
UnicodeString&
|
|
|
|
DateFormatSymbols::getZoneID(const UnicodeString& zid, UnicodeString& result, UErrorCode& status){
|
|
|
|
if(fZoneStringsHash == NULL){
|
|
|
|
initZoneStrings(fZoneArrayBundle, (const UChar*)gLastResortZoneStrings, ARRAY_LENGTH(gLastResortZoneStrings), status);
|
|
|
|
}
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
UnicodeString* strings = (UnicodeString*)fZoneStringsHash->get(zid);
|
|
|
|
if (strings != NULL) {
|
|
|
|
return result.setTo(zid,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do a search through the equivalency group for the given ID
|
|
|
|
int32_t n = TimeZone::countEquivalentIDs(zid);
|
|
|
|
if (n > 1) {
|
|
|
|
int32_t i;
|
|
|
|
for (i=0; i<n; ++i) {
|
|
|
|
UnicodeString equivID = TimeZone::getEquivalentID(zid, i);
|
|
|
|
if (equivID != zid) {
|
|
|
|
strings = (UnicodeString*)fZoneStringsHash->get(equivID);
|
|
|
|
if (strings != NULL) {
|
|
|
|
return result.setTo(equivID,0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DateFormatSymbols::getZoneType(const UnicodeString& zid, const UnicodeString& text, int32_t start,
|
|
|
|
TimeZoneTranslationType& type, UnicodeString& value, UErrorCode& status){
|
|
|
|
if(fZoneStringsHash == NULL){
|
|
|
|
initZoneStrings(fZoneArrayBundle, (const UChar*)gLastResortZoneStrings, ARRAY_LENGTH(gLastResortZoneStrings), status);
|
|
|
|
}
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
UnicodeString* strings = (UnicodeString*)fZoneStringsHash->get(zid);
|
|
|
|
if(strings != NULL){
|
|
|
|
for(int32_t j=0; j<UTZ_MAX_DISPLAY_STRINGS_LENGTH; j++){
|
|
|
|
if(text.caseCompare(start, strings[j].length(), strings[j], 0)==0){
|
|
|
|
type = (TimeZoneTranslationType)j;
|
|
|
|
value.setTo(strings[j]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void
|
|
|
|
DateFormatSymbols::findZoneIDTypeValue( UnicodeString& zid, const UnicodeString& text, int32_t start,
|
|
|
|
TimeZoneTranslationType& type, UnicodeString& value,
|
|
|
|
UErrorCode& status){
|
|
|
|
if(fZoneStringsHash == NULL){
|
|
|
|
initZoneStrings(fZoneArrayBundle, (const UChar*)gLastResortZoneStrings, ARRAY_LENGTH(gLastResortZoneStrings), status);
|
|
|
|
}
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const UnicodeString* myKey = NULL;
|
|
|
|
int32_t pos = 0;
|
|
|
|
TimeZoneKeysEnumeration *keys = (TimeZoneKeysEnumeration*)fZoneIDEnumeration;
|
|
|
|
while( (myKey=keys->snext(pos, status))!= NULL){
|
|
|
|
UnicodeString* strings = (UnicodeString*)fZoneStringsHash->get(*myKey);
|
|
|
|
if(strings != NULL){
|
|
|
|
for(int32_t j=0; j<UTZ_MAX_DISPLAY_STRINGS_LENGTH; j++){
|
|
|
|
if(text.caseCompare(start, strings[j].length(), strings[j], 0)==0){
|
|
|
|
type = (TimeZoneTranslationType)j;
|
|
|
|
value.setTo(strings[j]);
|
|
|
|
zid.setTo(*myKey);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2002-09-20 01:54:48 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
//eof
|