mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 14:31:31 +00:00
ICU-20920 Changing "Sequence" to "Mixed" in ICU4C MeasureUnit
This commit is contained in:
parent
1084c1430a
commit
b03feb6338
4 changed files with 30 additions and 30 deletions
|
@ -496,19 +496,19 @@ private:
|
|||
}
|
||||
bool added = result.append(singleUnit, status);
|
||||
if (sawPlus && !added) {
|
||||
// Two similar units are not allowed in a sequence unit
|
||||
// Two similar units are not allowed in a mixed unit
|
||||
status = kUnitIdentifierSyntaxError;
|
||||
return;
|
||||
}
|
||||
if ((++unitNum) >= 2) {
|
||||
UMeasureUnitComplexity complexity = sawPlus
|
||||
? UMEASURE_UNIT_SEQUENCE
|
||||
? UMEASURE_UNIT_MIXED
|
||||
: UMEASURE_UNIT_COMPOUND;
|
||||
if (unitNum == 2) {
|
||||
U_ASSERT(result.complexity == UMEASURE_UNIT_SINGLE);
|
||||
result.complexity = complexity;
|
||||
} else if (result.complexity != complexity) {
|
||||
// Mixed sequence and compound units
|
||||
// Can't have mixed compound units
|
||||
status = kUnitIdentifierSyntaxError;
|
||||
return;
|
||||
}
|
||||
|
@ -589,7 +589,7 @@ void serialize(MeasureUnitImpl& impl, UErrorCode& status) {
|
|||
return;
|
||||
}
|
||||
if (impl.complexity == UMEASURE_UNIT_COMPOUND) {
|
||||
// Note: don't sort a SEQUENCE unit
|
||||
// Note: don't sort a MIXED unit
|
||||
uprv_sortArray(
|
||||
impl.units.getAlias(),
|
||||
impl.units.length(),
|
||||
|
@ -609,7 +609,7 @@ void serialize(MeasureUnitImpl& impl, UErrorCode& status) {
|
|||
for (int32_t i = 1; i < impl.units.length(); i++) {
|
||||
const SingleUnitImpl& prev = *impl.units[i-1];
|
||||
const SingleUnitImpl& curr = *impl.units[i];
|
||||
if (impl.complexity == UMEASURE_UNIT_SEQUENCE) {
|
||||
if (impl.complexity == UMEASURE_UNIT_MIXED) {
|
||||
impl.identifier.append("-and-", status);
|
||||
serializeSingle(curr, true, impl.identifier, status);
|
||||
} else {
|
||||
|
@ -753,7 +753,7 @@ MeasureUnit MeasureUnit::product(const MeasureUnit& other, UErrorCode& status) c
|
|||
MeasureUnitImpl impl = MeasureUnitImpl::forMeasureUnitMaybeCopy(*this, status);
|
||||
MeasureUnitImpl temp;
|
||||
const MeasureUnitImpl& otherImpl = MeasureUnitImpl::forMeasureUnit(other, temp, status);
|
||||
if (impl.complexity == UMEASURE_UNIT_SEQUENCE || otherImpl.complexity == UMEASURE_UNIT_SEQUENCE) {
|
||||
if (impl.complexity == UMEASURE_UNIT_MIXED || otherImpl.complexity == UMEASURE_UNIT_MIXED) {
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ struct SingleUnitImpl : public UMemory {
|
|||
|
||||
/**
|
||||
* Internal representation of measurement units. Capable of representing all complexities of units,
|
||||
* including sequence and compound units.
|
||||
* including mixed and compound units.
|
||||
*/
|
||||
struct MeasureUnitImpl : public UMemory {
|
||||
/** Extract the MeasureUnitImpl from a MeasureUnit. */
|
||||
|
@ -151,7 +151,7 @@ struct MeasureUnitImpl : public UMemory {
|
|||
/** Mutates this MeasureUnitImpl to append a single unit. */
|
||||
bool append(const SingleUnitImpl& singleUnit, UErrorCode& status);
|
||||
|
||||
/** The complexity, either SINGLE, COMPOUND, or SEQUENCE. */
|
||||
/** The complexity, either SINGLE, COMPOUND, or MIXED. */
|
||||
UMeasureUnitComplexity complexity = UMEASURE_UNIT_SINGLE;
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,8 +40,8 @@ struct MeasureUnitImpl;
|
|||
* square-kilometer, kilojoule, one-per-second.
|
||||
* - COMPOUND: A unit composed of the product of multiple single units. Examples:
|
||||
* meter-per-second, kilowatt-hour, kilogram-meter-per-square-second.
|
||||
* - SEQUENCE: A unit composed of the sum of multiple single units. Examples: foot+inch,
|
||||
* hour+minute+second, degree+arcminute+arcsecond.
|
||||
* - MIXED: A unit composed of the sum of multiple single units. Examples: foot+inch,
|
||||
* hour+minute+second, degree+arcminute+arcsecond.
|
||||
*
|
||||
* The complexity determines which operations are available. For example, you cannot set the power
|
||||
* or SI prefix of a compound unit.
|
||||
|
@ -64,11 +64,11 @@ enum UMeasureUnitComplexity {
|
|||
UMEASURE_UNIT_COMPOUND,
|
||||
|
||||
/**
|
||||
* A sequence unit, like hour+minute.
|
||||
* A mixed unit, like hour+minute.
|
||||
*
|
||||
* @draft ICU 67
|
||||
*/
|
||||
UMEASURE_UNIT_SEQUENCE
|
||||
UMEASURE_UNIT_MIXED
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -258,14 +258,14 @@ class U_I18N_API MeasureUnit: public UObject {
|
|||
MeasureUnit(MeasureUnit &&other) noexcept;
|
||||
|
||||
/**
|
||||
* Construct a MeasureUnit from a CLDR Sequence Unit Identifier, defined in UTS 35.
|
||||
* Construct a MeasureUnit from a CLDR Unit Identifier, defined in UTS 35.
|
||||
* Validates and canonicalizes the identifier.
|
||||
*
|
||||
* <pre>
|
||||
* MeasureUnit example = MeasureUnit::forIdentifier("furlong-per-nanosecond")
|
||||
* </pre>
|
||||
*
|
||||
* @param identifier The CLDR Sequence Unit Identifier
|
||||
* @param identifier The CLDR Unit Identifier
|
||||
* @param status Set if the identifier is invalid.
|
||||
* @draft ICU 67
|
||||
*/
|
||||
|
@ -335,7 +335,7 @@ class U_I18N_API MeasureUnit: public UObject {
|
|||
|
||||
#ifndef U_HIDE_DRAFT_API
|
||||
/**
|
||||
* Get the CLDR Sequence Unit Identifier for this MeasureUnit, as defined in UTS 35.
|
||||
* Get the CLDR Unit Identifier for this MeasureUnit, as defined in UTS 35.
|
||||
*
|
||||
* @return The string form of this unit, owned by this MeasureUnit.
|
||||
* @draft ICU 67
|
||||
|
@ -357,7 +357,7 @@ class U_I18N_API MeasureUnit: public UObject {
|
|||
*
|
||||
* There is sufficient locale data to format all standard SI prefixes.
|
||||
*
|
||||
* NOTE: Only works on SINGLE units. If this is a COMPOUND or SEQUENCE unit, an error will
|
||||
* NOTE: Only works on SINGLE units. If this is a COMPOUND or MIXED unit, an error will
|
||||
* occur. For more information, see UMeasureUnitComplexity.
|
||||
*
|
||||
* @param prefix The SI prefix, from UMeasureSIPrefix.
|
||||
|
@ -371,7 +371,7 @@ class U_I18N_API MeasureUnit: public UObject {
|
|||
* Gets the current SI prefix of this SINGLE unit. For example, if the unit has the SI prefix
|
||||
* "kilo", then UMEASURE_SI_PREFIX_KILO is returned.
|
||||
*
|
||||
* NOTE: Only works on SINGLE units. If this is a COMPOUND or SEQUENCE unit, an error will
|
||||
* NOTE: Only works on SINGLE units. If this is a COMPOUND or MIXED unit, an error will
|
||||
* occur. For more information, see UMeasureUnitComplexity.
|
||||
*
|
||||
* @param status Set if this is not a SINGLE unit or if another error occurs.
|
||||
|
@ -384,7 +384,7 @@ class U_I18N_API MeasureUnit: public UObject {
|
|||
* 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.
|
||||
*
|
||||
* NOTE: Only works on SINGLE units. If this is a COMPOUND or SEQUENCE unit, an error will
|
||||
* NOTE: Only works on SINGLE units. If this is a COMPOUND or MIXED unit, an error will
|
||||
* occur. For more information, see UMeasureUnitComplexity.
|
||||
*
|
||||
* @param dimensionality The dimensionality (power).
|
||||
|
@ -398,7 +398,7 @@ class U_I18N_API MeasureUnit: public UObject {
|
|||
* Gets the dimensionality (power) of this MeasureUnit. For example, if the unit is square,
|
||||
* then 2 is returned.
|
||||
*
|
||||
* NOTE: Only works on SINGLE units. If this is a COMPOUND or SEQUENCE unit, an error will
|
||||
* NOTE: Only works on SINGLE units. If this is a COMPOUND or MIXED unit, an error will
|
||||
* occur. For more information, see UMeasureUnitComplexity.
|
||||
*
|
||||
* @param status Set if this is not a SINGLE unit or if another error occurs.
|
||||
|
@ -412,10 +412,10 @@ class U_I18N_API MeasureUnit: public UObject {
|
|||
*
|
||||
* For example, if the receiver is "meter-per-second", the unit "second-per-meter" is returned.
|
||||
*
|
||||
* NOTE: Only works on SINGLE and COMPOUND units. If this is a SEQUENCE unit, an error will
|
||||
* 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 SEQUENCE unit or if another error occurs.
|
||||
* @param status Set if this is a MIXED unit or if another error occurs.
|
||||
* @return The reciprocal of the target unit.
|
||||
* @draft ICU 67
|
||||
*/
|
||||
|
@ -431,10 +431,10 @@ class U_I18N_API MeasureUnit: public UObject {
|
|||
* unit "kilowatt-hour-per-day" is returned.
|
||||
*
|
||||
* NOTE: Only works on SINGLE and COMPOUND units. If either unit (receivee and argument) is a
|
||||
* SEQUENCE unit, an error will occur. For more information, see UMeasureUnitComplexity.
|
||||
* MIXED unit, an error will occur. For more information, see UMeasureUnitComplexity.
|
||||
*
|
||||
* @param other The MeasureUnit to multiply with the target.
|
||||
* @param status Set if this or other is a SEQUENCE unit or if another error occurs.
|
||||
* @param status Set if this or other is a MIXED unit or if another error occurs.
|
||||
* @return The product of the target unit with the provided unit.
|
||||
* @draft ICU 67
|
||||
*/
|
||||
|
@ -443,7 +443,7 @@ class U_I18N_API MeasureUnit: public UObject {
|
|||
|
||||
#ifndef U_HIDE_INTERNAL_API
|
||||
/**
|
||||
* Gets the list of SINGLE units contained within a SEQUENCE of COMPOUND unit.
|
||||
* Gets the list of SINGLE units contained within a MIXED of COMPOUND unit.
|
||||
*
|
||||
* Examples:
|
||||
* - Given "meter-kilogram-per-second", three units will be returned: "meter",
|
||||
|
|
|
@ -152,7 +152,7 @@ private:
|
|||
const char* identifier,
|
||||
const char** subIdentifiers,
|
||||
int32_t subIdentifierCount);
|
||||
void verifySequenceUnit(
|
||||
void verifyMixedUnit(
|
||||
const MeasureUnit& unit,
|
||||
const char* identifier,
|
||||
const char** subIdentifiers,
|
||||
|
@ -3368,10 +3368,10 @@ void MeasureFormatTest::TestCompoundUnitOperations() {
|
|||
MeasureUnit inchFoot = MeasureUnit::forIdentifier("inch-and-foot", status);
|
||||
|
||||
const char* footInchSub[] = {"foot", "inch"};
|
||||
verifySequenceUnit(footInch, "foot-and-inch",
|
||||
verifyMixedUnit(footInch, "foot-and-inch",
|
||||
footInchSub, UPRV_LENGTHOF(footInchSub));
|
||||
const char* inchFootSub[] = {"inch", "foot"};
|
||||
verifySequenceUnit(inchFoot, "inch-and-foot",
|
||||
verifyMixedUnit(inchFoot, "inch-and-foot",
|
||||
inchFootSub, UPRV_LENGTHOF(inchFootSub));
|
||||
|
||||
assertTrue("order matters inequality", footInch != inchFoot);
|
||||
|
@ -3575,12 +3575,12 @@ void MeasureFormatTest::verifyCompoundUnit(
|
|||
}
|
||||
}
|
||||
|
||||
void MeasureFormatTest::verifySequenceUnit(
|
||||
void MeasureFormatTest::verifyMixedUnit(
|
||||
const MeasureUnit& unit,
|
||||
const char* identifier,
|
||||
const char** subIdentifiers,
|
||||
int32_t subIdentifierCount) {
|
||||
IcuTestErrorCode status(*this, "verifySequenceUnit");
|
||||
IcuTestErrorCode status(*this, "verifyMixedUnit");
|
||||
UnicodeString uid(identifier, -1, US_INV);
|
||||
assertEquals(uid + ": Identifier",
|
||||
identifier,
|
||||
|
@ -3590,7 +3590,7 @@ void MeasureFormatTest::verifySequenceUnit(
|
|||
unit == MeasureUnit::forIdentifier(identifier, status));
|
||||
status.errIfFailureAndReset("%s: Constructor", identifier);
|
||||
assertEquals(uid + ": Complexity",
|
||||
UMEASURE_UNIT_SEQUENCE,
|
||||
UMEASURE_UNIT_MIXED,
|
||||
unit.getComplexity(status));
|
||||
status.errIfFailureAndReset("%s: Complexity", identifier);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue