]> granicus.if.org Git - icu/commitdiff
ICU-22073 Do not throw away CompactDecimalFormat's affixes cldr/2022-06-27
authorShane F. Carr <shane@unicode.org>
Sat, 25 Jun 2022 01:00:14 +0000 (18:00 -0700)
committerPeter Edberg <42151464+pedberg-icu@users.noreply.github.com>
Mon, 27 Jun 2022 19:53:22 +0000 (12:53 -0700)
icu4c/source/i18n/number_formatimpl.cpp
icu4c/source/i18n/number_mapper.cpp
icu4j/main/classes/core/src/com/ibm/icu/number/NumberFormatterImpl.java
icu4j/main/classes/core/src/com/ibm/icu/number/NumberPropertyMapper.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/CompactDecimalFormatTest.java

index 96e3e9e7c6991020bb39910db78216364481079b..4fb190b744b7c15fa60114b75b6159c3d9e78d6b 100644 (file)
@@ -353,7 +353,9 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe,
     }
     fPatternModifier.adoptInstead(patternModifier);
     const AffixPatternProvider* affixProvider =
-        macros.affixProvider != nullptr
+        macros.affixProvider != nullptr && (
+                // For more information on this condition, see ICU-22073
+                !isCompactNotation || isCurrency == macros.affixProvider->hasCurrencySign())
             ? macros.affixProvider
             : static_cast<const AffixPatternProvider*>(fPatternInfo.getAlias());
     patternModifier->setPatternInfo(affixProvider, kUndefinedField);
index 350c431dfdd0792ab94ac7f8330adcf7d7dd15c8..2f398d4a9392fb4db35f072a233875c38ecfe926 100644 (file)
@@ -256,8 +256,6 @@ MacroProps NumberPropertyMapper::oldToNew(const DecimalFormatProperties& propert
         } else {
             macros.notation = Notation::compactShort();
         }
-        // Do not forward the affix provider.
-        macros.affixProvider = nullptr;
     }
 
     /////////////////
index 365dfc783c2d9886497c40ec0ae689c036f2deb5..238a64f27b1749a8c1fc2b50a6379d2b24f3b3c9 100644 (file)
@@ -363,7 +363,9 @@ class NumberFormatterImpl {
         // The default middle modifier is weak (thus the false argument).
         MutablePatternModifier patternMod = new MutablePatternModifier(false);
         AffixPatternProvider affixProvider =
-            (macros.affixProvider != null)
+            (macros.affixProvider != null && (
+                    // For more information on this condition, see ICU-22073
+                    !isCompactNotation || isCurrency == macros.affixProvider.hasCurrencySign()))
                 ? macros.affixProvider
                 : patternInfo;
         patternMod.setPatternInfo(affixProvider, null);
index 2ed5f1c2bc42ef9d92f333a1a62f4ea5c2bc4e03..6adbda4847d8b74ffac282eaba1366da47e4fbf6 100644 (file)
@@ -301,8 +301,6 @@ final class NumberPropertyMapper {
             } else {
                 macros.notation = Notation.compactShort();
             }
-            // Do not forward the affix provider.
-            macros.affixProvider = null;
         }
 
         /////////////////
index 6a7140488110f42b9e7d21671bc1c7fc82705541..93712d186e53a77d26bea10a40b0f77657e29bb9 100644 (file)
@@ -30,6 +30,7 @@ import org.junit.runners.JUnit4;
 
 import com.ibm.icu.dev.test.TestFmwk;
 import com.ibm.icu.impl.number.DecimalFormatProperties;
+import com.ibm.icu.impl.number.PatternStringParser;
 import com.ibm.icu.text.CompactDecimalFormat;
 import com.ibm.icu.text.CompactDecimalFormat.CompactStyle;
 import com.ibm.icu.text.DecimalFormat;
@@ -669,10 +670,12 @@ public class CompactDecimalFormatTest extends TestFmwk {
         cdf.setProperties(new PropertySetter() {
             @Override
             public void set(DecimalFormatProperties props) {
+                PatternStringParser.parseToExistingProperties(
+                    "0 foo", props, PatternStringParser.IGNORE_ROUNDING_ALWAYS);
                 props.setCompactCustomData(customData);
             }
         });
-        assertEquals("Below custom range", "123", cdf.format(123));
+        assertEquals("Below custom range", "123 foo", cdf.format(123));
         assertEquals("Plural form one", "1 qwerty", cdf.format(1000));
         assertEquals("Plural form other", "1.2 dvorak", cdf.format(1234));
         assertEquals("Above custom range", "12 dvorak", cdf.format(12345));