From de86b3269ec395f5a5c0595017259a2357975f53 Mon Sep 17 00:00:00 2001 From: DraganBesevic Date: Fri, 27 Sep 2024 18:19:05 -0700 Subject: [PATCH] ICU-22723 Integrate CLDR 46 release beta3, part 3, source files --- icu4c/source/i18n/measunit.cpp | 103 +++++++++++------- icu4c/source/i18n/unicode/measunit.h | 84 ++++++++++---- .../icu/dev/test/format/MeasureUnitTest.java | 58 +++++++++- .../java/com/ibm/icu/util/MeasureUnit.java | 6 - 4 files changed, 178 insertions(+), 73 deletions(-) diff --git a/icu4c/source/i18n/measunit.cpp b/icu4c/source/i18n/measunit.cpp index a70d486539ff..2741b84aabf0 100644 --- a/icu4c/source/i18n/measunit.cpp +++ b/icu4c/source/i18n/measunit.cpp @@ -43,24 +43,24 @@ static const int32_t gOffsets[] = { 17, 27, 31, - 332, - 343, - 360, - 364, - 373, - 376, - 380, - 388, - 410, - 414, - 429, - 430, - 436, - 447, - 452, - 456, - 458, - 492 + 333, + 344, + 362, + 366, + 375, + 378, + 382, + 390, + 412, + 416, + 431, + 432, + 438, + 449, + 455, + 459, + 461, + 495 }; static const int32_t kCurrencyOffset = 5; @@ -423,6 +423,7 @@ static const char * const gSubTypes[] = { "ZRZ", "ZWC", "ZWD", + "ZWG", "ZWL", "ZWN", "ZWR", @@ -448,6 +449,7 @@ static const char * const gSubTypes[] = { "month", "month-person", "nanosecond", + "night", "quarter", "second", "week", @@ -544,6 +546,7 @@ static const char * const gSubTypes[] = { "beaufort", "kilometer-per-hour", "knot", + "light-speed", "meter-per-second", "mile-per-hour", "celsius", @@ -1016,54 +1019,62 @@ MeasureUnit MeasureUnit::getNanosecond() { return MeasureUnit(7, 10); } -MeasureUnit *MeasureUnit::createQuarter(UErrorCode &status) { +MeasureUnit *MeasureUnit::createNight(UErrorCode &status) { return MeasureUnit::create(7, 11, status); } -MeasureUnit MeasureUnit::getQuarter() { +MeasureUnit MeasureUnit::getNight() { return MeasureUnit(7, 11); } -MeasureUnit *MeasureUnit::createSecond(UErrorCode &status) { +MeasureUnit *MeasureUnit::createQuarter(UErrorCode &status) { return MeasureUnit::create(7, 12, status); } -MeasureUnit MeasureUnit::getSecond() { +MeasureUnit MeasureUnit::getQuarter() { return MeasureUnit(7, 12); } -MeasureUnit *MeasureUnit::createWeek(UErrorCode &status) { +MeasureUnit *MeasureUnit::createSecond(UErrorCode &status) { return MeasureUnit::create(7, 13, status); } -MeasureUnit MeasureUnit::getWeek() { +MeasureUnit MeasureUnit::getSecond() { return MeasureUnit(7, 13); } -MeasureUnit *MeasureUnit::createWeekPerson(UErrorCode &status) { +MeasureUnit *MeasureUnit::createWeek(UErrorCode &status) { return MeasureUnit::create(7, 14, status); } -MeasureUnit MeasureUnit::getWeekPerson() { +MeasureUnit MeasureUnit::getWeek() { return MeasureUnit(7, 14); } -MeasureUnit *MeasureUnit::createYear(UErrorCode &status) { +MeasureUnit *MeasureUnit::createWeekPerson(UErrorCode &status) { return MeasureUnit::create(7, 15, status); } -MeasureUnit MeasureUnit::getYear() { +MeasureUnit MeasureUnit::getWeekPerson() { return MeasureUnit(7, 15); } -MeasureUnit *MeasureUnit::createYearPerson(UErrorCode &status) { +MeasureUnit *MeasureUnit::createYear(UErrorCode &status) { return MeasureUnit::create(7, 16, status); } -MeasureUnit MeasureUnit::getYearPerson() { +MeasureUnit MeasureUnit::getYear() { return MeasureUnit(7, 16); } +MeasureUnit *MeasureUnit::createYearPerson(UErrorCode &status) { + return MeasureUnit::create(7, 17, status); +} + +MeasureUnit MeasureUnit::getYearPerson() { + return MeasureUnit(7, 17); +} + MeasureUnit *MeasureUnit::createAmpere(UErrorCode &status) { return MeasureUnit::create(8, 0, status); } @@ -1544,14 +1555,6 @@ MeasureUnit MeasureUnit::getKilogram() { return MeasureUnit(15, 5); } -MeasureUnit *MeasureUnit::createMetricTon(UErrorCode &status) { - return MeasureUnit::create(15, 14, status); -} - -MeasureUnit MeasureUnit::getMetricTon() { - return MeasureUnit(15, 14); -} - MeasureUnit *MeasureUnit::createMicrogram(UErrorCode &status) { return MeasureUnit::create(15, 6, status); } @@ -1624,6 +1627,14 @@ MeasureUnit MeasureUnit::getTonne() { return MeasureUnit(15, 14); } +MeasureUnit *MeasureUnit::createMetricTon(UErrorCode &status) { + return MeasureUnit::create(15, 14, status); +} + +MeasureUnit MeasureUnit::getMetricTon() { + return MeasureUnit(15, 14); +} + MeasureUnit *MeasureUnit::createGigawatt(UErrorCode &status) { return MeasureUnit::create(17, 0, status); } @@ -1784,22 +1795,30 @@ MeasureUnit MeasureUnit::getKnot() { return MeasureUnit(19, 2); } -MeasureUnit *MeasureUnit::createMeterPerSecond(UErrorCode &status) { +MeasureUnit *MeasureUnit::createLightSpeed(UErrorCode &status) { return MeasureUnit::create(19, 3, status); } -MeasureUnit MeasureUnit::getMeterPerSecond() { +MeasureUnit MeasureUnit::getLightSpeed() { return MeasureUnit(19, 3); } -MeasureUnit *MeasureUnit::createMilePerHour(UErrorCode &status) { +MeasureUnit *MeasureUnit::createMeterPerSecond(UErrorCode &status) { return MeasureUnit::create(19, 4, status); } -MeasureUnit MeasureUnit::getMilePerHour() { +MeasureUnit MeasureUnit::getMeterPerSecond() { return MeasureUnit(19, 4); } +MeasureUnit *MeasureUnit::createMilePerHour(UErrorCode &status) { + return MeasureUnit::create(19, 5, status); +} + +MeasureUnit MeasureUnit::getMilePerHour() { + return MeasureUnit(19, 5); +} + MeasureUnit *MeasureUnit::createCelsius(UErrorCode &status) { return MeasureUnit::create(20, 0, status); } diff --git a/icu4c/source/i18n/unicode/measunit.h b/icu4c/source/i18n/unicode/measunit.h index 3933b25b455f..b23897192eb4 100644 --- a/icu4c/source/i18n/unicode/measunit.h +++ b/icu4c/source/i18n/unicode/measunit.h @@ -1568,6 +1568,24 @@ class U_I18N_API MeasureUnit: public UObject { */ static MeasureUnit getNanosecond(); +#ifndef U_HIDE_DRAFT_API + /** + * Returns by pointer, unit of duration: night. + * Caller owns returned value and must free it. + * Also see {@link #getNight()}. + * @param status ICU error code. + * @draft ICU 76 + */ + static MeasureUnit *createNight(UErrorCode &status); + + /** + * Returns by value, unit of duration: night. + * Also see {@link #createNight()}. + * @draft ICU 76 + */ + static MeasureUnit getNight(); +#endif /* U_HIDE_DRAFT_API */ + /** * Returns by pointer, unit of duration: quarter. * Caller owns returned value and must free it. @@ -2624,30 +2642,6 @@ class U_I18N_API MeasureUnit: public UObject { */ static MeasureUnit getKilogram(); - /** - * Returns by pointer, unit of mass: metric-ton - * (renamed to tonne in CLDR 42 / ICU 72). - * Caller owns returned value and must free it. - * Note: In ICU 74 this will be deprecated in favor of - * createTonne(), which is currently draft but will - * become stable in ICU 74, and which uses the preferred naming. - * Also see {@link #getMetricTon()} and {@link #createTonne()}. - * @param status ICU error code. - * @stable ICU 54 - */ - static MeasureUnit *createMetricTon(UErrorCode &status); - - /** - * Returns by value, unit of mass: metric-ton - * (renamed to tonne in CLDR 42 / ICU 72). - * Note: In ICU 74 this will be deprecated in favor of - * getTonne(), which is currently draft but will - * become stable in ICU 74, and which uses the preferred naming. - * Also see {@link #createMetricTon()} and {@link #getTonne()}. - * @stable ICU 64 - */ - static MeasureUnit getMetricTon(); - /** * Returns by pointer, unit of mass: microgram. * Caller owns returned value and must free it. @@ -2792,6 +2786,30 @@ class U_I18N_API MeasureUnit: public UObject { */ static MeasureUnit getTonne(); + /** + * Returns by pointer, unit of mass: metric-ton + * (renamed to tonne in CLDR 42 / ICU 72). + * Caller owns returned value and must free it. + * Note: In ICU 74 this will be deprecated in favor of + * createTonne(), which is currently draft but will + * become stable in ICU 74, and which uses the preferred naming. + * Also see {@link #getMetricTon()} and {@link #createTonne()}. + * @param status ICU error code. + * @stable ICU 54 + */ + static MeasureUnit *createMetricTon(UErrorCode &status); + + /** + * Returns by value, unit of mass: metric-ton + * (renamed to tonne in CLDR 42 / ICU 72). + * Note: In ICU 74 this will be deprecated in favor of + * getTonne(), which is currently draft but will + * become stable in ICU 74, and which uses the preferred naming. + * Also see {@link #createMetricTon()} and {@link #getTonne()}. + * @stable ICU 64 + */ + static MeasureUnit getMetricTon(); + /** * Returns by pointer, unit of power: gigawatt. * Caller owns returned value and must free it. @@ -3112,6 +3130,24 @@ class U_I18N_API MeasureUnit: public UObject { */ static MeasureUnit getKnot(); +#ifndef U_HIDE_DRAFT_API + /** + * Returns by pointer, unit of speed: light-speed. + * Caller owns returned value and must free it. + * Also see {@link #getLightSpeed()}. + * @param status ICU error code. + * @draft ICU 76 + */ + static MeasureUnit *createLightSpeed(UErrorCode &status); + + /** + * Returns by value, unit of speed: light-speed. + * Also see {@link #createLightSpeed()}. + * @draft ICU 76 + */ + static MeasureUnit getLightSpeed(); +#endif /* U_HIDE_DRAFT_API */ + /** * Returns by pointer, unit of speed: meter-per-second. * Caller owns returned value and must free it. diff --git a/icu4j/main/common_tests/src/test/java/com/ibm/icu/dev/test/format/MeasureUnitTest.java b/icu4j/main/common_tests/src/test/java/com/ibm/icu/dev/test/format/MeasureUnitTest.java index b2298dba4b99..fbc50fc50106 100644 --- a/icu4j/main/common_tests/src/test/java/com/ibm/icu/dev/test/format/MeasureUnitTest.java +++ b/icu4j/main/common_tests/src/test/java/com/ibm/icu/dev/test/format/MeasureUnitTest.java @@ -2901,7 +2901,6 @@ public void TestCompatible76() { MeasureUnit.PERMILLE, MeasureUnit.PART_PER_MILLION, MeasureUnit.PERMYRIAD, - MeasureUnit.PORTION_PER_1E9, MeasureUnit.LITER_PER_100KILOMETERS, MeasureUnit.LITER_PER_KILOMETER, MeasureUnit.MILE_PER_GALLON, @@ -4129,11 +4128,46 @@ static void generateCXXHConstants(String thisVersion) { System.out.println("#endif /* U_HIDE_DRAFT_API */"); } System.out.println(""); + // Hack: METRIC-TON unit changed its name from "metric-ton" to "tonne" + // In order to preserve the existing APIs for "metric-ton" we need to + // add those APIs manually + if (name.equals("Tonne")) { + addCXXHForMetricTon(); + } } } System.out.println("// End generated createXXX methods"); } + // Add the headers for "metric-ton" + // The tool won't create them any more + private static void addCXXHForMetricTon() { + System.out.println(" /**"); + System.out.println(" * Returns by pointer, unit of mass: metric-ton"); + System.out.println(" * (renamed to tonne in CLDR 42 / ICU 72)."); + System.out.println(" * Caller owns returned value and must free it."); + System.out.println(" * Note: In ICU 74 this will be deprecated in favor of"); + System.out.println(" * createTonne(), which is currently draft but will"); + System.out.println(" * become stable in ICU 74, and which uses the preferred naming."); + System.out.println(" * Also see {@link #getMetricTon()} and {@link #createTonne()}."); + System.out.println(" * @param status ICU error code."); + System.out.println(" * @stable ICU 54"); + System.out.println(" */"); + System.out.println(" static MeasureUnit *createMetricTon(UErrorCode &status);"); + System.out.println(""); + System.out.println(" /**"); + System.out.println(" * Returns by value, unit of mass: metric-ton"); + System.out.println(" * (renamed to tonne in CLDR 42 / ICU 72)."); + System.out.println(" * Note: In ICU 74 this will be deprecated in favor of"); + System.out.println(" * getTonne(), which is currently draft but will"); + System.out.println(" * become stable in ICU 74, and which uses the preferred naming."); + System.out.println(" * Also see {@link #createMetricTon()} and {@link #getTonne()}."); + System.out.println(" * @stable ICU 64"); + System.out.println(" */"); + System.out.println(" static MeasureUnit getMetricTon();"); + System.out.println(""); + } + private static void checkForDup( Map seen, String name, MeasureUnit unit) { if (seen.containsKey(name)) { @@ -4308,11 +4342,33 @@ static void generateCXXConstants() { typeSubType.first, typeSubType.second); System.out.println("}"); System.out.println(); + // Hack: METRIC-TON unit changed its name from "metric-ton" to "tonne" + // In order to preserve the existing APIs for "metric-ton" we need to + // add those APIs manually + if (name.equals("Tonne")) { + addCXXForMetricTon(typeSubType); + } } } System.out.println("// End generated code for measunit.cpp"); } + // Add the API skeletons for "metric-ton" + // The tool won't create them any more + private static void addCXXForMetricTon(Pair typeSubType) { + String name = "MetricTon"; + System.out.printf("MeasureUnit *MeasureUnit::create%s(UErrorCode &status) {\n", name); + System.out.printf(" return MeasureUnit::create(%d, %d, status);\n", + typeSubType.first, typeSubType.second); + System.out.println("}"); + System.out.println(); + System.out.printf("MeasureUnit MeasureUnit::get%s() {\n", name); + System.out.printf(" return MeasureUnit(%d, %d);\n", + typeSubType.first, typeSubType.second); + System.out.println("}"); + System.out.println(); + } + private static String toCamelCase(MeasureUnit unit) { StringBuilder result = new StringBuilder(); boolean caps = true; diff --git a/icu4j/main/core/src/main/java/com/ibm/icu/util/MeasureUnit.java b/icu4j/main/core/src/main/java/com/ibm/icu/util/MeasureUnit.java index d1267528a3ef..1f94544f6f3b 100644 --- a/icu4j/main/core/src/main/java/com/ibm/icu/util/MeasureUnit.java +++ b/icu4j/main/core/src/main/java/com/ibm/icu/util/MeasureUnit.java @@ -1081,12 +1081,6 @@ protected synchronized static MeasureUnit addUnit(String type, String unitName, */ public static final MeasureUnit PERMYRIAD = MeasureUnit.internalGetInstance("concentr", "permyriad"); - /** - * Constant for unit of concentr: portion-per-1e9 - * @draft ICU 76 - */ - public static final MeasureUnit PORTION_PER_1E9 = MeasureUnit.internalGetInstance("concentr", "portion-per-1e9"); - /** * Constant for unit of consumption: liter-per-100-kilometer * @stable ICU 56