Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: source/i18n/calendar.cpp

Issue 1621843002: ICU 56 update step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@561
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « source/i18n/brktrans.cpp ('k') | source/i18n/coll.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
{
« no previous file with comments | « source/i18n/brktrans.cpp ('k') | source/i18n/coll.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698