Skip to content

Commit

Permalink
ICU-11276 Apply the approximately pattern inside of the unit string. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc authored Sep 21, 2018
1 parent 9fc064c commit d16724e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
7 changes: 5 additions & 2 deletions icu4c/source/i18n/numrange_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,11 @@ void NumberRangeFormatterImpl::formatApproximately (UFormattedNumberRangeData& d
if (U_FAILURE(status)) { return; }
if (fSameFormatters) {
int32_t length = NumberFormatterImpl::writeNumber(micros1, data.quantity1, data.string, 0, status);
length += NumberFormatterImpl::writeAffixes(micros1, data.string, 0, length, status);
fApproximatelyModifier.apply(data.string, 0, length, status);
// HEURISTIC: Desired modifier order: inner, middle, approximately, outer.
length += micros1.modInner->apply(data.string, 0, length, status);
length += micros1.modMiddle->apply(data.string, 0, length, status);
length += fApproximatelyModifier.apply(data.string, 0, length, status);
micros1.modOuter->apply(data.string, 0, length, status);
} else {
formatRange(data, micros1, micros2, status);
}
Expand Down
18 changes: 17 additions & 1 deletion icu4c/source/test/intltest/numbertest_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ void NumberRangeFormatterTest::testIdentity() {
u"5,000–5,000,000");

assertFormatRange(
u"Identity fallback Single Value",
u"Identity fallback Single Value",
NumberRangeFormatter::with().identityFallback(UNUM_IDENTITY_FALLBACK_SINGLE_VALUE),
Locale("en-us"),
u"1–5",
Expand Down Expand Up @@ -623,6 +623,22 @@ void NumberRangeFormatterTest::testIdentity() {
u"~5K",
u"5K",
u"5K – 5M");

assertFormatRange(
u"Approximately in middle of unit string",
NumberRangeFormatter::with().numberFormatterBoth(
NumberFormatter::with().unit(FAHRENHEIT).unitWidth(UNUM_UNIT_WIDTH_FULL_NAME)),
Locale("zh-Hant"),
u"華氏 1-5 度",
u"華氏 ~5 度",
u"華氏 ~5 度",
u"華氏 0-3 度",
u"華氏 ~0 度",
u"華氏 3-3,000 度",
u"華氏 3,000-5,000 度",
u"華氏 4,999-5,001 度",
u"華氏 ~5,000 度",
u"華氏 5,000-5,000,000 度");
}

void NumberRangeFormatterTest::testDifferentFormatters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,11 @@ private void formatApproximately(DecimalQuantity quantity1, DecimalQuantity quan
MicroProps micros1, MicroProps micros2) {
if (fSameFormatters) {
int length = NumberFormatterImpl.writeNumber(micros1, quantity1, string, 0);
length += NumberFormatterImpl.writeAffixes(micros1, string, 0, length);
fApproximatelyModifier.apply(string, 0, length);
// HEURISTIC: Desired modifier order: inner, middle, approximately, outer.
length += micros1.modInner.apply(string, 0, length);
length += micros1.modMiddle.apply(string, 0, length);
length += fApproximatelyModifier.apply(string, 0, length);
micros1.modOuter.apply(string, 0, length);
} else {
formatRange(quantity1, quantity2, string, micros1, micros2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,22 @@ public void testIdentity() {
"~5K",
"5K",
"5K – 5M");

assertFormatRange(
"Approximately in middle of unit string",
NumberRangeFormatter.with().numberFormatterBoth(
NumberFormatter.with().unit(MeasureUnit.FAHRENHEIT).unitWidth(UnitWidth.FULL_NAME)),
new ULocale("zh-Hant"),
"華氏 1-5 度",
"華氏 ~5 度",
"華氏 ~5 度",
"華氏 0-3 度",
"華氏 ~0 度",
"華氏 3-3,000 度",
"華氏 3,000-5,000 度",
"華氏 4,999-5,001 度",
"華氏 ~5,000 度",
"華氏 5,000-5,000,000 度");
}

@Test
Expand Down

0 comments on commit d16724e

Please sign in to comment.