]> granicus.if.org Git - icu/commitdiff
ICU-13634 Fixing affix overrides when using CurrencyPluralInfo.
authorShane Carr <shane@unicode.org>
Wed, 11 Apr 2018 23:14:06 +0000 (23:14 +0000)
committerShane Carr <shane@unicode.org>
Wed, 11 Apr 2018 23:14:06 +0000 (23:14 +0000)
X-SVN-Rev: 41217

icu4c/source/i18n/number_decimfmtprops.h
icu4c/source/i18n/number_mapper.cpp
icu4c/source/i18n/number_mapper.h
icu4c/source/i18n/numparse_impl.cpp
icu4j/main/classes/core/src/com/ibm/icu/impl/number/CurrencyPluralInfoAffixProvider.java
icu4j/main/classes/core/src/com/ibm/icu/impl/number/parse/NumberParserImpl.java
icu4j/main/classes/core/src/com/ibm/icu/number/NumberPropertyMapper.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/NumberFormatTest.java

index 6632dfc5a2a6303387007f4360eea872c3797edf..d66a621250ced136d80236a5f9c4ba4bbcf5e9c6 100644 (file)
@@ -132,10 +132,6 @@ struct U_I18N_API DecimalFormatProperties {
 
     DecimalFormatProperties();
 
-    //DecimalFormatProperties(const DecimalFormatProperties &other) = default;
-
-    DecimalFormatProperties& operator=(const DecimalFormatProperties& other) = default;
-
     bool operator==(const DecimalFormatProperties& other) const;
 
     void clear();
index 24a09e6f4b2c8379a809df255c228bfb89370090..51ebb3c08701a9f630059cd78d86b4ed1179baae 100644 (file)
@@ -67,7 +67,7 @@ MacroProps NumberPropertyMapper::oldToNew(const DecimalFormatProperties& propert
         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;
     }
@@ -434,17 +434,23 @@ bool PropertiesAffixPatternProvider::hasBody() const {
 }
 
 
-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);
     }
 }
 
index 5183b1195f64e1fbd02ea34a8249e09e78c74f1d..ef9de18f77efa98d0717ea7591f22c26bfe876b6 100644 (file)
@@ -77,7 +77,8 @@ class CurrencyPluralInfoAffixProvider : public AffixPatternProvider, public UMem
         fBogus = true;
     }
 
-    void setTo(const CurrencyPluralInfo& cpi, UErrorCode& status);
+    void setTo(const CurrencyPluralInfo& cpi, const DecimalFormatProperties& properties,
+               UErrorCode& status);
 
     // AffixPatternProvider Methods:
 
@@ -100,7 +101,7 @@ class CurrencyPluralInfoAffixProvider : public AffixPatternProvider, public UMem
     bool hasBody() const U_OVERRIDE;
 
   private:
-    ParsedPatternInfo affixesByPlural[StandardPlural::COUNT];
+    PropertiesAffixPatternProvider affixesByPlural[StandardPlural::COUNT];
 
     bool fBogus{true};
 };
index 54609151bcd8a042fa0df798713643a2ca33deac..db1586bca48de697c4da3f68203aa10f4c953c2d 100644 (file)
@@ -88,7 +88,7 @@ NumberParserImpl::createParserFromProperties(const number::impl::DecimalFormatPr
         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; }
index 2540899cda7586cf2489ef4754c55c81d2bdd4f5..a3aae565aff1bceb5efcb7c693396d5c7e46f59f 100644 (file)
@@ -3,17 +3,21 @@
 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);
         }
     }
 
index 957a593345209c5350ee8c26492d9f947b419f09..bff15dce37e3d3a9e88e5b592e7931cb8c0d25ab 100644 (file)
@@ -139,7 +139,7 @@ public class NumberParserImpl {
         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;
index b3051bc4f68094c68ec7e41f0366a77f17118be8..0cbdf3c5ef7f60dad8d97eeebc4f2ef7c524a450 100644 (file)
@@ -102,7 +102,7 @@ final class NumberPropertyMapper {
         if (properties.getCurrencyPluralInfo() == null) {
             affixProvider = new PropertiesAffixPatternProvider(properties);
         } else {
-            affixProvider = new CurrencyPluralInfoAffixProvider(properties.getCurrencyPluralInfo());
+            affixProvider = new CurrencyPluralInfoAffixProvider(properties.getCurrencyPluralInfo(), properties);
         }
         macros.affixProvider = affixProvider;
 
index 6a784fdf4c681950754838a245962cf45e8b4bf1..728c538197b305d7144537b48eb3c243419b94a9 100644 (file)
@@ -6027,4 +6027,14 @@ public class NumberFormatTest extends TestFmwk {
         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));
+    }
 }