Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions icu4c/source/i18n/number_patternmodifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,15 @@ int32_t MutablePatternModifier::apply(FormattedStringBuilder& output, int32_t le
kUndefinedField,
status);
}
CurrencySpacingEnabledModifier::applyCurrencySpacing(
int32_t spacingLen = CurrencySpacingEnabledModifier::applyCurrencySpacing(
output,
leftIndex,
prefixLen,
rightIndex + overwriteLen + prefixLen,
suffixLen,
*fSymbols,
status);
return prefixLen + overwriteLen + suffixLen;
return prefixLen + overwriteLen + suffixLen + spacingLen;
}

int32_t MutablePatternModifier::getPrefixLength() const {
Expand Down
23 changes: 23 additions & 0 deletions icu4c/source/test/intltest/numbertest_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4277,6 +4277,29 @@ void NumberFormatterApiTest::padding() {
Locale::getEnglish(),
514.23,
u"GBP 000514.23"); // TODO: This is broken; it renders too wide (13 instead of 12).

// Both tests render 16 wide because currency spacing is not counted in padding width.
assertFormatSingle(
u"Prefix Currency Spacing with Pad After Suffix (ICU-23645)",
nullptr,
nullptr,
NumberFormatter::with()
.padding(Padder::codePoints('_', 15, PadPosition::UNUM_PAD_AFTER_SUFFIX))
.unit(CHF),
Locale::getEnglish(),
123.45,
u"CHF\u00A0123.45______");

assertFormatSingle(
u"Suffix Currency Spacing with Pad After Suffix (ICU-23645)",
nullptr,
nullptr,
NumberFormatter::with()
.padding(Padder::codePoints('_', 15, PadPosition::UNUM_PAD_AFTER_SUFFIX))
.unit(CNY),
Locale("lu"),
123.12,
u"123,12\u00A0CN¥______");
}

void NumberFormatterApiTest::integerWidth() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5045,6 +5045,29 @@ public void padding() {
ULocale.ENGLISH,
514.23,
"GBP 000514.23"); // TODO: This is broken; it renders too wide (13 instead of 12).

// Both tests render 16 wide because currency spacing is not counted in padding width.
assertFormatSingle(
"Prefix Currency Spacing with Pad After Suffix (ICU-23645)",
null,
null,
NumberFormatter.with()
.padding(Padder.codePoints('_', 15, PadPosition.AFTER_SUFFIX))
.unit(CHF),
ULocale.ENGLISH,
123.45,
"CHF\u00A0123.45______");

assertFormatSingle(
"Suffix Currency Spacing with Pad After Suffix (ICU-23645)",
null,
null,
NumberFormatter.with()
.padding(Padder.codePoints('_', 15, PadPosition.AFTER_SUFFIX))
.unit(CNY),
ULocale.forLanguageTag("lu"),
123.12,
"123,12\u00A0CN¥______");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,15 @@ public int apply(FormattedStringBuilder output, int leftIndex, int rightIndex) {
overwriteLen =
output.splice(leftIndex + prefixLen, rightIndex + prefixLen, "", 0, 0, null);
}
CurrencySpacingEnabledModifier.applyCurrencySpacing(
output,
leftIndex,
prefixLen,
rightIndex + prefixLen + overwriteLen,
suffixLen,
symbols);
return prefixLen + overwriteLen + suffixLen;
int spacingLen =
CurrencySpacingEnabledModifier.applyCurrencySpacing(
output,
leftIndex,
prefixLen,
rightIndex + prefixLen + overwriteLen,
suffixLen,
symbols);
return prefixLen + overwriteLen + suffixLen + spacingLen;
}

@Override
Expand Down
Loading