-void MutablePatternModifier::setPatternInfo(const AffixPatternProvider* patternInfo) {
- this->patternInfo = patternInfo;
+void MutablePatternModifier::setPatternInfo(const AffixPatternProvider* patternInfo, Field field) {
+ fPatternInfo = patternInfo;
+ fField = field;
}
void MutablePatternModifier::setSymbols(const DecimalFormatSymbols* symbols,
const CurrencySymbols* currencySymbols,
const UNumberUnitWidth unitWidth, const PluralRules* rules) {
U_ASSERT((rules != nullptr) == needsPlurals());
}
void MutablePatternModifier::setSymbols(const DecimalFormatSymbols* symbols,
const CurrencySymbols* currencySymbols,
const UNumberUnitWidth unitWidth, const PluralRules* rules) {
U_ASSERT((rules != nullptr) == needsPlurals());
- this->symbols = symbols;
- this->currencySymbols = currencySymbols;
- this->unitWidth = unitWidth;
- this->rules = rules;
+ fSymbols = symbols;
+ fCurrencySymbols = currencySymbols;
+ fUnitWidth = unitWidth;
+ fRules = rules;
StandardPlural::Form::MANY,
StandardPlural::Form::OTHER};
StandardPlural::Form::MANY,
StandardPlural::Form::OTHER};
// Slower path when we require the plural keyword.
for (StandardPlural::Form plural : STANDARD_PLURAL_VALUES) {
setNumberProperties(1, plural);
// Slower path when we require the plural keyword.
for (StandardPlural::Form plural : STANDARD_PLURAL_VALUES) {
setNumberProperties(1, plural);
} else {
// Faster path when plural keyword is not needed.
setNumberProperties(1, StandardPlural::Form::COUNT);
} else {
// Faster path when plural keyword is not needed.
setNumberProperties(1, StandardPlural::Form::COUNT);
- Modifier* negative = createConstantModifier(status);
- pm->adoptPositiveNegativeModifiers(positive, zero, negative);
+ pm->adoptModifierWithoutPlural(-1, createConstantModifier(status));
NumberStringBuilder b;
insertPrefix(a, 0, status);
insertSuffix(b, 0, status);
NumberStringBuilder b;
insertPrefix(a, 0, status);
insertSuffix(b, 0, status);
- a, b, !patternInfo->hasBody(), fStrong, *symbols, status);
+ a, b, !fPatternInfo->hasBody(), fStrong, *fSymbols, status);
- return new ConstantMultiFieldModifier(a, b, !patternInfo->hasBody(), fStrong);
+ return new ConstantMultiFieldModifier(a, b, !fPatternInfo->hasBody(), fStrong);
-ImmutablePatternModifier::ImmutablePatternModifier(ParameterizedModifier* pm, const PluralRules* rules,
+ImmutablePatternModifier::ImmutablePatternModifier(AdoptingModifierStore* pm, const PluralRules* rules,
const MicroPropsGenerator* parent)
: pm(pm), rules(rules), parent(parent) {}
void ImmutablePatternModifier::processQuantity(DecimalQuantity& quantity, MicroProps& micros,
UErrorCode& status) const {
parent->processQuantity(quantity, micros, status);
const MicroPropsGenerator* parent)
: pm(pm), rules(rules), parent(parent) {}
void ImmutablePatternModifier::processQuantity(DecimalQuantity& quantity, MicroProps& micros,
UErrorCode& status) const {
parent->processQuantity(quantity, micros, status);
-void ImmutablePatternModifier::applyToMicros(MicroProps& micros, DecimalQuantity& quantity) const {
+void ImmutablePatternModifier::applyToMicros(
+ MicroProps& micros, const DecimalQuantity& quantity, UErrorCode& status) const {
- // TODO: Fix this. Avoid the copy.
- DecimalQuantity copy(quantity);
- copy.roundToInfinity();
- StandardPlural::Form plural = utils::getStandardPlural(rules, copy);
- micros.modMiddle = pm->getModifier(quantity.signum(), plural);
+ StandardPlural::Form pluralForm = utils::getPluralSafe(micros.rounder, rules, quantity, status);
+ micros.modMiddle = pm->getModifier(quantity.signum(), pluralForm);
/** Used by the unsafe code path. */
MicroPropsGenerator& MutablePatternModifier::addToChain(const MicroPropsGenerator* parent) {
/** Used by the unsafe code path. */
MicroPropsGenerator& MutablePatternModifier::addToChain(const MicroPropsGenerator* parent) {
return *this;
}
void MutablePatternModifier::processQuantity(DecimalQuantity& fq, MicroProps& micros,
UErrorCode& status) const {
return *this;
}
void MutablePatternModifier::processQuantity(DecimalQuantity& fq, MicroProps& micros,
UErrorCode& status) const {
// The unsafe code path performs self-mutation, so we need a const_cast.
// This method needs to be const because it overrides a const method in the parent class.
auto nonConstThis = const_cast<MutablePatternModifier*>(this);
if (needsPlurals()) {
// The unsafe code path performs self-mutation, so we need a const_cast.
// This method needs to be const because it overrides a const method in the parent class.
auto nonConstThis = const_cast<MutablePatternModifier*>(this);
if (needsPlurals()) {
- // TODO: Fix this. Avoid the copy.
- DecimalQuantity copy(fq);
- micros.rounder.apply(copy, status);
- nonConstThis->setNumberProperties(fq.signum(), utils::getStandardPlural(rules, copy));
+ StandardPlural::Form pluralForm = utils::getPluralSafe(micros.rounder, fRules, fq, status);
+ nonConstThis->setNumberProperties(fq.signum(), pluralForm);
int32_t suffixLen = nonConstThis->insertSuffix(output, rightIndex + prefixLen, status);
// If the pattern had no decimal stem body (like #,##0.00), overwrite the value.
int32_t overwriteLen = 0;
int32_t suffixLen = nonConstThis->insertSuffix(output, rightIndex + prefixLen, status);
// If the pattern had no decimal stem body (like #,##0.00), overwrite the value.
int32_t overwriteLen = 0;
// The unsafe code path performs self-mutation, so we need a const_cast.
// This method needs to be const because it overrides a const method in the parent class.
auto nonConstThis = const_cast<MutablePatternModifier*>(this);
// Enter and exit CharSequence Mode to get the length.
// The unsafe code path performs self-mutation, so we need a const_cast.
// This method needs to be const because it overrides a const method in the parent class.
auto nonConstThis = const_cast<MutablePatternModifier*>(this);
// Enter and exit CharSequence Mode to get the length.
nonConstThis->prepareAffix(true);
int result = AffixUtils::unescapedCodePointCount(currentAffix, *this, status); // prefix length
return result;
}
nonConstThis->prepareAffix(true);
int result = AffixUtils::unescapedCodePointCount(currentAffix, *this, status); // prefix length
return result;
}
// The unsafe code path performs self-mutation, so we need a const_cast.
// This method needs to be const because it overrides a const method in the parent class.
auto nonConstThis = const_cast<MutablePatternModifier*>(this);
// Render the affixes to get the length
// The unsafe code path performs self-mutation, so we need a const_cast.
// This method needs to be const because it overrides a const method in the parent class.
auto nonConstThis = const_cast<MutablePatternModifier*>(this);
// Render the affixes to get the length
nonConstThis->prepareAffix(true);
int result = AffixUtils::unescapedCodePointCount(currentAffix, *this, status); // prefix length
nonConstThis->prepareAffix(false);
nonConstThis->prepareAffix(true);
int result = AffixUtils::unescapedCodePointCount(currentAffix, *this, status); // prefix length
nonConstThis->prepareAffix(false);
+bool MutablePatternModifier::containsField(UNumberFormatFields field) const {
+ (void)field;
+ // This method is not currently used.
+ UPRV_UNREACHABLE;
+}
+
+void MutablePatternModifier::getParameters(Parameters& output) const {
+ (void)output;
+ // This method is not currently used.
+ UPRV_UNREACHABLE;
+}
+
+bool MutablePatternModifier::semanticallyEquivalent(const Modifier& other) const {
+ (void)other;
+ // This method is not currently used.
+ UPRV_UNREACHABLE;
+}
+
int32_t MutablePatternModifier::insertPrefix(NumberStringBuilder& sb, int position, UErrorCode& status) {
prepareAffix(true);
int32_t MutablePatternModifier::insertPrefix(NumberStringBuilder& sb, int position, UErrorCode& status) {
prepareAffix(true);
- int length = AffixUtils::unescape(currentAffix, sb, position, *this, status);
+ int32_t length = AffixUtils::unescape(currentAffix, sb, position, *this, fField, status);
return length;
}
int32_t MutablePatternModifier::insertSuffix(NumberStringBuilder& sb, int position, UErrorCode& status) {
prepareAffix(false);
return length;
}
int32_t MutablePatternModifier::insertSuffix(NumberStringBuilder& sb, int position, UErrorCode& status) {
prepareAffix(false);
- int length = AffixUtils::unescape(currentAffix, sb, position, *this, status);
+ int32_t length = AffixUtils::unescape(currentAffix, sb, position, *this, fField, status);
return length;
}
/** This method contains the heart of the logic for rendering LDML affix strings. */
void MutablePatternModifier::prepareAffix(bool isPrefix) {
PatternStringUtils::patternInfoToStringBuilder(
return length;
}
/** This method contains the heart of the logic for rendering LDML affix strings. */
void MutablePatternModifier::prepareAffix(bool isPrefix) {
PatternStringUtils::patternInfoToStringBuilder(
- *patternInfo, isPrefix, signum, signDisplay, plural, perMilleReplacesPercent, currentAffix);
+ *fPatternInfo, isPrefix, fSignum, fSignDisplay, fPlural, fPerMilleReplacesPercent, currentAffix);
}
UnicodeString MutablePatternModifier::getSymbol(AffixPatternType type) const {
UErrorCode localStatus = U_ZERO_ERROR;
switch (type) {
case AffixPatternType::TYPE_MINUS_SIGN:
}
UnicodeString MutablePatternModifier::getSymbol(AffixPatternType type) const {
UErrorCode localStatus = U_ZERO_ERROR;
switch (type) {
case AffixPatternType::TYPE_MINUS_SIGN:
case AffixPatternType::TYPE_CURRENCY_SINGLE: {
// UnitWidth ISO and HIDDEN overrides the singular currency symbol.
case AffixPatternType::TYPE_CURRENCY_SINGLE: {
// UnitWidth ISO and HIDDEN overrides the singular currency symbol.
- if (unitWidth == UNumberUnitWidth::UNUM_UNIT_WIDTH_ISO_CODE) {
- return currencySymbols->getIntlCurrencySymbol(localStatus);
- } else if (unitWidth == UNumberUnitWidth::UNUM_UNIT_WIDTH_HIDDEN) {
+ if (fUnitWidth == UNumberUnitWidth::UNUM_UNIT_WIDTH_ISO_CODE) {
+ return fCurrencySymbols->getIntlCurrencySymbol(localStatus);
+ } else if (fUnitWidth == UNumberUnitWidth::UNUM_UNIT_WIDTH_HIDDEN) {
- } else if (unitWidth == UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW) {
- return currencySymbols->getNarrowCurrencySymbol(localStatus);
+ } else if (fUnitWidth == UNumberUnitWidth::UNUM_UNIT_WIDTH_NARROW) {
+ return fCurrencySymbols->getNarrowCurrencySymbol(localStatus);
case AffixPatternType::TYPE_CURRENCY_TRIPLE:
// NOTE: This is the code path only for patterns containing "¤¤¤".
// Plural currencies set via the API are formatted in LongNameHandler.
// This code path is used by DecimalFormat via CurrencyPluralInfo.
case AffixPatternType::TYPE_CURRENCY_TRIPLE:
// NOTE: This is the code path only for patterns containing "¤¤¤".
// Plural currencies set via the API are formatted in LongNameHandler.
// This code path is used by DecimalFormat via CurrencyPluralInfo.
- U_ASSERT(plural != StandardPlural::Form::COUNT);
- return currencySymbols->getPluralName(plural, localStatus);
+ U_ASSERT(fPlural != StandardPlural::Form::COUNT);
+ return fCurrencySymbols->getPluralName(fPlural, localStatus);
case AffixPatternType::TYPE_CURRENCY_QUAD:
return UnicodeString(u"\uFFFD");
case AffixPatternType::TYPE_CURRENCY_QUINT:
return UnicodeString(u"\uFFFD");
default:
case AffixPatternType::TYPE_CURRENCY_QUAD:
return UnicodeString(u"\uFFFD");
case AffixPatternType::TYPE_CURRENCY_QUINT:
return UnicodeString(u"\uFFFD");
default: