}
UnicodeString
-PluralRules::select(const Formattable& obj, const NumberFormat& fmt) const {
- UErrorCode status = U_ZERO_ERROR;
- const DecimalFormat *decFmt = dynamic_cast<const DecimalFormat *>(&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<const DecimalFormat *>(&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
* @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
return 0;
}
Formattable obj(number);
- UnicodeString result = plrules->select(obj, *nf);
+ UnicodeString result = plrules->select(obj, *nf, *status);
return result.extract(keyword, capacity, *status);
}