]> granicus.if.org Git - icu/commitdiff
ICU-21349 Add update instructions for unitConstants. Plus minor fixes.
authorHugo van der Merwe <17109322+hugovdm@users.noreply.github.com>
Fri, 20 Nov 2020 13:55:26 +0000 (14:55 +0100)
committerHugo van der Merwe <17109322+hugovdm@users.noreply.github.com>
Thu, 3 Dec 2020 11:48:01 +0000 (12:48 +0100)
See #1480

docs/processes/release/tasks/updating-measure-unit.md
icu4c/source/test/intltest/units_test.cpp

index 2f10cdbc56891107d84f8993e6b31ade6f658f34..8bd82b927dd8a0b61ab9cd5f2c91c68db2ef10da 100644 (file)
@@ -1,6 +1,11 @@
+<!--
+© 2020 and later: Unicode, Inc. and others.
+License & terms of use: http://www.unicode.org/copyright.html
+-->
+
 # Updating Measure Unit with new CLDR data
 
-This document explains how to update the C and JAVA version of the MeasureUnit
+This document explains how to update the C++ and Java version of the MeasureUnit
 class with new CLDR data.
 
 Code is generated by running MeasureUnitTest.java unit tests, which writes
@@ -80,9 +85,6 @@ that you are updating the MeasureUnit clases for ICU 68.
   `// End generated code for measunit.cpp`
 * Replace all the generated code in between with the contents of the clipboard
 
-\# Update measfmt.cpp -- Update the value for `MEAS_UNIT_COUNT` - no longer
-necessary
-
 ### Run C++ tests
 
 * Run `./intltest format/MeasureFormatTest` from `test/intltest` to ensure new
@@ -109,3 +111,23 @@ will be considered new for the next release too.
 
   **Important:** what you are copying are just the new functions for the current
   ICU version, in this case 68. Therefore append, do not replace.
+
+## Updating units.txt and unitConstants
+
+The standard ldml2icu process is used to update ICU's resource files (see
+[cldr-icu-readme.txt](../../../../icu4c/source/data/cldr-icu-readme.txt)).
+CLDR's units.xml defines conversion rates in terms of some constants defined in
+`unitConstants`.
+
+For efficiency and simplicity, ICU does not read `unitConstants` from the
+resource file. If any new constants are added, some code changes would be
+needed. This would be caught by `testUnitConstantFreshness` unit test in
+`units_test.cpp`.
+
+They are hard-coded:
+* Java: `UnitConverter.java` has the constant names in
+  `UnitConverter.Factor.addEntity()` and constant values in
+  `UnitConverter.Factor.getConversionRate()`.
+* C++: `units_converter.cpp` has the constant names in
+  `addSingleFactorConstant()`, with the constant values in `double
+  constantsValues[]` in the `units_converter.h` header file.
index 6eea5ec2676207a36b7c831c8a94e00b339cf6c7..fb67503616c4b61c3446b9e393c7bbdd4dfdc9f9 100644 (file)
@@ -87,7 +87,8 @@ void UnitsTest::testUnitConstantFreshness() {
         if (status.errDataIfFailureAndReset(
                 "addSingleFactorConstant(<%s>, ...).\n\n"
                 "If U_INVALID_FORMAT_ERROR, please check that \"icu4c/source/i18n/units_converter.cpp\" "
-                "has all constants? Is \"%s\" a new constant?\n",
+                "has all constants? Is \"%s\" a new constant?\n"
+                "See docs/processes/release/tasks/updating-measure-unit.md for more information.\n",
                 constant, constant)) {
             continue;
         }