From: Filip Navara Date: Sun, 3 Feb 2019 00:50:56 +0000 (+0100) Subject: Simplify and fix error handling X-Git-Tag: accepted/tizen/unified/20190813.215958~141^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a7f13657cf6bdb27fb51f6ad57835378857a5059;p=platform%2Fupstream%2Fcoreclr.git Simplify and fix error handling --- diff --git a/src/corefx/System.Globalization.Native/pal_calendarData.c b/src/corefx/System.Globalization.Native/pal_calendarData.c index 404c0df..8e14d8b 100644 --- a/src/corefx/System.Globalization.Native/pal_calendarData.c +++ b/src/corefx/System.Globalization.Native/pal_calendarData.c @@ -116,22 +116,8 @@ int32_t GlobalizationNative_GetCalendars( UErrorCode err = U_ZERO_ERROR; char locale[ULOC_FULLNAME_CAPACITY]; GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, false, &err); - - if (U_FAILURE(err)) - return 0; - UEnumeration* pEnum = ucal_getKeywordValuesForLocale("calendar", locale, TRUE, &err); - - if (U_FAILURE(err)) - return 0; - int stringEnumeratorCount = uenum_count(pEnum, &err); - if (U_FAILURE(err)) - { - uenum_close(pEnum); - return 0; - } - int calendarsReturned = 0; for (int i = 0; i < stringEnumeratorCount && calendarsReturned < calendarsCapacity; i++) { @@ -147,7 +133,6 @@ int32_t GlobalizationNative_GetCalendars( } } } - uenum_close(pEnum); return calendarsReturned; } @@ -162,12 +147,7 @@ ResultCode GetMonthDayPattern(const char* locale, UChar* sMonthDay, int32_t stri { UErrorCode err = U_ZERO_ERROR; UDateTimePatternGenerator* pGenerator = udatpg_open(locale, &err); - - if (U_FAILURE(err)) - return GetResultCode(err); - udatpg_getBestPattern(pGenerator, UDAT_MONTH_DAY_UCHAR, -1, sMonthDay, stringCapacity, &err); - udatpg_close(pGenerator); return GetResultCode(err); } @@ -603,69 +583,32 @@ int32_t GlobalizationNative_GetJapaneseEraStartDate( ucal_set(pCal, UCAL_DATE, 1); int32_t currentEra; - for (int i = 0; i <= 12; i++) + for (int i = 0; U_SUCCESS(err) && i <= 12; i++) { currentEra = ucal_get(pCal, UCAL_ERA, &err); - if (U_FAILURE(err)) - { - ucal_close(pCal); - return false; - } - if (currentEra == era) { - for (int i = 0; i < 31; i++) + for (int i = 0; U_SUCCESS(err) && i < 31; i++) { // subtract 1 day at a time until we get out of the specified Era ucal_add(pCal, UCAL_DATE, -1, &err); - if (U_FAILURE(err)) - { - ucal_close(pCal); - return false; - } - currentEra = ucal_get(pCal, UCAL_ERA, &err); - if (U_FAILURE(err)) - { - ucal_close(pCal); - return false; - } - - if (currentEra != era) + if (U_SUCCESS(err) && currentEra != era) { // add back 1 day to get back into the specified Era ucal_add(pCal, UCAL_DATE, 1, &err); - if (U_FAILURE(err)) - { - ucal_close(pCal); - return false; - } - *startMonth = ucal_get(pCal, UCAL_MONTH, &err) + 1; // ICU Calendar months are 0-based, but .NET is 1-based - if (U_FAILURE(err)) - { - ucal_close(pCal); - return false; - } - *startDay = ucal_get(pCal, UCAL_DATE, &err); ucal_close(pCal); - if (U_FAILURE(err)) - return false; - return true; + return U_SUCCESS(err); } } } // add 1 month at a time until we get into the specified Era ucal_add(pCal, UCAL_MONTH, 1, &err); - if (U_FAILURE(err)) - { - ucal_close(pCal); - return false; - } } ucal_close(pCal); diff --git a/src/corefx/System.Globalization.Native/pal_localeStringData.c b/src/corefx/System.Globalization.Native/pal_localeStringData.c index 5f97792..d17e667 100644 --- a/src/corefx/System.Globalization.Native/pal_localeStringData.c +++ b/src/corefx/System.Globalization.Native/pal_localeStringData.c @@ -20,12 +20,7 @@ GetLocaleInfoDecimalFormatSymbol(const char* locale, UNumberFormatSymbol symbol, { UErrorCode status = U_ZERO_ERROR; UNumberFormat* pFormat = unum_open(UNUM_DECIMAL, NULL, 0, locale, NULL, &status); - - if (U_FAILURE(status)) - return status; - unum_getSymbol(pFormat, symbol, value, valueLength, &status); - unum_close(pFormat); return status; } @@ -61,12 +56,7 @@ UErrorCode GetLocaleInfoAmPm(const char* locale, bool am, UChar* value, int32_t { UErrorCode status = U_ZERO_ERROR; UDateFormat* pFormat = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, locale, NULL, 0, NULL, 0, &status); - - if (U_FAILURE(status)) - return status; - udat_getSymbols(pFormat, UDAT_AM_PMS, am ? 0 : 1, value, valueLength, &status); - udat_close(pFormat); return status; } @@ -88,8 +78,6 @@ UErrorCode GetLocaleIso639LanguageTwoLetterName(const char* locale, UChar* value return U_MEMORY_ALLOCATION_ERROR; } - status = U_ZERO_ERROR; - uloc_getLanguage(locale, buf, length, &status); if (U_SUCCESS(status)) @@ -365,20 +353,9 @@ int32_t GlobalizationNative_GetLocaleTimeFormat( UErrorCode err = U_ZERO_ERROR; char locale[ULOC_FULLNAME_CAPACITY]; GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, false, &err); - - if (U_FAILURE(err)) - { - return UErrorCodeToBool(U_ILLEGAL_ARGUMENT_ERROR); - } - UDateFormatStyle style = (shortFormat != 0) ? UDAT_SHORT : UDAT_MEDIUM; UDateFormat* pFormat = udat_open(style, UDAT_NONE, locale, NULL, 0, NULL, 0, &err); - - if (U_FAILURE(err)) - return UErrorCodeToBool(err); - udat_toPattern(pFormat, false, value, valueLength, &err); - udat_close(pFormat); return UErrorCodeToBool(err); }