ICU-13415 Refactoring shadowed virtual method in IFixedDecimal.

X-SVN-Rev: 40626
This commit is contained in:
Shane Carr 2017-10-23 07:12:39 +00:00
parent a5e9be8dd6
commit de3c990b0b
2 changed files with 27 additions and 20 deletions

View File

@ -789,7 +789,9 @@ AndConstraint::isFulfilled(const IFixedDecimal &number) {
// An empty AndConstraint, created by a rule with a keyword but no following expression.
return TRUE;
}
double n = number.getPluralOperand(digitsType); // pulls n | i | v | f value for the number.
PluralOperand operand = tokenTypeToPluralOperand(digitsType);
double n = number.getPluralOperand(operand); // pulls n | i | v | f value for the number.
// Will always be positive.
// May be non-integer (n option only)
do {
@ -1405,6 +1407,24 @@ PluralKeywordEnumeration::count(UErrorCode& /*status*/) const {
PluralKeywordEnumeration::~PluralKeywordEnumeration() {
}
PluralOperand tokenTypeToPluralOperand(tokenType tt) {
switch(tt) {
case tVariableN:
return PLURAL_OPERAND_N;
case tVariableI:
return PLURAL_OPERAND_I;
case tVariableF:
return PLURAL_OPERAND_F;
case tVariableV:
return PLURAL_OPERAND_V;
case tVariableT:
return PLURAL_OPERAND_T;
default:
U_ASSERT(FALSE); // unexpected.
return PLURAL_OPERAND_N;
}
}
IFixedDecimal::~IFixedDecimal() = default;
FixedDecimal::FixedDecimal(const VisibleDigits &digits) {

View File

@ -221,6 +221,12 @@ enum PluralOperand {
PLURAL_OPERAND_J
};
/**
* Converts from the tokenType enum to PluralOperand. Asserts that the given
* tokenType can be mapped to a PluralOperand.
*/
PluralOperand tokenTypeToPluralOperand(tokenType tt);
/**
* An interface to FixedDecimal, allowing for other implementations.
* @internal
@ -235,25 +241,6 @@ class U_I18N_API IFixedDecimal {
*/
virtual double getPluralOperand(PluralOperand operand) const = 0;
/** Converts from the tokenType enum to PluralOperand. */
virtual double getPluralOperand(tokenType tt) const {
switch(tt) {
case tVariableN:
return getPluralOperand(PLURAL_OPERAND_N);
case tVariableI:
return getPluralOperand(PLURAL_OPERAND_I);
case tVariableF:
return getPluralOperand(PLURAL_OPERAND_F);
case tVariableV:
return getPluralOperand(PLURAL_OPERAND_V);
case tVariableT:
return getPluralOperand(PLURAL_OPERAND_T);
default:
U_ASSERT(FALSE); // unexpected.
return 0.0;
}
}
virtual bool isNaN() const = 0;
virtual bool isInfinite() const = 0;