]> granicus.if.org Git - icu/commitdiff
Post-merge: update code to make "make check" pass.
authorHugo van der Merwe <17109322+hugovdm@users.noreply.github.com>
Tue, 28 Apr 2020 19:55:19 +0000 (21:55 +0200)
committerHugo van der Merwe <17109322+hugovdm@users.noreply.github.com>
Wed, 29 Apr 2020 11:58:58 +0000 (13:58 +0200)
* MaybeStackVector<ConversionRateInfo> -> ConversionRates.
* Inherit from UMemory to make MaybeStackVector happy (UnitConverter
  and ConverterPreference).
* Hack around getUnitsData's bad interface.

Code is still bad though, unit tests don't cover everything:

* getUnitsData does not work correctly, and various things are marked
  with "WIP" comments (Work In Progress).

icu4c/source/i18n/complexunitsconverter.cpp
icu4c/source/i18n/complexunitsconverter.h
icu4c/source/i18n/unitconverter.cpp
icu4c/source/i18n/unitconverter.h
icu4c/source/i18n/unitsrouter.cpp
icu4c/source/i18n/unitsrouter.h
icu4c/source/test/intltest/unitstest.cpp

index 1b6389b5953b4a2b394460dcbd23ae89431b7120..b5eca8e1c69c1e84c97d7a756baccf19685dd02f 100644 (file)
@@ -15,8 +15,7 @@
 U_NAMESPACE_BEGIN
 
 ComplexUnitsConverter::ComplexUnitsConverter(const MeasureUnit inputUnit, const MeasureUnit outputUnits,
-                                             const MaybeStackVector<ConversionRateInfo> &ratesInfo,
-                                             UErrorCode &status) {
+                                             const ConversionRates &ratesInfo, UErrorCode &status) {
     int32_t length;
     auto singleUnits = outputUnits.splitToSingleUnits(length, status);
     MaybeStackVector<MeasureUnit> singleUnitsInOrder;
@@ -30,8 +29,7 @@ ComplexUnitsConverter::ComplexUnitsConverter(const MeasureUnit inputUnit, const
 
 ComplexUnitsConverter::ComplexUnitsConverter(const MeasureUnit inputUnit,
                                              const MaybeStackVector<MeasureUnit> outputUnits,
-                                             const MaybeStackVector<ConversionRateInfo> &ratesInfo,
-                                             UErrorCode &status) {
+                                             const ConversionRates &ratesInfo, UErrorCode &status) {
     if (outputUnits.length() == 0) {
         status = U_ILLEGAL_ARGUMENT_ERROR;
         return;
index d021ed9cc3a7e0b649d1abc6ee499f4eda4cb2bf..3b71689416f0b851ed0fb5354f8446d3d0ae3846 100644 (file)
@@ -31,10 +31,10 @@ class U_I18N_API ComplexUnitsConverter {
      * @param status
      */
     ComplexUnitsConverter(const MeasureUnit inputUnit, const MaybeStackVector<MeasureUnit> outputUnits,
-                          const MaybeStackVector<ConversionRateInfo> &ratesInfo, UErrorCode &status);
+                          const ConversionRates &ratesInfo, UErrorCode &status);
 
     ComplexUnitsConverter(const MeasureUnit inputUnit, const MeasureUnit outputUnits,
-                          const MaybeStackVector<ConversionRateInfo> &ratesInfo, UErrorCode &status);
+                          const ConversionRates &ratesInfo, UErrorCode &status);
 
     // Returns true if the `quantity` in the `inputUnit` is greater than or equal than the `limit` in the
     // biggest `outputUnits`
index 5e3e76fa5c602c4ff6b76f64a0a6e41be91588c0..85b82521dbb4f433560f932485babc920316cd86 100644 (file)
@@ -268,7 +268,7 @@ void addFactorElement(Factor &factor, StringPiece elementStr, SigNum sigNum) {
 /*
  * Extracts `Factor` from a complete string factor. e.g. "ft2m^3*1007/cup2m3*3"
  *
- * TODO: unused parameter 'status' [-Wunused-parameter]
+ * TODO: warning: unused parameter 'status' [-Wunused-parameter]
  */
 Factor extractFactorConversions(StringPiece stringFactor, UErrorCode &status) {
     Factor result;
@@ -343,7 +343,7 @@ void substituteSingleConstant(int32_t constantPower,
     }
 }
 
-// TODO: unused parameter 'status' [-Wunused-parameter]
+// TODO: warning: unused parameter 'status' [-Wunused-parameter]
 void substituteConstants(Factor &factor, UErrorCode &status) {
     double constantsValues[CONSTANTS_COUNT];
 
index 62d9582f4ec31c817bfb240c10c20da6e77ff801..272de4ca50b16ac04d39f548bcd00d708fed3371 100644 (file)
@@ -42,7 +42,7 @@ UnitsConvertibilityState U_I18N_API checkConvertibility(const MeasureUnit &sourc
 /**
  * Converts from a source `MeasureUnit` to a target `MeasureUnit`.
  */
-class U_I18N_API UnitConverter {
+class U_I18N_API UnitConverter : public UMemory {
   public:
     /**
      * Constructor of `UnitConverter`.
index 62e59c8e2ade9ab0cbcdc5701318868717aa33cd..5ca1347aedad59760cbaf9bcd720e52fa4036809 100644 (file)
@@ -25,9 +25,12 @@ UnitsRouter::UnitsRouter(MeasureUnit inputUnit, StringPiece locale, StringPiece
     const char *region = "001"; // FIXME extract from locale.
     CharString category;
     MeasureUnit baseUnit;
-    MaybeStackVector<ConversionRateInfo> conversionRates;
+    ConversionRates conversionRates(status);
+
+    // WIP/TODO(hugovdm): drop tmpConversionRates, redo getUnitsData.
+    MaybeStackVector<ConversionRateInfo> tmpConversionRates;
     MaybeStackVector<UnitPreference> unitPreferences;
-    getUnitsData(region, usage.data(), inputUnit, category, baseUnit, conversionRates, unitPreferences,
+    getUnitsData(region, usage.data(), inputUnit, category, baseUnit, tmpConversionRates, unitPreferences,
                  status);
 
     for (int i = 0, n = unitPreferences.length(); i < n; ++i) {
index 0b25c63c11938a3f355ae5dbba109490e8c6383f..9e38f150569b2f326c9610565e57e2e97b0cadcd 100644 (file)
 
 U_NAMESPACE_BEGIN
 
-struct ConverterPreference {
+struct ConverterPreference : UMemory {
     ComplexUnitsConverter converter;
     double limit;
 
     ConverterPreference(MeasureUnit source, MeasureUnit complexTarget, double limit,
-                        const MaybeStackVector<ConversionRateInfo> &ratesInfo, UErrorCode &status)
+                        const ConversionRates &ratesInfo, UErrorCode &status)
         : converter(source, complexTarget, ratesInfo, status), limit(limit) {}
 };
 
index 1b92c12b664550d27b4e8e6415c8df9fd70720c0..247a89f59f8bacf2fd68206ab7c2b1ed0d02bd8c 100644 (file)
@@ -157,10 +157,8 @@ void UnitsTest::verifyTestCase(const UnitConversionTestCase &testCase) {
     MeasureUnit sourceUnit = MeasureUnit::forIdentifier(testCase.source, status);
     MeasureUnit targetUnit = MeasureUnit::forIdentifier(testCase.target, status);
 
-    MaybeStackVector<ConversionRateInfo> unitsInfos;
-    getAllConversionRates(unitsInfos, status);
-
-    UnitConverter converter(sourceUnit, targetUnit, unitsInfos, status);
+    ConversionRates conversionRates(status);
+    UnitConverter converter(sourceUnit, targetUnit, conversionRates, status);
 
     double actual = converter.convert(testCase.inputValue);