Skip to content

Commit d7c424b

Browse files
sffcpedberg-icu
authored andcommitted
ICU-22073 Do not throw away CompactDecimalFormat's affixes
1 parent 929cf40 commit d7c424b

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

icu4c/source/i18n/number_formatimpl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,9 @@ NumberFormatterImpl::macrosToMicroGenerator(const MacroProps& macros, bool safe,
353353
}
354354
fPatternModifier.adoptInstead(patternModifier);
355355
const AffixPatternProvider* affixProvider =
356-
macros.affixProvider != nullptr
356+
macros.affixProvider != nullptr && (
357+
// For more information on this condition, see ICU-22073
358+
!isCompactNotation || isCurrency == macros.affixProvider->hasCurrencySign())
357359
? macros.affixProvider
358360
: static_cast<const AffixPatternProvider*>(fPatternInfo.getAlias());
359361
patternModifier->setPatternInfo(affixProvider, kUndefinedField);

icu4c/source/i18n/number_mapper.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,6 @@ MacroProps NumberPropertyMapper::oldToNew(const DecimalFormatProperties& propert
256256
} else {
257257
macros.notation = Notation::compactShort();
258258
}
259-
// Do not forward the affix provider.
260-
macros.affixProvider = nullptr;
261259
}
262260

263261
/////////////////

icu4j/main/classes/core/src/com/ibm/icu/number/NumberFormatterImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,9 @@ private static MicroPropsGenerator macrosToMicroGenerator(MacroProps macros, Mic
363363
// The default middle modifier is weak (thus the false argument).
364364
MutablePatternModifier patternMod = new MutablePatternModifier(false);
365365
AffixPatternProvider affixProvider =
366-
(macros.affixProvider != null)
366+
(macros.affixProvider != null && (
367+
// For more information on this condition, see ICU-22073
368+
!isCompactNotation || isCurrency == macros.affixProvider.hasCurrencySign()))
367369
? macros.affixProvider
368370
: patternInfo;
369371
patternMod.setPatternInfo(affixProvider, null);

icu4j/main/classes/core/src/com/ibm/icu/number/NumberPropertyMapper.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,6 @@ public static MacroProps oldToNew(
301301
} else {
302302
macros.notation = Notation.compactShort();
303303
}
304-
// Do not forward the affix provider.
305-
macros.affixProvider = null;
306304
}
307305

308306
/////////////////

icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/CompactDecimalFormatTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import com.ibm.icu.dev.test.TestFmwk;
3232
import com.ibm.icu.impl.number.DecimalFormatProperties;
33+
import com.ibm.icu.impl.number.PatternStringParser;
3334
import com.ibm.icu.text.CompactDecimalFormat;
3435
import com.ibm.icu.text.CompactDecimalFormat.CompactStyle;
3536
import com.ibm.icu.text.DecimalFormat;
@@ -669,10 +670,12 @@ public void TestCustomData() {
669670
cdf.setProperties(new PropertySetter() {
670671
@Override
671672
public void set(DecimalFormatProperties props) {
673+
PatternStringParser.parseToExistingProperties(
674+
"0 foo", props, PatternStringParser.IGNORE_ROUNDING_ALWAYS);
672675
props.setCompactCustomData(customData);
673676
}
674677
});
675-
assertEquals("Below custom range", "123", cdf.format(123));
678+
assertEquals("Below custom range", "123 foo", cdf.format(123));
676679
assertEquals("Plural form one", "1 qwerty", cdf.format(1000));
677680
assertEquals("Plural form other", "1.2 dvorak", cdf.format(1234));
678681
assertEquals("Above custom range", "12 dvorak", cdf.format(12345));

0 commit comments

Comments
 (0)