DecimalFormatProperties();
- //DecimalFormatProperties(const DecimalFormatProperties &other) = default;
-
- DecimalFormatProperties& operator=(const DecimalFormatProperties& other) = default;
-
bool operator==(const DecimalFormatProperties& other) const;
void clear();
warehouse.propertiesAPP.setTo(properties, status);
affixProvider = &warehouse.propertiesAPP;
} else {
- warehouse.currencyPluralInfoAPP.setTo(*properties.currencyPluralInfo.fPtr, status);
+ warehouse.currencyPluralInfoAPP.setTo(*properties.currencyPluralInfo.fPtr, properties, status);
warehouse.propertiesAPP.setToBogus();
affixProvider = &warehouse.currencyPluralInfoAPP;
}
}
-void CurrencyPluralInfoAffixProvider::setTo(const CurrencyPluralInfo& cpi, UErrorCode& status) {
+void CurrencyPluralInfoAffixProvider::setTo(const CurrencyPluralInfo& cpi,
+ const DecimalFormatProperties& properties,
+ UErrorCode& status) {
+ // We need to use a PropertiesAffixPatternProvider, not the simpler version ParsedPatternInfo,
+ // because user-specified affix overrides still need to work.
fBogus = false;
+ DecimalFormatProperties pluralProperties(properties);
for (int32_t plural = 0; plural < StandardPlural::COUNT; plural++) {
const char* keyword = StandardPlural::getKeyword(static_cast<StandardPlural::Form>(plural));
UnicodeString patternString;
patternString = cpi.getCurrencyPluralPattern(keyword, patternString);
- // ParsedPatternInfo does not support being overwritten if it was written previously;
- // instead, we need to write to a fresh instance and move it into place.
- ParsedPatternInfo temp;
- PatternParser::parseToPatternInfo(patternString, temp, status);
- affixesByPlural[plural] = std::move(temp);
+ PatternParser::parseToExistingProperties(
+ patternString,
+ pluralProperties,
+ IGNORE_ROUNDING_NEVER,
+ status);
+ affixesByPlural[plural].setTo(pluralProperties, status);
}
}
fBogus = true;
}
- void setTo(const CurrencyPluralInfo& cpi, UErrorCode& status);
+ void setTo(const CurrencyPluralInfo& cpi, const DecimalFormatProperties& properties,
+ UErrorCode& status);
// AffixPatternProvider Methods:
bool hasBody() const U_OVERRIDE;
private:
- ParsedPatternInfo affixesByPlural[StandardPlural::COUNT];
+ PropertiesAffixPatternProvider affixesByPlural[StandardPlural::COUNT];
bool fBogus{true};
};
localPAPP.setTo(properties, status);
affixProvider = &localPAPP;
} else {
- localCPIAP.setTo(*properties.currencyPluralInfo.fPtr, status);
+ localCPIAP.setTo(*properties.currencyPluralInfo.fPtr, properties, status);
affixProvider = &localCPIAP;
}
if (affixProvider == nullptr || U_FAILURE(status)) { return nullptr; }
package com.ibm.icu.impl.number;
import com.ibm.icu.impl.StandardPlural;
-import com.ibm.icu.impl.number.PatternStringParser.ParsedPatternInfo;
import com.ibm.icu.text.CurrencyPluralInfo;
public class CurrencyPluralInfoAffixProvider implements AffixPatternProvider {
- private final AffixPatternProvider[] affixesByPlural;
+ private final PropertiesAffixPatternProvider[] affixesByPlural;
- public CurrencyPluralInfoAffixProvider(CurrencyPluralInfo cpi) {
- affixesByPlural = new ParsedPatternInfo[StandardPlural.COUNT];
+ public CurrencyPluralInfoAffixProvider(CurrencyPluralInfo cpi, DecimalFormatProperties properties) {
+ // We need to use a PropertiesAffixPatternProvider, not the simpler version ParsedPatternInfo,
+ // because user-specified affix overrides still need to work.
+ affixesByPlural = new PropertiesAffixPatternProvider[StandardPlural.COUNT];
+ DecimalFormatProperties pluralProperties = new DecimalFormatProperties();
+ pluralProperties.copyFrom(properties);
for (StandardPlural plural : StandardPlural.VALUES) {
- affixesByPlural[plural.ordinal()] = PatternStringParser
- .parseToPatternInfo(cpi.getCurrencyPluralPattern(plural.getKeyword()));
+ String pattern = cpi.getCurrencyPluralPattern(plural.getKeyword());
+ PatternStringParser.parseToExistingProperties(pattern, pluralProperties);
+ affixesByPlural[plural.ordinal()] = new PropertiesAffixPatternProvider(pluralProperties);
}
}
if (properties.getCurrencyPluralInfo() == null) {
affixProvider = new PropertiesAffixPatternProvider(properties);
} else {
- affixProvider = new CurrencyPluralInfoAffixProvider(properties.getCurrencyPluralInfo());
+ affixProvider = new CurrencyPluralInfoAffixProvider(properties.getCurrencyPluralInfo(), properties);
}
Currency currency = CustomSymbolCurrency.resolve(properties.getCurrency(), locale, symbols);
boolean isStrict = properties.getParseMode() == ParseMode.STRICT;
if (properties.getCurrencyPluralInfo() == null) {
affixProvider = new PropertiesAffixPatternProvider(properties);
} else {
- affixProvider = new CurrencyPluralInfoAffixProvider(properties.getCurrencyPluralInfo());
+ affixProvider = new CurrencyPluralInfoAffixProvider(properties.getCurrencyPluralInfo(), properties);
}
macros.affixProvider = affixProvider;
assertEquals("Should fail to parse", 0, ppos.getIndex());
assertEquals("Should fail to parse", 0, ppos.getErrorIndex());
}
+
+ @Test
+ public void testCurrencyPluralAffixOverrides() {
+ // The affix setters should override CurrencyPluralInfo, used in the plural currency constructor.
+ DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(ULocale.ENGLISH, NumberFormat.PLURALCURRENCYSTYLE);
+ df.setCurrency(Currency.getInstance("USD"));
+ df.setPositiveSuffix("lala");
+ assertEquals("Custom suffix should round-trip", "lala", df.getPositiveSuffix());
+ assertEquals("Custom suffix should be used in formatting", "123.00lala", df.format(123));
+ }
}