ICU-22073 Do not throw away CompactDecimalFormat's affixes
diff --git a/icu4c/source/i18n/number_formatimpl.cpp b/icu4c/source/i18n/number_formatimpl.cpp
index 96e3e9e..4fb190b 100644
--- a/icu4c/source/i18n/number_formatimpl.cpp
+++ b/icu4c/source/i18n/number_formatimpl.cpp
@@ -353,7 +353,9 @@
}
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);
diff --git a/icu4c/source/i18n/number_mapper.cpp b/icu4c/source/i18n/number_mapper.cpp
index 350c431..2f398d4 100644
--- a/icu4c/source/i18n/number_mapper.cpp
+++ b/icu4c/source/i18n/number_mapper.cpp
@@ -256,8 +256,6 @@
} else {
macros.notation = Notation::compactShort();
}
- // Do not forward the affix provider.
- macros.affixProvider = nullptr;
}
/////////////////
diff --git a/icu4j/main/classes/core/src/com/ibm/icu/number/NumberFormatterImpl.java b/icu4j/main/classes/core/src/com/ibm/icu/number/NumberFormatterImpl.java
index 365dfc7..238a64f 100644
--- a/icu4j/main/classes/core/src/com/ibm/icu/number/NumberFormatterImpl.java
+++ b/icu4j/main/classes/core/src/com/ibm/icu/number/NumberFormatterImpl.java
@@ -363,7 +363,9 @@
// 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);
diff --git a/icu4j/main/classes/core/src/com/ibm/icu/number/NumberPropertyMapper.java b/icu4j/main/classes/core/src/com/ibm/icu/number/NumberPropertyMapper.java
index 2ed5f1c..6adbda4 100644
--- a/icu4j/main/classes/core/src/com/ibm/icu/number/NumberPropertyMapper.java
+++ b/icu4j/main/classes/core/src/com/ibm/icu/number/NumberPropertyMapper.java
@@ -301,8 +301,6 @@
} else {
macros.notation = Notation.compactShort();
}
- // Do not forward the affix provider.
- macros.affixProvider = null;
}
/////////////////
diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/CompactDecimalFormatTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/CompactDecimalFormatTest.java
index 6a71404..93712d1 100644
--- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/CompactDecimalFormatTest.java
+++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/CompactDecimalFormatTest.java
@@ -30,6 +30,7 @@
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 @@
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));