ICU-21957 fix NumberFormatterSettings::unitDisplayCase status, remove FormattedNumber:getGender

This commit is contained in:
Peter Edberg 2022-09-15 11:27:29 -07:00 committed by Peter Edberg
parent db59034793
commit b734048799
3 changed files with 14 additions and 321 deletions

View file

@ -45,11 +45,6 @@ UDisplayOptionsNounClass FormattedNumber::getNounClass(UErrorCode &status) const
return udispopt_fromNounClassIdentifier(nounClass);
}
const char *FormattedNumber::getGender(UErrorCode &status) const {
UPRV_FORMATTED_VALUE_METHOD_GUARD("")
return fData->gender;
}
void FormattedNumber::getDecimalQuantity(impl::DecimalQuantity& output, UErrorCode& status) const {
UPRV_FORMATTED_VALUE_METHOD_GUARD(UPRV_NOARG)
output = fData->quantity;

View file

@ -2275,24 +2275,30 @@ class U_I18N_API NumberFormatterSettings {
Derived displayOptions(const DisplayOptions &displayOptions) &&;
#endif // U_HIDE_DRAFT_API
#ifndef U_HIDE_DEPRECATED_API
#ifndef U_HIDE_INTERNAL_API
/**
* NOTE: This function is deprecated, use `displayOptions` instead.
* NOTE: Use `displayOptions` instead. This method was part of
* an internal technology preview in ICU 69, but will be removed
* in ICU 73, in favor of `displayOptions`
*
* Specifies the desired case for a unit formatter's output (e.g.
* accusative, dative, genitive).
*
* @deprecated ICU 72
* @internal
*/
Derived unitDisplayCase(StringPiece unitDisplayCase) const &;
/**
* NOTE: Use `displayOptions` instead. This method was part of
* an internal technology preview in ICU 69, but will be removed
* in ICU 73, in favor of `displayOptions`
*
* Overload of unitDisplayCase() for use on an rvalue reference.
*
* @deprecated ICU 72
* @internal
*/
Derived unitDisplayCase(StringPiece unitDisplayCase) &&;
#endif // U_HIDE_DEPRECATED_API
#endif // U_HIDE_INTERNAL_API
#ifndef U_HIDE_INTERNAL_API
@ -2819,18 +2825,6 @@ class U_I18N_API FormattedNumber : public UMemory, public FormattedValue {
#endif /* U_HIDE_INTERNAL_API */
#ifndef U_HIDE_DEPRECATED_API
/**
* Gets the gender of the formatted output. Returns "" when the gender is
* unknown, or for ungendered languages.
*
* @deprecated This API is for ICU internal use only.
*/
const char *getGender(UErrorCode &status) const;
#endif /* U_HIDE_DEPRECATED_API */
private:
// Can't use LocalPointer because UFormattedNumberData is forward-declared
const impl::UFormattedNumberData *fData;

View file

@ -91,7 +91,6 @@ void NumberFormatterApiTest::runIndexedTest(int32_t index, UBool exec, const cha
TESTCASE_AUTO(unitCurrency);
TESTCASE_AUTO(unitInflections);
TESTCASE_AUTO(unitNounClass);
TESTCASE_AUTO(unitGender);
TESTCASE_AUTO(unitNotConvertible);
TESTCASE_AUTO(unitPercent);
if (!quick) {
@ -2797,304 +2796,9 @@ void NumberFormatterApiTest::unitNounClass() {
UDISPOPT_NOUN_CLASS_UNDEFINED, fn.getNounClass(status));
}
void NumberFormatterApiTest::unitGender() {
IcuTestErrorCode status(*this, "unitGender");
const struct TestCase {
const char *locale;
const char *unitIdentifier;
const char *expectedGender;
} cases[] = {
{"de", "inch", "masculine"},
{"de", "yard", "neuter"},
{"de", "meter", "masculine"},
{"de", "liter", "masculine"},
{"de", "second", "feminine"},
{"de", "minute", "feminine"},
{"de", "hour", "feminine"},
{"de", "day", "masculine"},
{"de", "year", "neuter"},
{"de", "gram", "neuter"},
{"de", "watt", "neuter"},
{"de", "bit", "neuter"},
{"de", "byte", "neuter"},
{"fr", "inch", "masculine"},
{"fr", "yard", "masculine"},
{"fr", "meter", "masculine"},
{"fr", "liter", "masculine"},
{"fr", "second", "feminine"},
{"fr", "minute", "feminine"},
{"fr", "hour", "feminine"},
{"fr", "day", "masculine"},
{"fr", "year", "masculine"},
{"fr", "gram", "masculine"},
// grammaticalFeatures deriveCompound "per" rule takes the gender of the
// numerator unit:
{"de", "meter-per-hour", "masculine"},
{"fr", "meter-per-hour", "masculine"},
{"af", "meter-per-hour", ""}, // ungendered language
// French "times" takes gender from first value, German takes the
// second. Prefix and power does not have impact on gender for these
// languages:
{"de", "square-decimeter-square-second", "feminine"},
{"fr", "square-decimeter-square-second", "masculine"},
// TODO(icu-units#149): percent and permille bypasses LongNameHandler
// when unitWidth is not FULL_NAME:
// // Gender of per-second might be that of percent? TODO(icu-units#28)
// {"de", "percent", "neuter"},
// {"fr", "percent", "masculine"},
// Built-in units whose simple units lack gender in the CLDR data file
{"de", "kilopascal", "neuter"},
{"fr", "kilopascal", "masculine"},
// {"de", "pascal", ""},
// {"fr", "pascal", ""},
// Built-in units that lack gender in the CLDR data file
// {"de", "revolution", ""},
// {"de", "radian", ""},
// {"de", "arc-minute", ""},
// {"de", "arc-second", ""},
{"de", "square-yard", "neuter"}, // POWER
{"de", "square-inch", "masculine"}, // POWER
// {"de", "dunam", ""},
// {"de", "karat", ""},
// {"de", "milligram-ofglucose-per-deciliter", ""}, // COMPOUND, ofglucose
// {"de", "millimole-per-liter", ""}, // COMPOUND, mole
// {"de", "permillion", ""},
// {"de", "permille", ""},
// {"de", "permyriad", ""},
// {"de", "mole", ""},
{"de", "liter-per-kilometer", "masculine"}, // COMPOUND
{"de", "petabyte", "neuter"}, // PREFIX
{"de", "terabit", "neuter"}, // PREFIX
// {"de", "century", ""},
// {"de", "decade", ""},
{"de", "millisecond", "feminine"}, // PREFIX
{"de", "microsecond", "feminine"}, // PREFIX
{"de", "nanosecond", "feminine"}, // PREFIX
// {"de", "ampere", ""},
// {"de", "milliampere", ""}, // PREFIX, ampere
// {"de", "ohm", ""},
// {"de", "calorie", ""},
// {"de", "kilojoule", ""}, // PREFIX, joule
// {"de", "joule", ""},
{"de", "kilowatt-hour", "feminine"}, // COMPOUND
// {"de", "electronvolt", ""},
// {"de", "british-thermal-unit", ""},
// {"de", "therm-us", ""},
// {"de", "pound-force", ""},
// {"de", "newton", ""},
// {"de", "gigahertz", ""}, // PREFIX, hertz
// {"de", "megahertz", ""}, // PREFIX, hertz
// {"de", "kilohertz", ""}, // PREFIX, hertz
// {"de", "hertz", ""},
// {"de", "em", ""},
// {"de", "pixel", ""},
// {"de", "megapixel", ""},
// {"de", "pixel-per-centimeter", ""}, // COMPOUND, pixel
// {"de", "pixel-per-inch", ""}, // COMPOUND, pixel
// {"de", "dot-per-centimeter", ""}, // COMPOUND, dot
// {"de", "dot-per-inch", ""}, // COMPOUND, dot
// {"de", "dot", ""},
// {"de", "earth-radius", ""},
{"de", "decimeter", "masculine"}, // PREFIX
{"de", "micrometer", "masculine"}, // PREFIX
{"de", "nanometer", "masculine"}, // PREFIX
// {"de", "light-year", ""},
// {"de", "astronomical-unit", ""},
// {"de", "furlong", ""},
// {"de", "fathom", ""},
// {"de", "nautical-mile", ""},
// {"de", "mile-scandinavian", ""},
// {"de", "point", ""},
// {"de", "lux", ""},
// {"de", "candela", ""},
// {"de", "lumen", ""},
// {"de", "tonne", ""},
// {"de", "microgram", "neuter"}, // PREFIX
// {"de", "ton", ""},
// {"de", "stone", ""},
// {"de", "ounce-troy", ""},
// {"de", "carat", ""},
{"de", "gigawatt", "neuter"}, // PREFIX
{"de", "milliwatt", "neuter"}, // PREFIX
// {"de", "horsepower", ""},
// {"de", "millimeter-ofhg", ""},
// {"de", "pound-force-per-square-inch", ""}, // COMPOUND, pound-force
// {"de", "inch-ofhg", ""},
// {"de", "bar", ""},
// {"de", "millibar", ""}, // PREFIX, bar
// {"de", "atmosphere", ""},
// {"de", "pascal", ""}, // PREFIX, kilopascal? neuter?
// {"de", "hectopascal", ""}, // PREFIX, pascal, neuter?
// {"de", "megapascal", ""}, // PREFIX, pascal, neuter?
// {"de", "knot", ""},
{"de", "pound-force-foot", "masculine"}, // COMPOUND
{"de", "newton-meter", "masculine"}, // COMPOUND
{"de", "cubic-kilometer", "masculine"}, // POWER
{"de", "cubic-yard", "neuter"}, // POWER
{"de", "cubic-inch", "masculine"}, // POWER
{"de", "megaliter", "masculine"}, // PREFIX
{"de", "hectoliter", "masculine"}, // PREFIX
// {"de", "pint-metric", ""},
// {"de", "cup-metric", ""},
{"de", "acre-foot", "masculine"}, // COMPOUND
// {"de", "bushel", ""},
// {"de", "barrel", ""},
// Units missing gender in German also misses gender in French:
// {"fr", "revolution", ""},
// {"fr", "radian", ""},
// {"fr", "arc-minute", ""},
// {"fr", "arc-second", ""},
{"fr", "square-yard", "masculine"}, // POWER
{"fr", "square-inch", "masculine"}, // POWER
// {"fr", "dunam", ""},
// {"fr", "karat", ""},
{"fr", "milligram-ofglucose-per-deciliter", "masculine"}, // COMPOUND
// {"fr", "millimole-per-liter", ""}, // COMPOUND, mole
// {"fr", "permillion", ""},
// {"fr", "permille", ""},
// {"fr", "permyriad", ""},
// {"fr", "mole", ""},
{"fr", "liter-per-kilometer", "masculine"}, // COMPOUND
// {"fr", "petabyte", ""}, // PREFIX
// {"fr", "terabit", ""}, // PREFIX
// {"fr", "century", ""},
// {"fr", "decade", ""},
{"fr", "millisecond", "feminine"}, // PREFIX
{"fr", "microsecond", "feminine"}, // PREFIX
{"fr", "nanosecond", "feminine"}, // PREFIX
// {"fr", "ampere", ""},
// {"fr", "milliampere", ""}, // PREFIX, ampere
// {"fr", "ohm", ""},
// {"fr", "calorie", ""},
// {"fr", "kilojoule", ""}, // PREFIX, joule
// {"fr", "joule", ""},
// {"fr", "kilowatt-hour", ""}, // COMPOUND
// {"fr", "electronvolt", ""},
// {"fr", "british-thermal-unit", ""},
// {"fr", "therm-us", ""},
// {"fr", "pound-force", ""},
// {"fr", "newton", ""},
// {"fr", "gigahertz", ""}, // PREFIX, hertz
// {"fr", "megahertz", ""}, // PREFIX, hertz
// {"fr", "kilohertz", ""}, // PREFIX, hertz
// {"fr", "hertz", ""},
// {"fr", "em", ""},
// {"fr", "pixel", ""},
// {"fr", "megapixel", ""},
// {"fr", "pixel-per-centimeter", ""}, // COMPOUND, pixel
// {"fr", "pixel-per-inch", ""}, // COMPOUND, pixel
// {"fr", "dot-per-centimeter", ""}, // COMPOUND, dot
// {"fr", "dot-per-inch", ""}, // COMPOUND, dot
// {"fr", "dot", ""},
// {"fr", "earth-radius", ""},
{"fr", "decimeter", "masculine"}, // PREFIX
{"fr", "micrometer", "masculine"}, // PREFIX
{"fr", "nanometer", "masculine"}, // PREFIX
// {"fr", "light-year", ""},
// {"fr", "astronomical-unit", ""},
// {"fr", "furlong", ""},
// {"fr", "fathom", ""},
// {"fr", "nautical-mile", ""},
// {"fr", "mile-scandinavian", ""},
// {"fr", "point", ""},
// {"fr", "lux", ""},
// {"fr", "candela", ""},
// {"fr", "lumen", ""},
// {"fr", "tonne", ""},
// {"fr", "microgram", "masculine"}, // PREFIX
// {"fr", "ton", ""},
// {"fr", "stone", ""},
// {"fr", "ounce-troy", ""},
// {"fr", "carat", ""},
// {"fr", "gigawatt", ""}, // PREFIX
// {"fr", "milliwatt", ""},
// {"fr", "horsepower", ""},
{"fr", "millimeter-ofhg", "masculine"},
// {"fr", "pound-force-per-square-inch", ""}, // COMPOUND, pound-force
{"fr", "inch-ofhg", "masculine"},
// {"fr", "bar", ""},
// {"fr", "millibar", ""}, // PREFIX, bar
// {"fr", "atmosphere", ""},
// {"fr", "pascal", ""}, // PREFIX, kilopascal?
// {"fr", "hectopascal", ""}, // PREFIX, pascal
// {"fr", "megapascal", ""}, // PREFIX, pascal
// {"fr", "knot", ""},
// {"fr", "pound-force-foot", ""},
// {"fr", "newton-meter", ""},
{"fr", "cubic-kilometer", "masculine"}, // POWER
{"fr", "cubic-yard", "masculine"}, // POWER
{"fr", "cubic-inch", "masculine"}, // POWER
{"fr", "megaliter", "masculine"}, // PREFIX
{"fr", "hectoliter", "masculine"}, // PREFIX
// {"fr", "pint-metric", ""},
// {"fr", "cup-metric", ""},
{"fr", "acre-foot", "feminine"}, // COMPOUND
// {"fr", "bushel", ""},
// {"fr", "barrel", ""},
// Some more French units missing gender:
// {"fr", "degree", ""},
{"fr", "square-meter", "masculine"}, // POWER
// {"fr", "terabyte", ""}, // PREFIX, byte
// {"fr", "gigabyte", ""}, // PREFIX, byte
// {"fr", "gigabit", ""}, // PREFIX, bit
// {"fr", "megabyte", ""}, // PREFIX, byte
// {"fr", "megabit", ""}, // PREFIX, bit
// {"fr", "kilobyte", ""}, // PREFIX, byte
// {"fr", "kilobit", ""}, // PREFIX, bit
// {"fr", "byte", ""},
// {"fr", "bit", ""},
// {"fr", "volt", ""},
// {"fr", "watt", ""},
{"fr", "cubic-meter", "masculine"}, // POWER
// gender-lacking builtins within compound units
{"de", "newton-meter-per-second", "masculine"},
// TODO(ICU-21494): determine whether list genders behave as follows,
// and implement proper getListGender support (covering more than just
// two genders):
// // gender rule for lists of people: de "neutral", fr "maleTaints"
// {"de", "day-and-hour-and-minute", "neuter"},
// {"de", "hour-and-minute", "feminine"},
// {"fr", "day-and-hour-and-minute", "masculine"},
// {"fr", "hour-and-minute", "feminine"},
};
LocalizedNumberFormatter formatter;
FormattedNumber fn;
for (const TestCase &t : cases) {
formatter = NumberFormatter::with()
.unit(MeasureUnit::forIdentifier(t.unitIdentifier, status))
.locale(Locale(t.locale));
fn = formatter.formatDouble(1.1, status);
assertEquals(UnicodeString("Testing gender with default width, unit: ") + t.unitIdentifier +
", locale: " + t.locale,
t.expectedGender, fn.getGender(status));
status.assertSuccess();
formatter = NumberFormatter::with()
.unit(MeasureUnit::forIdentifier(t.unitIdentifier, status))
.unitWidth(UNUM_UNIT_WIDTH_FULL_NAME)
.locale(Locale(t.locale));
fn = formatter.formatDouble(1.1, status);
assertEquals(UnicodeString("Testing gender with UNUM_UNIT_WIDTH_FULL_NAME, unit: ") +
t.unitIdentifier + ", locale: " + t.locale,
t.expectedGender, fn.getGender(status));
status.assertSuccess();
}
// Make sure getGender does not return garbage for genderless languages
formatter = NumberFormatter::with().locale(Locale::getEnglish());
fn = formatter.formatDouble(1.1, status);
status.assertSuccess();
assertEquals("getGender for a genderless language", "", fn.getGender(status));
}
// The following test of getGender (removed in ICU 72) is replaced by the above
// parallel test unitNounClass using getNounClass (getGender replacement).
//void NumberFormatterApiTest::unitGender() {...}
void NumberFormatterApiTest::unitNotConvertible() {
IcuTestErrorCode status(*this, "unitNotConvertible");