From: Peter Edberg Date: Thu, 9 Feb 2017 23:40:59 +0000 (+0000) Subject: ICU-12763 for C++ select(const Formattable&...), add UErrorCode param, return empty... X-Git-Tag: release-59-rc~151 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=870b0392961bf1351c9663197554219e63ebda47;p=icu ICU-12763 for C++ select(const Formattable&...), add UErrorCode param, return empty string if err X-SVN-Rev: 39658 --- diff --git a/icu4c/source/i18n/plurrule.cpp b/icu4c/source/i18n/plurrule.cpp index 0ce378cba9d..c4155cb4732 100644 --- a/icu4c/source/i18n/plurrule.cpp +++ b/icu4c/source/i18n/plurrule.cpp @@ -248,21 +248,23 @@ PluralRules::select(double number) const { } UnicodeString -PluralRules::select(const Formattable& obj, const NumberFormat& fmt) const { - UErrorCode status = U_ZERO_ERROR; - const DecimalFormat *decFmt = dynamic_cast(&fmt); - if (decFmt != NULL) { - VisibleDigitsWithExponent digits; - decFmt->initVisibleDigitsWithExponent(obj, digits, status); - if (U_SUCCESS(status)) { - return select(digits); - } - } - double number = obj.getDouble(status); +PluralRules::select(const Formattable& obj, const NumberFormat& fmt, UErrorCode& status) const { if (U_SUCCESS(status)) { - return select(number); + const DecimalFormat *decFmt = dynamic_cast(&fmt); + if (decFmt != NULL) { + VisibleDigitsWithExponent digits; + decFmt->initVisibleDigitsWithExponent(obj, digits, status); + if (U_SUCCESS(status)) { + return select(digits); + } + } else { + double number = obj.getDouble(status); + if (U_SUCCESS(status)) { + return select(number); + } + } } - return getKeywordOther(); + return UnicodeString(); } UnicodeString diff --git a/icu4c/source/i18n/unicode/plurrule.h b/icu4c/source/i18n/unicode/plurrule.h index a46abee85e6..d8ab2c52ea0 100644 --- a/icu4c/source/i18n/unicode/plurrule.h +++ b/icu4c/source/i18n/unicode/plurrule.h @@ -356,10 +356,14 @@ public: * @param obj The numeric object for which the rule should be determined. * @param fmt The NumberFormat specifying how the number will be formatted * (this can affect the plural form, e.g. "1 dollar" vs "1.0 dollars"). - * @return The keyword of the selected rule. + * @param status Input/output parameter. If at entry this indicates a + * failure status, the method returns immediately; otherwise + * this is set to indicate the outcome of the call. + * @return The keyword of the selected rule, or an empty string in the case + * of an error. * @internal ICU 59 technology preview, may be removed in the future */ - UnicodeString select(const Formattable& obj, const NumberFormat& fmt) const; + UnicodeString select(const Formattable& obj, const NumberFormat& fmt, UErrorCode& status) const; /** * @internal diff --git a/icu4c/source/i18n/upluralrules.cpp b/icu4c/source/i18n/upluralrules.cpp index 384a87c6b05..4eab7b23082 100644 --- a/icu4c/source/i18n/upluralrules.cpp +++ b/icu4c/source/i18n/upluralrules.cpp @@ -73,7 +73,7 @@ uplrules_selectWithFormat(const UPluralRules *uplrules, return 0; } Formattable obj(number); - UnicodeString result = plrules->select(obj, *nf); + UnicodeString result = plrules->select(obj, *nf, *status); return result.extract(keyword, capacity, *status); }