diff --git a/icu4c/source/i18n/decimfmt.cpp b/icu4c/source/i18n/decimfmt.cpp index 0470db0ffa..3992f0077a 100644 --- a/icu4c/source/i18n/decimfmt.cpp +++ b/icu4c/source/i18n/decimfmt.cpp @@ -435,7 +435,7 @@ UnicodeString& DecimalFormat::format(double number, UnicodeString& appendTo, Fie FormattedNumber output = fields->formatter->formatDouble(number, localStatus); fieldPositionHelper(output, pos, appendTo.length(), localStatus); auto appendable = UnicodeStringAppendable(appendTo); - output.appendTo(appendable); + output.appendTo(appendable, localStatus); return appendTo; } @@ -447,7 +447,7 @@ UnicodeString& DecimalFormat::format(double number, UnicodeString& appendTo, Fie FormattedNumber output = fields->formatter->formatDouble(number, status); fieldPositionHelper(output, pos, appendTo.length(), status); auto appendable = UnicodeStringAppendable(appendTo); - output.appendTo(appendable); + output.appendTo(appendable, status); return appendTo; } @@ -460,7 +460,7 @@ DecimalFormat::format(double number, UnicodeString& appendTo, FieldPositionItera FormattedNumber output = fields->formatter->formatDouble(number, status); fieldPositionIteratorHelper(output, posIter, appendTo.length(), status); auto appendable = UnicodeStringAppendable(appendTo); - output.appendTo(appendable); + output.appendTo(appendable, status); return appendTo; } @@ -487,7 +487,7 @@ UnicodeString& DecimalFormat::format(int64_t number, UnicodeString& appendTo, Fi FormattedNumber output = fields->formatter->formatInt(number, localStatus); fieldPositionHelper(output, pos, appendTo.length(), localStatus); auto appendable = UnicodeStringAppendable(appendTo); - output.appendTo(appendable); + output.appendTo(appendable, localStatus); return appendTo; } @@ -499,7 +499,7 @@ UnicodeString& DecimalFormat::format(int64_t number, UnicodeString& appendTo, Fi FormattedNumber output = fields->formatter->formatInt(number, status); fieldPositionHelper(output, pos, appendTo.length(), status); auto appendable = UnicodeStringAppendable(appendTo); - output.appendTo(appendable); + output.appendTo(appendable, status); return appendTo; } @@ -512,7 +512,7 @@ DecimalFormat::format(int64_t number, UnicodeString& appendTo, FieldPositionIter FormattedNumber output = fields->formatter->formatInt(number, status); fieldPositionIteratorHelper(output, posIter, appendTo.length(), status); auto appendable = UnicodeStringAppendable(appendTo); - output.appendTo(appendable); + output.appendTo(appendable, status); return appendTo; } @@ -522,7 +522,7 @@ DecimalFormat::format(StringPiece number, UnicodeString& appendTo, FieldPosition FormattedNumber output = fields->formatter->formatDecimal(number, status); fieldPositionIteratorHelper(output, posIter, appendTo.length(), status); auto appendable = UnicodeStringAppendable(appendTo); - output.appendTo(appendable); + output.appendTo(appendable, status); return appendTo; } @@ -531,7 +531,7 @@ UnicodeString& DecimalFormat::format(const DecimalQuantity& number, UnicodeStrin FormattedNumber output = fields->formatter->formatDecimalQuantity(number, status); fieldPositionIteratorHelper(output, posIter, appendTo.length(), status); auto appendable = UnicodeStringAppendable(appendTo); - output.appendTo(appendable); + output.appendTo(appendable, status); return appendTo; } @@ -541,7 +541,7 @@ DecimalFormat::format(const DecimalQuantity& number, UnicodeString& appendTo, Fi FormattedNumber output = fields->formatter->formatDecimalQuantity(number, status); fieldPositionHelper(output, pos, appendTo.length(), status); auto appendable = UnicodeStringAppendable(appendTo); - output.appendTo(appendable); + output.appendTo(appendable, status); return appendTo; } diff --git a/icu4c/source/i18n/number_fluent.cpp b/icu4c/source/i18n/number_fluent.cpp index 320fcbe40c..e0b0c92fbc 100644 --- a/icu4c/source/i18n/number_fluent.cpp +++ b/icu4c/source/i18n/number_fluent.cpp @@ -772,11 +772,6 @@ FormattedNumber& FormattedNumber::operator=(FormattedNumber&& src) U_NOEXCEPT { return *this; } -UnicodeString FormattedNumber::toString() const { - UErrorCode localStatus = U_ZERO_ERROR; - return toString(localStatus); -} - UnicodeString FormattedNumber::toString(UErrorCode& status) const { if (U_FAILURE(status)) { return ICU_Utility::makeBogusString(); @@ -799,11 +794,6 @@ UnicodeString FormattedNumber::toTempString(UErrorCode& status) const { return fResults->string.toTempUnicodeString(); } -Appendable& FormattedNumber::appendTo(Appendable& appendable) { - UErrorCode localStatus = U_ZERO_ERROR; - return appendTo(appendable, localStatus); -} - Appendable& FormattedNumber::appendTo(Appendable& appendable, UErrorCode& status) const { if (U_FAILURE(status)) { return appendable; @@ -828,20 +818,6 @@ UBool FormattedNumber::nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& return fResults->string.nextPosition(cfpos, status) ? TRUE : FALSE; } -void FormattedNumber::populateFieldPosition(FieldPosition& fieldPosition, UErrorCode& status) { - if (U_FAILURE(status)) { - return; - } - if (fResults == nullptr) { - status = fErrorCode; - return; - } - // in case any users were depending on the old behavior: - fieldPosition.setBeginIndex(0); - fieldPosition.setEndIndex(0); - fResults->string.nextFieldPosition(fieldPosition, status); -} - UBool FormattedNumber::nextFieldPosition(FieldPosition& fieldPosition, UErrorCode& status) const { if (U_FAILURE(status)) { return FALSE; @@ -854,10 +830,6 @@ UBool FormattedNumber::nextFieldPosition(FieldPosition& fieldPosition, UErrorCod return fResults->string.nextFieldPosition(fieldPosition, status) ? TRUE : FALSE; } -void FormattedNumber::populateFieldPositionIterator(FieldPositionIterator& iterator, UErrorCode& status) { - getAllFieldPositions(iterator, status); -} - void FormattedNumber::getAllFieldPositions(FieldPositionIterator& iterator, UErrorCode& status) const { FieldPositionIteratorHandler fpih(&iterator, status); getAllFieldPositionsImpl(fpih, status); diff --git a/icu4c/source/i18n/number_mapper.cpp b/icu4c/source/i18n/number_mapper.cpp index 5dca9df310..b075480b49 100644 --- a/icu4c/source/i18n/number_mapper.cpp +++ b/icu4c/source/i18n/number_mapper.cpp @@ -155,7 +155,7 @@ MacroProps NumberPropertyMapper::oldToNew(const DecimalFormatProperties& propert precision = Precision::constructCurrency(currencyUsage); } if (!precision.isBogus()) { - precision = precision.withMode(roundingMode); + precision.fRoundingMode = roundingMode; macros.precision = precision; } @@ -234,10 +234,10 @@ MacroProps NumberPropertyMapper::oldToNew(const DecimalFormatProperties& propert int maxFrac_ = properties.maximumFractionDigits; if (minInt_ == 0 && maxFrac_ == 0) { // Patterns like "#E0" and "##E0", which mean no rounding! - macros.precision = Precision::unlimited().withMode(roundingMode); + macros.precision = Precision::unlimited(); } else if (minInt_ == 0 && minFrac_ == 0) { // Patterns like "#.##E0" (no zeros in the mantissa), which mean round to maxFrac+1 - macros.precision = Precision::constructSignificant(1, maxFrac_ + 1).withMode(roundingMode); + macros.precision = Precision::constructSignificant(1, maxFrac_ + 1); } else { int maxSig_ = minInt_ + maxFrac_; // Bug #20058: if maxInt_ > minInt_ > 1, then minInt_ should be 1. @@ -247,8 +247,9 @@ MacroProps NumberPropertyMapper::oldToNew(const DecimalFormatProperties& propert int minSig_ = minInt_ + minFrac_; // To avoid regression, maxSig is not reset when minInt_ set to 1. // TODO: Reset maxSig_ = 1 + minFrac_ to follow the spec. - macros.precision = Precision::constructSignificant(minSig_, maxSig_).withMode(roundingMode); + macros.precision = Precision::constructSignificant(minSig_, maxSig_); } + macros.precision.fRoundingMode = roundingMode; } } diff --git a/icu4c/source/i18n/number_rounding.cpp b/icu4c/source/i18n/number_rounding.cpp index a43ea8c0f2..723b9776c2 100644 --- a/icu4c/source/i18n/number_rounding.cpp +++ b/icu4c/source/i18n/number_rounding.cpp @@ -169,13 +169,6 @@ CurrencyPrecision Precision::currency(UCurrencyUsage currencyUsage) { return constructCurrency(currencyUsage); } -Precision Precision::withMode(RoundingMode roundingMode) const { - if (fType == RND_ERROR) { return *this; } // no-op in error state - Precision retval = *this; - retval.fRoundingMode = roundingMode; - return retval; -} - Precision FractionPrecision::withMinDigits(int32_t minSignificantDigits) const { if (fType == RND_ERROR) { return *this; } // no-op in error state if (minSignificantDigits >= 1 && minSignificantDigits <= kMaxIntFracSig) { diff --git a/icu4c/source/i18n/unicode/numberformatter.h b/icu4c/source/i18n/unicode/numberformatter.h index 47a04dda3d..2603290b1c 100644 --- a/icu4c/source/i18n/unicode/numberformatter.h +++ b/icu4c/source/i18n/unicode/numberformatter.h @@ -441,34 +441,6 @@ class U_I18N_API ScientificNotation : public Notation { */ typedef Precision SignificantDigitsPrecision; -// Typedefs for ICU 60/61 compatibility. -// These will be removed in ICU 64. -// See http://bugs.icu-project.org/trac/ticket/13746 - -/** - * This will be removed in ICU 64. See ICU-13746. - * @deprecated ICU 63 - */ -typedef Precision Rounder; - -/** - * This will be removed in ICU 64. See ICU-13746. - * @deprecated ICU 63 - */ -typedef FractionPrecision FractionRounder; - -/** - * This will be removed in ICU 64. See ICU-13746. - * @deprecated ICU 63 - */ -typedef IncrementPrecision IncrementRounder; - -/** - * This will be removed in ICU 64. See ICU-13746. - * @deprecated ICU 63 - */ -typedef CurrencyPrecision CurrencyRounder; - /** * A class that defines the rounding precision to be used when formatting numbers in NumberFormatter. * @@ -630,31 +602,6 @@ class U_I18N_API Precision : public UMemory { static SignificantDigitsPrecision minMaxSignificantDigits(int32_t minSignificantDigits, int32_t maxSignificantDigits); -#ifndef U_HIDE_DEPRECATED_API - // Compatiblity methods that will be removed in ICU 64. - // See http://bugs.icu-project.org/trac/ticket/13746 - - /** @deprecated ICU 62 */ - static inline SignificantDigitsPrecision fixedDigits(int32_t a) { - return fixedSignificantDigits(a); - } - - /** @deprecated ICU 62 */ - static inline SignificantDigitsPrecision minDigits(int32_t a) { - return minSignificantDigits(a); - } - - /** @deprecated ICU 62 */ - static inline SignificantDigitsPrecision maxDigits(int32_t a) { - return maxSignificantDigits(a); - } - - /** @deprecated ICU 62 */ - static inline SignificantDigitsPrecision minMaxDigits(int32_t a, int32_t b) { - return minMaxSignificantDigits(a, b); - } -#endif /* U_HIDE_DEPRECATED_API */ - /** * Show numbers rounded if necessary to the closest multiple of a certain rounding increment. For example, if the * rounding increment is 0.5, then round 1.2 to 1 and round 1.3 to 1.5. @@ -695,21 +642,6 @@ class U_I18N_API Precision : public UMemory { */ static CurrencyPrecision currency(UCurrencyUsage currencyUsage); -#ifndef U_HIDE_DEPRECATED_API - /** - * Sets the rounding mode to use when picking the direction to round (up or down). Common values - * include HALF_EVEN, HALF_UP, and FLOOR. The default is HALF_EVEN. - * - * @param roundingMode - * The RoundingMode to use. - * @return A Precision for passing to the NumberFormatter precision() setter. - * @deprecated ICU 62 Use the top-level roundingMode() setting instead. - * This method will be removed in ICU 64. - * See http://bugs.icu-project.org/trac/ticket/13746 - */ - Precision withMode(UNumberFormatRoundingMode roundingMode) const; -#endif /* U_HIDE_DEPRECATED_API */ - private: enum PrecisionType { RND_BOGUS, @@ -1730,16 +1662,6 @@ class U_I18N_API NumberFormatterSettings { */ Derived precision(const Precision& precision) &&; -#ifndef U_HIDE_DEPRECATED_API - // Compatibility method that will be removed in ICU 64. - // Use precision() instead. - // See http://bugs.icu-project.org/trac/ticket/13746 - /** @deprecated ICU 62 */ - Derived rounding(const Rounder& rounder) const & { - return precision(rounder); - } -#endif /* U_HIDE_DEPRECATED_API */ - /** * Specifies how to determine the direction to round a number when it has more digits than fit in the * desired precision. When formatting 1.235: @@ -2488,18 +2410,6 @@ class U_I18N_API FormattedNumber : public UMemory, public FormattedValue { */ FormattedNumber& operator=(FormattedNumber&& src) U_NOEXCEPT; -#ifndef U_HIDE_DEPRECATED_API - /** - * Returns a UnicodeString representation of the formatted number. - * - * @return a UnicodeString containing the localized number. - * @deprecated ICU 62 Use the version of this method with an error code instead. - * This method was never @stable and will be removed in a future release. - * See http://bugs.icu-project.org/trac/ticket/13746 - */ - UnicodeString toString() const; -#endif /* U_HIDE_DEPRECATED_API */ - /** * @copydoc FormattedValue::toString() */ @@ -2510,21 +2420,6 @@ class U_I18N_API FormattedNumber : public UMemory, public FormattedValue { */ UnicodeString toTempString(UErrorCode& status) const U_OVERRIDE; -#ifndef U_HIDE_DEPRECATED_API - /** - * Appends the formatted number to an Appendable. - * - * @param appendable - * The Appendable to which to append the formatted number string. - * @return The same Appendable, for chaining. - * @deprecated ICU 62 Use the version of this method with an error code instead. - * This method was never @stable and will be removed in a future release. - * See http://bugs.icu-project.org/trac/ticket/13746 - * @see Appendable - */ - Appendable &appendTo(Appendable& appendable); -#endif /* U_HIDE_DEPRECATED_API */ - /** * @copydoc FormattedValue::appendTo() */ @@ -2535,30 +2430,6 @@ class U_I18N_API FormattedNumber : public UMemory, public FormattedValue { */ UBool nextPosition(ConstrainedFieldPosition& cfpos, UErrorCode& status) const U_OVERRIDE; -#ifndef U_HIDE_DEPRECATED_API - /** - * Determine the start and end indices of the first occurrence of the given field in the output string. - * This allows you to determine the locations of the integer part, fraction part, and sign. - * - *
- * If multiple different field attributes are needed, this method can be called repeatedly, or if all field - * attributes are needed, consider using populateFieldPositionIterator(). - * - *
- * If a field occurs multiple times in an output string, such as a grouping separator, this method will only ever - * return the first occurrence. Use populateFieldPositionIterator() to access all occurrences of an attribute. - * - * @param fieldPosition - * The FieldPosition to populate with the start and end indices of the desired field. - * @param status - * Set if an error occurs while populating the FieldPosition. - * @deprecated ICU 62 Use {@link #nextFieldPosition} instead. This method will be removed in a future - * release. See http://bugs.icu-project.org/trac/ticket/13746 - * @see UNumberFormatFields - */ - void populateFieldPosition(FieldPosition &fieldPosition, UErrorCode &status); -#endif /* U_HIDE_DEPRECATED_API */ - /** * Determines the start (inclusive) and end (exclusive) indices of the next occurrence of the given * field in the output string. This allows you to determine the locations of, for example, @@ -2592,25 +2463,6 @@ class U_I18N_API FormattedNumber : public UMemory, public FormattedValue { */ UBool nextFieldPosition(FieldPosition& fieldPosition, UErrorCode& status) const; -#ifndef U_HIDE_DEPRECATED_API - /** - * Export the formatted number to a FieldPositionIterator. This allows you to determine which characters in - * the output string correspond to which fields, such as the integer part, fraction part, and sign. - * - *
- * If information on only one field is needed, consider using populateFieldPosition() instead.
- *
- * @param iterator
- * The FieldPositionIterator to populate with all of the fields present in the formatted number.
- * @param status
- * Set if an error occurs while populating the FieldPositionIterator.
- * @deprecated ICU 62 Use {@link #getAllFieldPositions} instead. This method will be removed in a
- * future release. See http://bugs.icu-project.org/trac/ticket/13746
- * @see UNumberFormatFields
- */
- void populateFieldPositionIterator(FieldPositionIterator &iterator, UErrorCode &status);
-#endif /* U_HIDE_DEPRECATED_API */
-
/**
* Export the formatted number to a FieldPositionIterator. This allows you to determine which characters in
* the output string correspond to which fields, such as the integer part, fraction part, and sign.
diff --git a/icu4c/source/test/intltest/numbertest_api.cpp b/icu4c/source/test/intltest/numbertest_api.cpp
index 52e0bee24d..cdff922b40 100644
--- a/icu4c/source/test/intltest/numbertest_api.cpp
+++ b/icu4c/source/test/intltest/numbertest_api.cpp
@@ -1714,7 +1714,7 @@ void NumberFormatterApiTest::symbols() {
NumberFormatter::withLocale(Locale("ar@numbers=arab")).adoptSymbols(new NumberingSystem(LATN))
.unit(USD)
.formatDouble(12345.67, status)
- .toString());
+ .toString(status));
DecimalFormatSymbols symbols = SWISS_SYMBOLS;
UnlocalizedNumberFormatter f = NumberFormatter::with().symbols(symbols);
@@ -2139,7 +2139,7 @@ void NumberFormatterApiTest::locale() {
// Coverage for the locale setters.
UErrorCode status = U_ZERO_ERROR;
UnicodeString actual = NumberFormatter::withLocale(Locale::getFrench()).formatInt(1234, status)
- .toString();
+ .toString(status);
assertEquals("Locale withLocale()", u"1\u202f234", actual);
}
@@ -2148,20 +2148,20 @@ void NumberFormatterApiTest::formatTypes() {
LocalizedNumberFormatter formatter = NumberFormatter::withLocale(Locale::getEnglish());
// Double
- assertEquals("Format double", "514.23", formatter.formatDouble(514.23, status).toString());
+ assertEquals("Format double", "514.23", formatter.formatDouble(514.23, status).toString(status));
// Int64
- assertEquals("Format int64", "51,423", formatter.formatDouble(51423L, status).toString());
+ assertEquals("Format int64", "51,423", formatter.formatDouble(51423L, status).toString(status));
// decNumber
- UnicodeString actual = formatter.formatDecimal("98765432123456789E1", status).toString();
+ UnicodeString actual = formatter.formatDecimal("98765432123456789E1", status).toString(status);
assertEquals("Format decNumber", u"987,654,321,234,567,890", actual);
// Also test proper DecimalQuantity bytes storage when all digits are in the fraction.
// The number needs to have exactly 40 digits, which is the size of the default buffer.
// (issue discovered by the address sanitizer in C++)
static const char* str = "0.009876543210987654321098765432109876543211";
- actual = formatter.precision(Precision::unlimited()).formatDecimal(str, status).toString();
+ actual = formatter.precision(Precision::unlimited()).formatDecimal(str, status).toString(status);
assertEquals("Format decNumber to 40 digits", str, actual);
}
@@ -2550,7 +2550,7 @@ void NumberFormatterApiTest::errors() {
// FieldPosition
status = U_ZERO_ERROR;
FieldPosition fp;
- fn.populateFieldPosition(fp, status);
+ fn.nextFieldPosition(fp, status);
assertEquals(
"Should fail on FieldPosition terminal method with correct error code",
U_NUMBER_ARG_OUTOFBOUNDS_ERROR,
@@ -2559,7 +2559,7 @@ void NumberFormatterApiTest::errors() {
// FieldPositionIterator
status = U_ZERO_ERROR;
FieldPositionIterator fpi;
- fn.populateFieldPositionIterator(fpi, status);
+ fn.getAllFieldPositions(fpi, status);
assertEquals(
"Should fail on FieldPositoinIterator terminal method with correct error code",
U_NUMBER_ARG_OUTOFBOUNDS_ERROR,
@@ -2640,16 +2640,16 @@ void NumberFormatterApiTest::validRanges() {
} \
}
- VALID_RANGE_ONEARG(rounding, Precision::fixedFraction, 0);
- VALID_RANGE_ONEARG(rounding, Precision::minFraction, 0);
- VALID_RANGE_ONEARG(rounding, Precision::maxFraction, 0);
- VALID_RANGE_TWOARGS(rounding, Precision::minMaxFraction, 0);
- VALID_RANGE_ONEARG(rounding, Precision::fixedSignificantDigits, 1);
- VALID_RANGE_ONEARG(rounding, Precision::minSignificantDigits, 1);
- VALID_RANGE_ONEARG(rounding, Precision::maxSignificantDigits, 1);
- VALID_RANGE_TWOARGS(rounding, Precision::minMaxSignificantDigits, 1);
- VALID_RANGE_ONEARG(rounding, Precision::fixedFraction(1).withMinDigits, 1);
- VALID_RANGE_ONEARG(rounding, Precision::fixedFraction(1).withMaxDigits, 1);
+ VALID_RANGE_ONEARG(precision, Precision::fixedFraction, 0);
+ VALID_RANGE_ONEARG(precision, Precision::minFraction, 0);
+ VALID_RANGE_ONEARG(precision, Precision::maxFraction, 0);
+ VALID_RANGE_TWOARGS(precision, Precision::minMaxFraction, 0);
+ VALID_RANGE_ONEARG(precision, Precision::fixedSignificantDigits, 1);
+ VALID_RANGE_ONEARG(precision, Precision::minSignificantDigits, 1);
+ VALID_RANGE_ONEARG(precision, Precision::maxSignificantDigits, 1);
+ VALID_RANGE_TWOARGS(precision, Precision::minMaxSignificantDigits, 1);
+ VALID_RANGE_ONEARG(precision, Precision::fixedFraction(1).withMinDigits, 1);
+ VALID_RANGE_ONEARG(precision, Precision::fixedFraction(1).withMaxDigits, 1);
VALID_RANGE_ONEARG(notation, Notation::scientific().withMinExponentDigits, 1);
VALID_RANGE_ONEARG(integerWidth, IntegerWidth::zeroFillTo, 0);
VALID_RANGE_ONEARG(integerWidth, IntegerWidth::zeroFillTo(0).truncateAt, -1);
@@ -2660,33 +2660,33 @@ void NumberFormatterApiTest::copyMove() {
// Default constructors
LocalizedNumberFormatter l1;
- assertEquals("Initial behavior", u"10", l1.formatInt(10, status).toString(), true);
+ assertEquals("Initial behavior", u"10", l1.formatInt(10, status).toString(status), true);
if (status.errDataIfFailureAndReset()) { return; }
assertEquals("Initial call count", 1, l1.getCallCount());
assertTrue("Initial compiled", l1.getCompiled() == nullptr);
// Setup
l1 = NumberFormatter::withLocale("en").unit(NoUnit::percent()).threshold(3);
- assertEquals("Initial behavior", u"10%", l1.formatInt(10, status).toString());
+ assertEquals("Initial behavior", u"10%", l1.formatInt(10, status).toString(status));
assertEquals("Initial call count", 1, l1.getCallCount());
assertTrue("Initial compiled", l1.getCompiled() == nullptr);
l1.formatInt(123, status);
assertEquals("Still not compiled", 2, l1.getCallCount());
assertTrue("Still not compiled", l1.getCompiled() == nullptr);
l1.formatInt(123, status);
- assertEquals("Compiled", u"10%", l1.formatInt(10, status).toString());
+ assertEquals("Compiled", u"10%", l1.formatInt(10, status).toString(status));
assertEquals("Compiled", INT32_MIN, l1.getCallCount());
assertTrue("Compiled", l1.getCompiled() != nullptr);
// Copy constructor
LocalizedNumberFormatter l2 = l1;
- assertEquals("[constructor] Copy behavior", u"10%", l2.formatInt(10, status).toString());
+ assertEquals("[constructor] Copy behavior", u"10%", l2.formatInt(10, status).toString(status));
assertEquals("[constructor] Copy should not have compiled state", 1, l2.getCallCount());
assertTrue("[constructor] Copy should not have compiled state", l2.getCompiled() == nullptr);
// Move constructor
LocalizedNumberFormatter l3 = std::move(l1);
- assertEquals("[constructor] Move behavior", u"10%", l3.formatInt(10, status).toString());
+ assertEquals("[constructor] Move behavior", u"10%", l3.formatInt(10, status).toString(status));
assertEquals("[constructor] Move *should* have compiled state", INT32_MIN, l3.getCallCount());
assertTrue("[constructor] Move *should* have compiled state", l3.getCompiled() != nullptr);
assertEquals("[constructor] Source should be reset after move", 0, l1.getCallCount());
@@ -2705,13 +2705,13 @@ void NumberFormatterApiTest::copyMove() {
// Copy assignment
l1 = l3;
- assertEquals("[assignment] Copy behavior", u"10%", l1.formatInt(10, status).toString());
+ assertEquals("[assignment] Copy behavior", u"10%", l1.formatInt(10, status).toString(status));
assertEquals("[assignment] Copy should not have compiled state", 1, l1.getCallCount());
assertTrue("[assignment] Copy should not have compiled state", l1.getCompiled() == nullptr);
// Move assignment
l2 = std::move(l3);
- assertEquals("[assignment] Move behavior", u"10%", l2.formatInt(10, status).toString());
+ assertEquals("[assignment] Move behavior", u"10%", l2.formatInt(10, status).toString(status));
assertEquals("[assignment] Move *should* have compiled state", INT32_MIN, l2.getCallCount());
assertTrue("[assignment] Move *should* have compiled state", l2.getCompiled() != nullptr);
assertEquals("[assignment] Source should be reset after move", 0, l3.getCallCount());
@@ -2719,22 +2719,22 @@ void NumberFormatterApiTest::copyMove() {
// Coverage tests for UnlocalizedNumberFormatter
UnlocalizedNumberFormatter u1;
- assertEquals("Default behavior", u"10", u1.locale("en").formatInt(10, status).toString());
+ assertEquals("Default behavior", u"10", u1.locale("en").formatInt(10, status).toString(status));
u1 = u1.unit(NoUnit::percent());
- assertEquals("Copy assignment", u"10%", u1.locale("en").formatInt(10, status).toString());
+ assertEquals("Copy assignment", u"10%", u1.locale("en").formatInt(10, status).toString(status));
UnlocalizedNumberFormatter u2 = u1;
- assertEquals("Copy constructor", u"10%", u2.locale("en").formatInt(10, status).toString());
+ assertEquals("Copy constructor", u"10%", u2.locale("en").formatInt(10, status).toString(status));
UnlocalizedNumberFormatter u3 = std::move(u1);
- assertEquals("Move constructor", u"10%", u3.locale("en").formatInt(10, status).toString());
+ assertEquals("Move constructor", u"10%", u3.locale("en").formatInt(10, status).toString(status));
u1 = NumberFormatter::with();
u1 = std::move(u2);
- assertEquals("Move assignment", u"10%", u1.locale("en").formatInt(10, status).toString());
+ assertEquals("Move assignment", u"10%", u1.locale("en").formatInt(10, status).toString(status));
// FormattedNumber move operators
FormattedNumber result = l1.formatInt(10, status);
- assertEquals("FormattedNumber move constructor", u"10%", result.toString());
+ assertEquals("FormattedNumber move constructor", u"10%", result.toString(status));
result = l1.formatInt(20, status);
- assertEquals("FormattedNumber move assignment", u"20%", result.toString());
+ assertEquals("FormattedNumber move assignment", u"20%", result.toString(status));
}
void NumberFormatterApiTest::localPointerCAPI() {
@@ -2777,10 +2777,10 @@ void NumberFormatterApiTest::assertFormatDescending(const char16_t* umessage, co
double d = inputs[i];
UnicodeString expected = va_arg(args, const char16_t*);
expecteds[i] = expected;
- UnicodeString actual1 = l1.formatDouble(d, status).toString();
+ UnicodeString actual1 = l1.formatDouble(d, status).toString(status);
assertSuccess(message + u": Unsafe Path: " + caseNumber, status);
assertEquals(message + u": Unsafe Path: " + caseNumber, expected, actual1);
- UnicodeString actual2 = l2.formatDouble(d, status).toString();
+ UnicodeString actual2 = l2.formatDouble(d, status).toString(status);
assertSuccess(message + u": Safe Path: " + caseNumber, status);
assertEquals(message + u": Safe Path: " + caseNumber, expected, actual2);
}
@@ -2793,7 +2793,7 @@ void NumberFormatterApiTest::assertFormatDescending(const char16_t* umessage, co
LocalizedNumberFormatter l3 = NumberFormatter::forSkeleton(normalized, status).locale(locale);
for (int32_t i = 0; i < 9; i++) {
double d = inputs[i];
- UnicodeString actual3 = l3.formatDouble(d, status).toString();
+ UnicodeString actual3 = l3.formatDouble(d, status).toString(status);
assertEquals(message + ": Skeleton Path: '" + normalized + "': " + d, expecteds[i], actual3);
}
} else {
@@ -2818,10 +2818,10 @@ void NumberFormatterApiTest::assertFormatDescendingBig(const char16_t* umessage,
double d = inputs[i];
UnicodeString expected = va_arg(args, const char16_t*);
expecteds[i] = expected;
- UnicodeString actual1 = l1.formatDouble(d, status).toString();
+ UnicodeString actual1 = l1.formatDouble(d, status).toString(status);
assertSuccess(message + u": Unsafe Path: " + caseNumber, status);
assertEquals(message + u": Unsafe Path: " + caseNumber, expected, actual1);
- UnicodeString actual2 = l2.formatDouble(d, status).toString();
+ UnicodeString actual2 = l2.formatDouble(d, status).toString(status);
assertSuccess(message + u": Safe Path: " + caseNumber, status);
assertEquals(message + u": Safe Path: " + caseNumber, expected, actual2);
}
@@ -2834,7 +2834,7 @@ void NumberFormatterApiTest::assertFormatDescendingBig(const char16_t* umessage,
LocalizedNumberFormatter l3 = NumberFormatter::forSkeleton(normalized, status).locale(locale);
for (int32_t i = 0; i < 9; i++) {
double d = inputs[i];
- UnicodeString actual3 = l3.formatDouble(d, status).toString();
+ UnicodeString actual3 = l3.formatDouble(d, status).toString(status);
assertEquals(message + ": Skeleton Path: '" + normalized + "': " + d, expecteds[i], actual3);
}
} else {
@@ -2852,10 +2852,10 @@ NumberFormatterApiTest::assertFormatSingle(const char16_t* umessage, const char1
IcuTestErrorCode status(*this, "assertFormatSingle");
status.setScope(message);
FormattedNumber result1 = l1.formatDouble(input, status);
- UnicodeString actual1 = result1.toString();
+ UnicodeString actual1 = result1.toString(status);
assertSuccess(message + u": Unsafe Path", status);
assertEquals(message + u": Unsafe Path", expected, actual1);
- UnicodeString actual2 = l2.formatDouble(input, status).toString();
+ UnicodeString actual2 = l2.formatDouble(input, status).toString(status);
assertSuccess(message + u": Safe Path", status);
assertEquals(message + u": Safe Path", expected, actual2);
if (uskeleton != nullptr) { // if null, skeleton is declared as undefined.
@@ -2865,7 +2865,7 @@ NumberFormatterApiTest::assertFormatSingle(const char16_t* umessage, const char1
UnicodeString normalized = NumberFormatter::forSkeleton(skeleton, status).toSkeleton(status);
assertEquals(message + ": Skeleton:", normalized, f.toSkeleton(status));
LocalizedNumberFormatter l3 = NumberFormatter::forSkeleton(normalized, status).locale(locale);
- UnicodeString actual3 = l3.formatDouble(input, status).toString();
+ UnicodeString actual3 = l3.formatDouble(input, status).toString(status);
assertEquals(message + ": Skeleton Path: '" + normalized + "': " + input, expected, actual3);
} else {
assertUndefinedSkeleton(f);
diff --git a/icu4c/source/test/intltest/numbertest_range.cpp b/icu4c/source/test/intltest/numbertest_range.cpp
index cb6c29f4aa..a15ef9d9b6 100644
--- a/icu4c/source/test/intltest/numbertest_range.cpp
+++ b/icu4c/source/test/intltest/numbertest_range.cpp
@@ -647,7 +647,7 @@ void NumberRangeFormatterTest::testDifferentFormatters() {
u"Different rounding rules",
NumberRangeFormatter::with()
.numberFormatterFirst(NumberFormatter::with().precision(Precision::integer()))
- .numberFormatterSecond(NumberFormatter::with().precision(Precision::fixedDigits(2))),
+ .numberFormatterSecond(NumberFormatter::with().precision(Precision::fixedSignificantDigits(2))),
Locale("en-us"),
u"1–5.0",
u"5–5.0",
diff --git a/icu4c/source/test/intltest/numbertest_skeletons.cpp b/icu4c/source/test/intltest/numbertest_skeletons.cpp
index 8ac0529853..56cee56737 100644
--- a/icu4c/source/test/intltest/numbertest_skeletons.cpp
+++ b/icu4c/source/test/intltest/numbertest_skeletons.cpp
@@ -250,7 +250,7 @@ void NumberSkeletonTest::flexibleSeparators() {
status.setScope(skeletonString);
UnicodeString actual = NumberFormatter::forSkeleton(skeletonString, status).locale("en")
.formatDouble(5142.3, status)
- .toString();
+ .toString(status);
if (!status.errDataIfFailureAndReset()) {
assertEquals(skeletonString, expected, actual);
}
diff --git a/icu4c/source/test/intltest/numfmtst.cpp b/icu4c/source/test/intltest/numfmtst.cpp
index 91ff9f0d91..6781885177 100644
--- a/icu4c/source/test/intltest/numfmtst.cpp
+++ b/icu4c/source/test/intltest/numfmtst.cpp
@@ -8790,7 +8790,7 @@ void NumberFormatTest::TestFastFormatInt32() {
static_cast
- * If multiple different field attributes are needed, this method can be called repeatedly, or if
- * all field attributes are needed, consider using getFieldIterator().
- *
- *
- * If a field occurs multiple times in an output string, such as a grouping separator, this method
- * will only ever return the first occurrence. Use getFieldIterator() to access all occurrences of an
- * attribute.
- *
- * @param fieldPosition
- * The FieldPosition to populate with the start and end indices of the desired field.
- * @deprecated ICU 62 Use {@link #nextFieldPosition} instead. This method will be removed in a future
- * release. See http://bugs.icu-project.org/trac/ticket/13746
- * @see com.ibm.icu.text.NumberFormat.Field
- * @see NumberFormatter
- */
- @Deprecated
- public void populateFieldPosition(FieldPosition fieldPosition) {
- // in case any users were depending on the old behavior:
- fieldPosition.setBeginIndex(0);
- fieldPosition.setEndIndex(0);
- nextFieldPosition(fieldPosition);
- }
-
/**
* Determines the start and end indices of the next occurrence of the given field in the
* output string. This allows you to determine the locations of, for example, the integer part,
@@ -169,26 +140,6 @@ public class FormattedNumber implements FormattedValue {
return nsb.nextFieldPosition(fieldPosition);
}
- /**
- * Export the formatted number as an AttributedCharacterIterator. This allows you to determine which
- * characters in the output string correspond to which fields, such as the integer part,
- * fraction part, and sign.
- *
- * If information on only one field is needed, consider using populateFieldPosition() instead.
- *
- * @return An AttributedCharacterIterator, containing information on the field attributes of the
- * number string.
- * @deprecated ICU 62 Use {@link #toCharacterIterator} instead. This method will be removed in a future
- * release. See http://bugs.icu-project.org/trac/ticket/13746
- * @see com.ibm.icu.text.NumberFormat.Field
- * @see AttributedCharacterIterator
- * @see NumberFormatter
- */
- @Deprecated
- public AttributedCharacterIterator getFieldIterator() {
- return nsb.toCharacterIterator();
- }
-
/**
* {@inheritDoc}
*
diff --git a/icu4j/main/classes/core/src/com/ibm/icu/number/FractionRounder.java b/icu4j/main/classes/core/src/com/ibm/icu/number/FractionRounder.java
deleted file mode 100644
index 5fd1a6e7b3..0000000000
--- a/icu4j/main/classes/core/src/com/ibm/icu/number/FractionRounder.java
+++ /dev/null
@@ -1,15 +0,0 @@
-// © 2017 and later: Unicode, Inc. and others.
-// License & terms of use: http://www.unicode.org/copyright.html#License
-package com.ibm.icu.number;
-
-/**
- * @deprecated ICU 62 Use {@link FractionPrecision} instead. This class is for backwards compatibility
- * and will be removed in ICU 64. See http://bugs.icu-project.org/trac/ticket/13746
- */
-@Deprecated
-public abstract class FractionRounder extends FractionPrecision {
- // package private constructor just for blocking
- // java compiler to generate public no-arg constructor.
- FractionRounder() {
- }
-}
\ No newline at end of file
diff --git a/icu4j/main/classes/core/src/com/ibm/icu/number/LocalizedNumberFormatter.java b/icu4j/main/classes/core/src/com/ibm/icu/number/LocalizedNumberFormatter.java
index 29e9cb4ab7..6452130d27 100644
--- a/icu4j/main/classes/core/src/com/ibm/icu/number/LocalizedNumberFormatter.java
+++ b/icu4j/main/classes/core/src/com/ibm/icu/number/LocalizedNumberFormatter.java
@@ -161,8 +161,8 @@ public class LocalizedNumberFormatter extends NumberFormatterSettings
* http://www.serpentine.com/blog/2011/06/29/here-be-dragons-advances-in-problems-you-didnt-even-know-you-had/
@@ -279,42 +278,6 @@ public abstract class Precision implements Cloneable {
}
}
- /**
- * @deprecated ICU 62 Use *SignificantDigits() instead. This method is for backwards compatibility
- * and will be removed in ICU 64. See http://bugs.icu-project.org/trac/ticket/13746
- */
- @Deprecated
- public static Precision fixedDigits(int a) {
- return fixedSignificantDigits(a);
- }
-
- /**
- * @deprecated ICU 62 Use *SignificantDigits() instead. This method is for backwards compatibility
- * and will be removed in ICU 64. See http://bugs.icu-project.org/trac/ticket/13746
- */
- @Deprecated
- public static Precision minDigits(int a) {
- return minSignificantDigits(a);
- }
-
- /**
- * @deprecated ICU 62 Use *SignificantDigits() instead. This method is for backwards compatibility
- * and will be removed in ICU 64. See http://bugs.icu-project.org/trac/ticket/13746
- */
- @Deprecated
- public static Precision maxDigits(int a) {
- return maxSignificantDigits(a);
- }
-
- /**
- * @deprecated ICU 62 Use *SignificantDigits() instead. This method is for backwards compatibility
- * and will be removed in ICU 64. See http://bugs.icu-project.org/trac/ticket/13746
- */
- @Deprecated
- public static Precision minMaxDigits(int a, int b) {
- return minMaxSignificantDigits(a, b);
- }
-
/**
* Show numbers rounded if necessary to the closest multiple of a certain rounding increment. For
* example, if the rounding increment is 0.5, then round 1.2 to 1 and round 1.3 to 1.5.
@@ -376,24 +339,7 @@ public abstract class Precision implements Cloneable {
}
/**
- * Sets the {@link java.math.RoundingMode} to use when picking the direction to round (up or down).
- * Common values include HALF_EVEN, HALF_UP, and FLOOR. The default is HALF_EVEN.
- *
- * @param roundingMode
- * The RoundingMode to use.
- * @return A Precision for chaining.
- * @deprecated ICU 62 Use the top-level rounding mode setting instead. This method is for backwards
- * compatibility and will be removed in ICU 64. See
- * http://bugs.icu-project.org/trac/ticket/13746
- * @see NumberFormatter
- */
- @Deprecated
- public Precision withMode(RoundingMode roundingMode) {
- return withMode(RoundingUtils.mathContextUnlimited(roundingMode));
- }
-
- /**
- * Sets a MathContext directly instead of RoundingMode.
+ * Sets a MathContext to use on this Precision.
*
* @internal
* @deprecated This API is ICU internal only.
diff --git a/icu4j/main/classes/core/src/com/ibm/icu/number/Rounder.java b/icu4j/main/classes/core/src/com/ibm/icu/number/Rounder.java
deleted file mode 100644
index fa42942825..0000000000
--- a/icu4j/main/classes/core/src/com/ibm/icu/number/Rounder.java
+++ /dev/null
@@ -1,15 +0,0 @@
-// © 2018 and later: Unicode, Inc. and others.
-// License & terms of use: http://www.unicode.org/copyright.html#License
-package com.ibm.icu.number;
-
-/**
- * @deprecated ICU 62 Use {@link Precision} instead. This class is for backwards compatibility and will
- * be removed in ICU 64. See http://bugs.icu-project.org/trac/ticket/13746
- */
-@Deprecated
-public abstract class Rounder extends Precision {
- // package private constructor just for blocking
- // java compiler to generate public no-arg constructor.
- Rounder() {
- }
-}
diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormat.java
index f520e5ae5c..025e6bbaa6 100644
--- a/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormat.java
+++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormat.java
@@ -777,7 +777,7 @@ public class DecimalFormat extends NumberFormat {
if (!(obj instanceof Number)) throw new IllegalArgumentException();
Number number = (Number) obj;
FormattedNumber output = formatter.format(number);
- return output.getFieldIterator();
+ return output.toCharacterIterator();
}
/**
diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/MeasureFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/MeasureFormat.java
index 079356f7a0..cd8d893e61 100644
--- a/icu4j/main/classes/core/src/com/ibm/icu/text/MeasureFormat.java
+++ b/icu4j/main/classes/core/src/com/ibm/icu/text/MeasureFormat.java
@@ -36,6 +36,7 @@ import com.ibm.icu.impl.ICUResourceBundle;
import com.ibm.icu.impl.SimpleCache;
import com.ibm.icu.impl.SimpleFormatterImpl;
import com.ibm.icu.impl.number.LongNameHandler;
+import com.ibm.icu.impl.number.RoundingUtils;
import com.ibm.icu.number.FormattedNumber;
import com.ibm.icu.number.LocalizedNumberFormatter;
import com.ibm.icu.number.NumberFormatter;
@@ -320,7 +321,7 @@ public class MeasureFormat extends UFormat {
formatMeasuresInternal(toAppendTo, fpos, (Measure[]) obj);
} else if (obj instanceof Measure) {
FormattedNumber result = formatMeasure((Measure) obj);
- result.populateFieldPosition(fpos); // No offset: toAppendTo.length() is considered below
+ result.nextFieldPosition(fpos); // No offset: toAppendTo.length() is considered below
result.appendTo(toAppendTo);
} else {
throw new IllegalArgumentException(obj.toString());
@@ -433,7 +434,7 @@ public class MeasureFormat extends UFormat {
}
if (measures.length == 1) {
FormattedNumber result = formatMeasure(measures[0]);
- result.populateFieldPosition(fieldPosition);
+ result.nextFieldPosition(fieldPosition);
result.appendTo(appendTo);
return;
}
@@ -741,7 +742,8 @@ public class MeasureFormat extends UFormat {
} else {
assert type == NUMBER_FORMATTER_INTEGER;
formatter = getNumberFormatter().unit(unit).perUnit(perUnit).unitWidth(formatWidth.unitWidth)
- .rounding(Precision.integer().withMode(RoundingMode.DOWN));
+ .precision(Precision.integer().withMode(
+ RoundingUtils.mathContextUnlimited(RoundingMode.DOWN)));
}
formatter3 = formatter2;
formatter2 = formatter1;
@@ -802,7 +804,7 @@ public class MeasureFormat extends UFormat {
result = formatMeasureInteger(measures[i]);
}
if (fieldPositionFoundIndex == -1) {
- result.populateFieldPosition(fpos);
+ result.nextFieldPosition(fpos);
if (fpos.getEndIndex() != 0) {
fieldPositionFoundIndex = i;
}
@@ -929,7 +931,7 @@ public class MeasureFormat extends UFormat {
// when formatting 0 minutes 9 seconds, we may get "00:9" instead of "00:09"
FieldPosition intFieldPosition = new FieldPosition(NumberFormat.INTEGER_FIELD);
FormattedNumber result = getNumberFormatter().format(smallestAmount);
- result.populateFieldPosition(intFieldPosition);
+ result.nextFieldPosition(intFieldPosition);
smallestAmountFormatted = result.toString();
// Give up if there is no integer field.
if (intFieldPosition.getBeginIndex() == 0 && intFieldPosition.getEndIndex() == 0) {
diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/number/ExhaustiveNumberTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/number/ExhaustiveNumberTest.java
index 5bfec66f22..8813857517 100644
--- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/number/ExhaustiveNumberTest.java
+++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/number/ExhaustiveNumberTest.java
@@ -92,7 +92,7 @@ public class ExhaustiveNumberTest extends TestFmwk {
BigDecimal ten10000 = BigDecimal.valueOf(10).pow(10000);
BigDecimal longFraction = ten10000.subtract(BigDecimal.ONE).divide(ten10000);
String expected = longFraction.toPlainString();
- String actual = NumberFormatter.withLocale(ULocale.ENGLISH).rounding(Precision.unlimited())
+ String actual = NumberFormatter.withLocale(ULocale.ENGLISH).precision(Precision.unlimited())
.format(longFraction).toString();
assertEquals("All digits should be displayed", expected, actual);
}
diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/number/NumberFormatterApiTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/number/NumberFormatterApiTest.java
index 1545e04579..5cfd6e1df1 100644
--- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/number/NumberFormatterApiTest.java
+++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/number/NumberFormatterApiTest.java
@@ -2504,9 +2504,9 @@ public class NumberFormatterApiTest {
Method[] methodsWithOneArgument = new Method[] { Precision.class.getDeclaredMethod("fixedFraction", Integer.TYPE),
Precision.class.getDeclaredMethod("minFraction", Integer.TYPE),
Precision.class.getDeclaredMethod("maxFraction", Integer.TYPE),
- Precision.class.getDeclaredMethod("fixedDigits", Integer.TYPE),
- Precision.class.getDeclaredMethod("minDigits", Integer.TYPE),
- Precision.class.getDeclaredMethod("maxDigits", Integer.TYPE),
+ Precision.class.getDeclaredMethod("fixedSignificantDigits", Integer.TYPE),
+ Precision.class.getDeclaredMethod("minSignificantDigits", Integer.TYPE),
+ Precision.class.getDeclaredMethod("maxSignificantDigits", Integer.TYPE),
FractionPrecision.class.getDeclaredMethod("withMinDigits", Integer.TYPE),
FractionPrecision.class.getDeclaredMethod("withMaxDigits", Integer.TYPE),
ScientificNotation.class.getDeclaredMethod("withMinExponentDigits", Integer.TYPE),
@@ -2514,7 +2514,7 @@ public class NumberFormatterApiTest {
IntegerWidth.class.getDeclaredMethod("truncateAt", Integer.TYPE), };
Method[] methodsWithTwoArguments = new Method[] {
Precision.class.getDeclaredMethod("minMaxFraction", Integer.TYPE, Integer.TYPE),
- Precision.class.getDeclaredMethod("minMaxDigits", Integer.TYPE, Integer.TYPE), };
+ Precision.class.getDeclaredMethod("minMaxSignificantDigits", Integer.TYPE, Integer.TYPE), };
final int EXPECTED_MAX_INT_FRAC_SIG = 999;
final String expectedSubstring0 = "between 0 and 999 (inclusive)";
@@ -2524,10 +2524,10 @@ public class NumberFormatterApiTest {
// We require that the upper bounds all be 999 inclusive.
// The lower bound may be either -1, 0, or 1.
Set