diff --git a/icu4c/source/i18n/calendar.cpp b/icu4c/source/i18n/calendar.cpp index 62ae3788fcb..7c0b5020100 100644 --- a/icu4c/source/i18n/calendar.cpp +++ b/icu4c/source/i18n/calendar.cpp @@ -195,18 +195,6 @@ Calendar::createInstance(UErrorCode& success) // ------------------------------------- -Calendar* -Calendar::createInstance(TimeZone* zone, UErrorCode& success) -{ - if (FAILURE(success)) return 0; - // since the Locale isn't specified, use the default locale - Calendar* c = new GregorianCalendar(zone, Locale::getDefault(), success); - if (FAILURE(success)) { delete c; c = 0; } - return c; -} - -// ------------------------------------- - Calendar* Calendar::createInstance(const TimeZone& zone, UErrorCode& success) { @@ -234,9 +222,18 @@ Calendar::createInstance(const Locale& aLocale, UErrorCode& success) Calendar* Calendar::createInstance(TimeZone* zone, const Locale& aLocale, UErrorCode& success) { - if (FAILURE(success)) return 0; + if (FAILURE(success)) { + delete zone; + return 0; + } Calendar* c = new GregorianCalendar(zone, aLocale, success); - if (FAILURE(success)) { delete c; c = 0; } + if (c == 0) { + success = U_MEMORY_ALLOCATION_ERROR; + delete zone; + } else if (FAILURE(success)) { + delete c; + c = 0; + } return c; } diff --git a/icu4c/source/i18n/calendar.h b/icu4c/source/i18n/calendar.h index efc2e17bd87..c577a88f2de 100644 --- a/icu4c/source/i18n/calendar.h +++ b/icu4c/source/i18n/calendar.h @@ -237,9 +237,9 @@ public: static Calendar* createInstance(UErrorCode& success); /** - * Creates a Calendar using the given timezone and the default locale. If creation of - * a new Calendar is successful, the Calendar takes ownership of zoneToAdopt; the - * client should not delete it. + * Creates a Calendar using the given timezone and the default locale. + * The Calendar takes ownership of zoneToAdopt; the + * client must not delete it. * * @param zoneToAdopt The given timezone to be adopted. * @param success Indicates the success/failure of Calendar creation. Filled in @@ -273,9 +273,9 @@ public: static Calendar* createInstance(const Locale& aLocale, UErrorCode& success); /** - * Creates a Calendar using the given timezone and given locale. If creation of - * a new Calendar is successful, the Calendar takes ownership of zoneToAdopt; the - * client should not delete it. + * Creates a Calendar using the given timezone and given locale. + * The Calendar takes ownership of zoneToAdopt; the + * client must not delete it. * * @param zoneToAdopt The given timezone to be adopted. * @param aLocale The given locale. @@ -963,6 +963,15 @@ private: // ------------------------------------- +inline Calendar* +Calendar::createInstance(TimeZone* zone, UErrorCode& errorCode) +{ + // since the Locale isn't specified, use the default locale + return createInstance(zone, Locale::getDefault(), errorCode); +} + +// ------------------------------------- + inline void Calendar::roll(EDateFields field, bool_t up, UErrorCode& status) { diff --git a/icu4c/source/i18n/ucal.cpp b/icu4c/source/i18n/ucal.cpp index 65035209461..1c66e77f2e6 100644 --- a/icu4c/source/i18n/ucal.cpp +++ b/icu4c/source/i18n/ucal.cpp @@ -94,15 +94,7 @@ ucal_open( const UChar* zoneID, return 0; } - Calendar *cal = 0; - cal = Calendar::createInstance(zone, Locale().init(locale), *status); - if(cal == 0) { - *status = U_MEMORY_ALLOCATION_ERROR; - delete zone; - return 0; - } - - return (UCalendar*)cal; + return (UCalendar*)Calendar::createInstance(zone, Locale().init(locale), *status); } CAPI void