} // namespace
-MaybeStackVector<ConversionRateInfo>
-getConversionRatesInfo(const MeasureUnit source, const MeasureUnit target, UErrorCode &status) {
+MaybeStackVector<ConversionRateInfo> U_I18N_API
+getConversionRatesInfo(const MaybeStackVector<MeasureUnit> &units, UErrorCode &status) {
MaybeStackVector<ConversionRateInfo> result;
if (U_FAILURE(status)) return result;
- int32_t sourceUnitsLength, targetUnitsLength;
- LocalArray<MeasureUnit> sourceUnits = source.splitToSingleUnits(sourceUnitsLength, status);
- LocalArray<MeasureUnit> targetUnits = target.splitToSingleUnits(targetUnitsLength, status);
-
LocalUResourceBundlePointer unitsBundle(ures_openDirect(NULL, "units", &status));
StackUResourceBundle convertUnitsBundle;
ures_getByKey(unitsBundle.getAlias(), "convertUnits", convertUnitsBundle.getAlias(), &status);
ConversionRateDataSink convertSink(result);
- for (int i = 0; i < sourceUnitsLength; i++) {
- processSingleUnit(sourceUnits[i], convertUnitsBundle.getAlias(), convertSink, status);
- }
+ for (int i = 0; i < units.length(); i++) {
+ int32_t numSingleUnits;
+ LocalArray<MeasureUnit> singleUnits = units[i]->splitToSingleUnits(numSingleUnits, status);
- for (int i = 0; i < targetUnitsLength; i++) {
- processSingleUnit(targetUnits[i], convertUnitsBundle.getAlias(), convertSink, status);
+ for (int i = 0; i < numSingleUnits; i++) {
+ processSingleUnit(singleUnits[i], convertUnitsBundle.getAlias(), convertSink, status);
+ }
}
return result;
}
};
/**
- * Collects and returns ConversionRateInfo needed for conversions from source
- * and to target.
+ * Collects and returns ConversionRateInfo needed for conversions for a set of
+ * units.
*
- * @param source The source unit (the unit type converted from).
- * @param target The target unit (the unit type converted to).
+ * @param units The units for which to load conversion data.
* @param status Receives status.
*/
-MaybeStackVector<ConversionRateInfo> U_I18N_API getConversionRatesInfo(MeasureUnit source,
- MeasureUnit target,
- UErrorCode &status);
+MaybeStackVector<ConversionRateInfo>
+ U_I18N_API getConversionRatesInfo(const MaybeStackVector<MeasureUnit> &units, UErrorCode &status);
U_NAMESPACE_END
logln("---testing: source=\"%s\", target=\"%s\"", t.sourceUnit, t.targetUnit);
IcuTestErrorCode status(*this, "testGetConversionRateInfo");
- MeasureUnit sourceUnit = MeasureUnit::forIdentifier(t.sourceUnit, status);
- MeasureUnit targetUnit = MeasureUnit::forIdentifier(t.targetUnit, status);
- MaybeStackVector<ConversionRateInfo> conversionInfo =
- getConversionRatesInfo(sourceUnit, targetUnit, status);
- if (status.errIfFailureAndReset("getConversionRatesInfo(<%s>, <%s>, ...)",
- sourceUnit.getIdentifier(), targetUnit.getIdentifier())) {
+ MaybeStackVector<MeasureUnit> units;
+ MeasureUnit *item = units.emplaceBack(MeasureUnit::forIdentifier(t.sourceUnit, status));
+ if (!item) {
+ status.set(U_MEMORY_ALLOCATION_ERROR);
+ return;
+ }
+ item = units.emplaceBack(MeasureUnit::forIdentifier(t.targetUnit, status));
+ if (!item) {
+ status.set(U_MEMORY_ALLOCATION_ERROR);
+ return;
+ }
+
+ MaybeStackVector<ConversionRateInfo> conversionInfo = getConversionRatesInfo(units, status);
+ if (status.errIfFailureAndReset("getConversionRatesInfo({<%s>, <%s>}, ...)", t.sourceUnit,
+ t.targetUnit)) {
continue;
}