From df0d824956544940c1e764162e7a92ee769c3df3 Mon Sep 17 00:00:00 2001 From: Travis Keep Date: Thu, 27 Sep 2012 23:41:01 +0000 Subject: [PATCH] ICU-9612 Fix CompactDecimalFormat so that it handles periods correctly that appear in prefixes or suffixes. X-SVN-Rev: 32450 --- .../ibm/icu/text/CompactDecimalDataCache.java | 7 +++++-- .../test/format/CompactDecimalFormatTest.java | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/CompactDecimalDataCache.java b/icu4j/main/classes/core/src/com/ibm/icu/text/CompactDecimalDataCache.java index e8747c6736..3477288d6f 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/CompactDecimalDataCache.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/CompactDecimalDataCache.java @@ -269,9 +269,9 @@ class CompactDecimalDataCache { " in " + localeAndStyle(locale, style)); } savePrefixOrSuffix( - template.substring(0, firstIdx), pluralVariant, idx, result.prefixes); + fixQuotes(template.substring(0, firstIdx)), pluralVariant, idx, result.prefixes); savePrefixOrSuffix( - template.substring(lastIdx + 1), pluralVariant, idx, result.suffixes); + fixQuotes(template.substring(lastIdx + 1)), pluralVariant, idx, result.suffixes); // Calculate number of zeros before decimal point. int i = firstIdx + 1; @@ -281,6 +281,9 @@ class CompactDecimalDataCache { return i - firstIdx; } + private static String fixQuotes(String prefixOrSuffix) { + return prefixOrSuffix.replace("'.'", "."); + } /** * Returns locale and style. Used to form useful messages in thrown 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 d70f33b2d0..cbe9d45a6a 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 @@ -107,6 +107,23 @@ public class CompactDecimalFormatTest extends TestFmwk { {12345678901234f, "T12"}, {12345678901234567890f, "T12000000"}, }; + + Object[][] CsTestDataShort = { + {1000, "1\u00a0tis."}, + {1500, "1,5\u00a0tis."}, + {5000, "5\u00a0tis."}, + {23000, "23\u00a0tis."}, + {127123, "130\u00a0tis."}, + {1271234, "1,3\u00a0mil."}, + {12712345, "13\u00a0mil."}, + {127123456, "130\u00a0mil."}, + {1271234567f, "1,3\u00a0mld."}, + {12712345678f, "13\u00a0mld."}, + {127123456789f, "130\u00a0mld."}, + {1271234567890f, "1,3\u00a0bil."}, + {12712345678901f, "13\u00a0bil."}, + {127123456789012f, "130\u00a0bil."}, + }; public void TestCharacterIterator() { CompactDecimalFormat cdf = @@ -129,6 +146,10 @@ public class CompactDecimalFormatTest extends TestFmwk { ULocale.forLanguageTag("ar"), CompactStyle.LONG); assertEquals("Arabic Long", "٥٫٣ ألف", cdf.format(5300)); } + + public void TestCsShort() { + checkLocale(ULocale.forLanguageTag("cs"), CompactStyle.SHORT, CsTestDataShort); + } public void TestSerbianShort() { checkLocale(ULocale.forLanguageTag("sr"), CompactStyle.SHORT, SerbianTestDataShort);