Skip to content

Commit

Permalink
Add methods for handling constant denominators in MeasureUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
younies committed Jan 20, 2025
1 parent 2c5e021 commit 82f5fc1
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion icu4c/source/i18n/unicode/measunit.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,40 @@ class U_I18N_API MeasureUnit: public UObject {
*/
UMeasurePrefix getPrefix(UErrorCode& status) const;

/**
* Creates a new MeasureUnit with a specified constant denominator.
*
* This method is applicable only to COMPOUND units. If invoked on a
* SINGLE or MIXED unit, an error will be set in the status.
*
* NOTE: If the constant denominator is set to 0, it means that you are removing
* the constant denominator.
*
* @param denominator The constant denominator to set.
* @param status Set if this is not a COMPOUND or SINGLE unit or if another error occurs.
* @return A new MeasureUnit with the specified constant denominator.
* @draft ICU 77
*/
MeasureUnit withConstantDenominator(int64_t denominator, UErrorCode &status) const;

/**
* Retrieves the constant denominator for this COMPOUND unit.
*
* Examples:
* - For the unit "liter-per-1000-kiloliter", the constant denominator is 1000.
* - For the unit "liter-per-kilometer", the constant denominator is zero.
*
* This method is applicable only to COMPOUND units. If invoked on a SINGLE or
* MIXED unit, an error will be set in the status.
*
* NOTE: If no constant denominator exists, the method returns 0.
*
* @param status Set if this is not a COMPOUND unit or if another error occurs.
* @return The value of the constant denominator.
* @draft ICU 77
*/
int64_t getConstantDenominator(UErrorCode &status) const;

/**
* Creates a MeasureUnit which is this SINGLE unit augmented with the specified dimensionality
* (power). For example, if dimensionality is 2, the unit will be squared.
Expand Down Expand Up @@ -591,7 +625,9 @@ class U_I18N_API MeasureUnit: public UObject {
* NOTE: Only works on SINGLE and COMPOUND units. If this is a MIXED unit, an error will
* occur. For more information, see UMeasureUnitComplexity.
*
* @param status Set if this is a MIXED unit or if another error occurs.
* NOTE: An Error will be returned for units that have a constant denominator.
*
* @param status Set if this is a MIXED unit, has a constant denominator or if another error occurs.
* @return The reciprocal of the target unit.
* @stable ICU 67
*/
Expand Down Expand Up @@ -627,6 +663,10 @@ class U_I18N_API MeasureUnit: public UObject {
*
* If this is a SINGLE unit, an array of length 1 will be returned.
*
* NOTE: For units with a constant denominator, the returned single units will
* not include the constant denominator. To obtain the constant denominator,
* retrieve it from the original unit.
*
* @param status Set if an error occurs.
* @return A pair with the list of units as a LocalArray and the number of units in the list.
* @stable ICU 68
Expand Down

0 comments on commit 82f5fc1

Please sign in to comment.