mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-06 22:15:31 +00:00
[ICU-20] C++: clean up object adoption semantics & implementation in failure cases
X-Commit-URL: https://ssl.icu-project.org/trac/changeset/56
This commit is contained in:
parent
5495203457
commit
9dd74b5940
3 changed files with 27 additions and 29 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue