| Index: source/i18n/calendar.cpp
|
| diff --git a/source/i18n/calendar.cpp b/source/i18n/calendar.cpp
|
| index 062a9e9c30ae0af4dffe7d7629b2002001e872f6..d07269d75c8fb0f01939b29d986f5ffe22db2055 100644
|
| --- a/source/i18n/calendar.cpp
|
| +++ b/source/i18n/calendar.cpp
|
| @@ -1,6 +1,6 @@
|
| /*
|
| *******************************************************************************
|
| -* Copyright (C) 1997-2014, International Business Machines Corporation and *
|
| +* Copyright (C) 1997-2015, International Business Machines Corporation and *
|
| * others. All Rights Reserved. *
|
| *******************************************************************************
|
| *
|
| @@ -57,6 +57,8 @@
|
| #include "ustrenum.h"
|
| #include "uassert.h"
|
| #include "olsontz.h"
|
| +#include "sharedcalendar.h"
|
| +#include "unifiedcache.h"
|
|
|
| #if !UCONFIG_NO_SERVICE
|
| static icu::ICULocaleService* gService = NULL;
|
| @@ -199,6 +201,27 @@ typedef enum ECalType {
|
|
|
| U_NAMESPACE_BEGIN
|
|
|
| +SharedCalendar::~SharedCalendar() {
|
| + delete ptr;
|
| +}
|
| +
|
| +template<> U_I18N_API
|
| +const SharedCalendar *LocaleCacheKey<SharedCalendar>::createObject(
|
| + const void * /*unusedCreationContext*/, UErrorCode &status) const {
|
| + Calendar *calendar = Calendar::makeInstance(fLoc, status);
|
| + if (U_FAILURE(status)) {
|
| + return NULL;
|
| + }
|
| + SharedCalendar *shared = new SharedCalendar(calendar);
|
| + if (shared == NULL) {
|
| + delete calendar;
|
| + status = U_MEMORY_ALLOCATION_ERROR;
|
| + return NULL;
|
| + }
|
| + shared->addRef();
|
| + return shared;
|
| +}
|
| +
|
| static ECalType getCalendarType(const char *s) {
|
| for (int i = 0; gCalTypes[i] != NULL; i++) {
|
| if (uprv_stricmp(s, gCalTypes[i]) == 0) {
|
| @@ -612,8 +635,8 @@ static const int32_t kCalendarLimits[UCAL_FIELD_COUNT][4] = {
|
| { 1, 1, 7, 7 }, // DOW_LOCAL
|
| {/*N/A*/-1, /*N/A*/-1, /*N/A*/-1, /*N/A*/-1}, // EXTENDED_YEAR
|
| { -0x7F000000, -0x7F000000, 0x7F000000, 0x7F000000 }, // JULIAN_DAY
|
| - { 0, 0, 24*kOneHour-1, 24*kOneHour-1 }, // MILLISECONDS_IN_DAY
|
| - { 0, 0, 1, 1 }, // IS_LEAP_MONTH
|
| + { 0, 0, 24*kOneHour-1, 24*kOneHour-1 }, // MILLISECONDS_IN_DAY
|
| + { 0, 0, 1, 1 }, // IS_LEAP_MONTH
|
| };
|
|
|
| // Resource bundle tags read by this class
|
| @@ -833,9 +856,8 @@ Calendar::createInstance(const Locale& aLocale, UErrorCode& success)
|
|
|
| // Note: this is the bottleneck that actually calls the service routines.
|
|
|
| -Calendar* U_EXPORT2
|
| -Calendar::createInstance(TimeZone* zone, const Locale& aLocale, UErrorCode& success)
|
| -{
|
| +Calendar * U_EXPORT2
|
| +Calendar::makeInstance(const Locale& aLocale, UErrorCode& success) {
|
| if (U_FAILURE(success)) {
|
| return NULL;
|
| }
|
| @@ -855,7 +877,6 @@ Calendar::createInstance(TimeZone* zone, const Locale& aLocale, UErrorCode& succ
|
| Calendar* c = NULL;
|
|
|
| if(U_FAILURE(success) || !u) {
|
| - delete zone;
|
| if(U_SUCCESS(success)) { // Propagate some kind of err
|
| success = U_INTERNAL_PROGRAM_ERROR;
|
| }
|
| @@ -884,7 +905,6 @@ Calendar::createInstance(TimeZone* zone, const Locale& aLocale, UErrorCode& succ
|
| c = (Calendar*)getCalendarService(success)->get(l, LocaleKey::KIND_ANY, &actualLoc2, success);
|
|
|
| if(U_FAILURE(success) || !c) {
|
| - delete zone;
|
| if(U_SUCCESS(success)) {
|
| success = U_INTERNAL_PROGRAM_ERROR; // Propagate some err
|
| }
|
| @@ -910,7 +930,6 @@ Calendar::createInstance(TimeZone* zone, const Locale& aLocale, UErrorCode& succ
|
| #endif
|
| success = U_MISSING_RESOURCE_ERROR; // requested a calendar type which could NOT be found.
|
| delete c;
|
| - delete zone;
|
| return NULL;
|
| }
|
| #ifdef U_DEBUG_CALSVC
|
| @@ -933,8 +952,27 @@ Calendar::createInstance(TimeZone* zone, const Locale& aLocale, UErrorCode& succ
|
| c = (Calendar*)u;
|
| }
|
|
|
| + return c;
|
| +}
|
| +
|
| +Calendar* U_EXPORT2
|
| +Calendar::createInstance(TimeZone* zone, const Locale& aLocale, UErrorCode& success)
|
| +{
|
| + LocalPointer<TimeZone> zonePtr(zone);
|
| + const SharedCalendar *shared = NULL;
|
| + UnifiedCache::getByLocale(aLocale, shared, success);
|
| + if (U_FAILURE(success)) {
|
| + return NULL;
|
| + }
|
| + Calendar *c = (*shared)->clone();
|
| + shared->removeRef();
|
| + if (c == NULL) {
|
| + success = U_MEMORY_ALLOCATION_ERROR;
|
| + return NULL;
|
| + }
|
| +
|
| // Now, reset calendar to default state:
|
| - c->adoptTimeZone(zone); // Set the correct time zone
|
| + c->adoptTimeZone(zonePtr.orphan()); // Set the correct time zone
|
| c->setTimeInMillis(getNow(), success); // let the new calendar have the current time.
|
|
|
| return c;
|
| @@ -954,6 +992,24 @@ Calendar::createInstance(const TimeZone& zone, const Locale& aLocale, UErrorCode
|
|
|
| // -------------------------------------
|
|
|
| +void U_EXPORT2
|
| +Calendar::getCalendarTypeFromLocale(
|
| + const Locale &aLocale,
|
| + char *typeBuffer,
|
| + int32_t typeBufferSize,
|
| + UErrorCode &success) {
|
| + const SharedCalendar *shared = NULL;
|
| + UnifiedCache::getByLocale(aLocale, shared, success);
|
| + if (U_FAILURE(success)) {
|
| + return;
|
| + }
|
| + uprv_strncpy(typeBuffer, (*shared)->getType(), typeBufferSize);
|
| + shared->removeRef();
|
| + if (typeBuffer[typeBufferSize - 1]) {
|
| + success = U_BUFFER_OVERFLOW_ERROR;
|
| + }
|
| +}
|
| +
|
| UBool
|
| Calendar::operator==(const Calendar& that) const
|
| {
|
|
|