/**
* A ResourceSink that collects conversion rate information.
*
- * This class is for use by ures_getAllItemsWithFallback. Example code for
- * collecting conversion info for "mile" and "foot" into conversionInfoOutput:
- *
- * UErrorCode status = U_ZERO_ERROR;
- * ures_getByKey(unitsBundle, "convertUnits", &fillIn, &status);
- * MaybeStackVector<ConversionRateInfo> conversionInfoOutput;
- * ConversionRateDataSink convertSink(conversionInfoOutput);
- * ures_getAllItemsWithFallback(fillIn, "mile", convertSink, status);
- * ures_getAllItemsWithFallback(fillIn, "foot", convertSink, status);
+ * This class is for use by ures_getAllItemsWithFallback.
*/
class ConversionRateDataSink : public ResourceSink {
public:
void put(const char *source, ResourceValue &value, UBool /*noFallback*/, UErrorCode &status) {
if (U_FAILURE(status)) return;
if (uprv_strcmp(source, "convertUnits") != 0) {
+ // This is very strict, however it is the cheapest way to be sure
+ // that with `value`, we're looking at the convertUnits table.
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
U_NAMESPACE_BEGIN
-// Encapsulates "convertUnits" information from units resources, specifying how
-// to convert from one unit to another.
-//
-// Information in this class is still in the form of strings: symbolic constants
-// need to be interpreted.
+/**
+ * Encapsulates "convertUnits" information from units resources, specifying how
+ * to convert from one unit to another.
+ *
+ * Information in this class is still in the form of strings: symbolic constants
+ * need to be interpreted. Rationale: symbols can cancel out for higher
+ * precision conversion - going from feet to inches should cancel out the
+ * `ft_to_m` constant.
+ */
class U_I18N_API ConversionRateInfo {
public:
ConversionRateInfo(){};
MaybeStackVector<ConversionRateInfo> U_I18N_API getAllConversionRates(UErrorCode &status);
/**
- * Collects and returns ConversionRateInfo needed for conversions for a set of
- * units.
+ * Temporary backward-compatibility function.
*
- * @param units The units for which to load conversion data.
- * @param status Receives status.
+ * TODO(hugovdm): ensure this gets removed. Currently
+ * https://github.com/sffc/icu/pull/32 is making use of it.
+ *
+ * @param units Ignored.
+ * @return the result of getAllConversionRates.
*/
MaybeStackVector<ConversionRateInfo>
U_I18N_API getConversionRatesInfo(const MaybeStackVector<MeasureUnit> &units, UErrorCode &status);