diff --git a/icu4c/source/i18n/number_capi.cpp b/icu4c/source/i18n/number_capi.cpp index 9c150931bf..16d87bb188 100644 --- a/icu4c/source/i18n/number_capi.cpp +++ b/icu4c/source/i18n/number_capi.cpp @@ -9,8 +9,8 @@ // Helpful in toString methods and elsewhere. #define UNISTR_FROM_STRING_EXPLICIT -#include "numparse_types.h" #include "number_utypes.h" +#include "numparse_types.h" #include "unicode/numberformatter.h" #include "unicode/unumberformatter.h" @@ -159,14 +159,14 @@ unumf_resultToString(const UFormattedNumber* uresult, UChar* buffer, int32_t buf U_CAPI UBool U_EXPORT2 unumf_resultNextFieldPosition(const UFormattedNumber* uresult, UFieldPosition* ufpos, UErrorCode* ec) { + const UFormattedNumberData* result = UFormattedNumberData::validate(uresult, *ec); + if (U_FAILURE(*ec)) { return FALSE; } + if (ufpos == nullptr) { *ec = U_ILLEGAL_ARGUMENT_ERROR; return FALSE; } - const UFormattedNumberData* result = UFormattedNumberData::validate(uresult, *ec); - if (U_FAILURE(*ec)) { return FALSE; } - FieldPosition fp; fp.setField(ufpos->field); fp.setBeginIndex(ufpos->beginIndex); @@ -181,14 +181,14 @@ unumf_resultNextFieldPosition(const UFormattedNumber* uresult, UFieldPosition* u U_CAPI void U_EXPORT2 unumf_resultGetAllFieldPositions(const UFormattedNumber* uresult, UFieldPositionIterator* ufpositer, UErrorCode* ec) { + const UFormattedNumberData* result = UFormattedNumberData::validate(uresult, *ec); + if (U_FAILURE(*ec)) { return; } + if (ufpositer == nullptr) { *ec = U_ILLEGAL_ARGUMENT_ERROR; return; } - const UFormattedNumberData* result = UFormattedNumberData::validate(uresult, *ec); - if (U_FAILURE(*ec)) { return; } - auto* helper = reinterpret_cast(ufpositer); result->string.getAllFieldPositions(*helper, *ec); } @@ -197,7 +197,6 @@ U_CAPI void U_EXPORT2 unumf_closeResult(UFormattedNumber* uresult) { UErrorCode localStatus = U_ZERO_ERROR; const UFormattedNumberData* impl = UFormattedNumberData::validate(uresult, localStatus); - if (U_FAILURE(localStatus)) { return; } delete impl; } @@ -205,7 +204,6 @@ U_CAPI void U_EXPORT2 unumf_close(UNumberFormatter* f) { UErrorCode localStatus = U_ZERO_ERROR; const UNumberFormatterData* impl = UNumberFormatterData::validate(f, localStatus); - if (U_FAILURE(localStatus)) { return; } delete impl; } diff --git a/icu4c/source/i18n/plurrule_impl.h b/icu4c/source/i18n/plurrule_impl.h index 43ca84f27f..3ab445d584 100644 --- a/icu4c/source/i18n/plurrule_impl.h +++ b/icu4c/source/i18n/plurrule_impl.h @@ -106,7 +106,7 @@ static const UChar LOW_W = ((UChar) 0x0077); static const UChar LOW_Y = ((UChar) 0x0079); static const UChar LOW_Z = ((UChar) 0x007A); -}; +} static const int32_t PLURAL_RANGE_HIGH = 0x7fffffff; diff --git a/icu4c/source/i18n/unicode/numberformatter.h b/icu4c/source/i18n/unicode/numberformatter.h index 47b4f9a7ae..5ec1018223 100644 --- a/icu4c/source/i18n/unicode/numberformatter.h +++ b/icu4c/source/i18n/unicode/numberformatter.h @@ -13,11 +13,11 @@ #include "unicode/fieldpos.h" #include "unicode/fpositer.h" #include "unicode/measunit.h" -#include "unicode/unumberformatter.h" #include "unicode/nounit.h" #include "unicode/plurrule.h" #include "unicode/ucurr.h" #include "unicode/unum.h" +#include "unicode/unumberformatter.h" #include "unicode/uobject.h" #ifndef U_HIDE_DRAFT_API diff --git a/icu4c/source/test/cintltst/unumberformattertst.c b/icu4c/source/test/cintltst/unumberformattertst.c index dc3946f396..0b35c46332 100644 --- a/icu4c/source/test/cintltst/unumberformattertst.c +++ b/icu4c/source/test/cintltst/unumberformattertst.c @@ -76,7 +76,8 @@ static void TestSkeletonFormatToFields() { // setup: UNumberFormatter* uformatter = unumf_openFromSkeletonAndLocale( u".00 measure-unit/length-meter sign-always", -1, "en", &ec); - assertSuccess("Should create without error", &ec); + assertSuccessCheck("Should create without error", &ec, TRUE); + if (U_FAILURE(ec)) { return; } UFormattedNumber* uresult = unumf_openResult(&ec); assertSuccess("Should create result without error", &ec); unumf_formatInt(uformatter, 9876543210L, uresult, &ec); // "+9,876,543,210.00 m" @@ -154,7 +155,8 @@ static void TestExampleCode() { UErrorCode ec = U_ZERO_ERROR; UNumberFormatter* uformatter = unumf_openFromSkeletonAndLocale(u"round-integer", -1, "en", &ec); UFormattedNumber* uresult = unumf_openResult(&ec); - assertSuccess("There should not be a failure in the example code", &ec); + assertSuccessCheck("There should not be a failure in the example code", &ec, TRUE); + if (U_FAILURE(ec)) { return; } // Format a double: unumf_formatDouble(uformatter, 5142.3, uresult, &ec); diff --git a/icu4c/source/test/intltest/numbertest_api.cpp b/icu4c/source/test/intltest/numbertest_api.cpp index bbb2f767a1..4947af33a7 100644 --- a/icu4c/source/test/intltest/numbertest_api.cpp +++ b/icu4c/source/test/intltest/numbertest_api.cpp @@ -2374,7 +2374,8 @@ void NumberFormatterApiTest::localPointerCAPI() { // Setup: LocalUNumberFormatterPointer uformatter(unumf_openFromSkeletonAndLocale(u"percent", -1, "en", &ec)); LocalUFormattedNumberPointer uresult(unumf_openResult(&ec)); - assertSuccess("", ec); + assertSuccess("", ec, TRUE); + if (U_FAILURE(ec)) { return; } // Format a decimal number: unumf_formatDecimal(uformatter.getAlias(), "9.87E-3", -1, uresult.getAlias(), &ec);