Skip to content

Commit

Permalink
ICU-22073 Do not throw away CompactDecimalFormat's affixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc authored and pedberg-icu committed Jun 27, 2022
1 parent 929cf40 commit d7c424b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
4 changes: 3 additions & 1 deletion icu4c/source/i18n/number_formatimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions icu4c/source/i18n/number_mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,6 @@ MacroProps NumberPropertyMapper::oldToNew(const DecimalFormatProperties& propert
} else {
macros.notation = Notation::compactShort();
}
// Do not forward the affix provider.
macros.affixProvider = nullptr;
}

/////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,9 @@ private static MicroPropsGenerator macrosToMicroGenerator(MacroProps macros, Mic
// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,6 @@ public static MacroProps oldToNew(
} else {
macros.notation = Notation.compactShort();
}
// Do not forward the affix provider.
macros.affixProvider = null;
}

/////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -669,10 +670,12 @@ public void TestCustomData() {
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));
Expand Down

0 comments on commit d7c424b

Please sign in to comment.