From 49407c6a1e324fbf33260d14f8df3db8c2b49ce3 Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Wed, 7 Sep 2011 23:02:21 +0000 Subject: [PATCH] ICU-8806 fix MessageFormat plural # formatting: fix offset lookup X-SVN-Rev: 30634 --- .../src/com/ibm/icu/text/MessageFormat.java | 2 +- .../dev/test/format/PluralFormatUnitTest.java | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/MessageFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/MessageFormat.java index ba6d42dbf9c..e5e56f26733 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/MessageFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/MessageFormat.java @@ -1706,7 +1706,7 @@ public class MessageFormat extends UFormat { pluralProvider = new PluralSelectorProvider(ulocale); } int subMsgStart=PluralFormat.findSubMessage(msgPattern, i, pluralProvider, number); - double offset=msgPattern.getPluralOffset(subMsgStart); + double offset=msgPattern.getPluralOffset(i); formatComplexSubMessage(subMsgStart, number-offset, args, argsMap, dest); } else if(argType==ArgType.SELECT) { int subMsgStart=SelectFormat.findSubMessage(msgPattern, i, arg.toString()); diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/PluralFormatUnitTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/PluralFormatUnitTest.java index 7f41c8467ef..d08f239f53f 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/PluralFormatUnitTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/PluralFormatUnitTest.java @@ -284,17 +284,22 @@ public class PluralFormatUnitTest extends TestFmwk { "There is a bling widget and 5 other widgets.", "There is a bling widget and 6 other widgets.", }; - PluralFormat pf = new PluralFormat( - ULocale.ENGLISH, - "offset:1.0 " - + "=0 {There are no widgets.} " - + "=1.0 {There is one widget.} " - + "=5 {Widgets, five (5-1=#) there be.} " - + "one {There is a bling widget and one other widget.} " - + "other {There is a bling widget and # other widgets.}"); + String pluralStyle = + "offset:1.0 " + + "=0 {There are no widgets.} " + + "=1.0 {There is one widget.} " + + "=5 {Widgets, five (5-1=#) there be.} " + + "one {There is a bling widget and one other widget.} " + + "other {There is a bling widget and # other widgets.}"; + PluralFormat pf = new PluralFormat(ULocale.ENGLISH, pluralStyle); + MessageFormat mf = new MessageFormat("{0,plural," + pluralStyle + "}", ULocale.ENGLISH); + Integer args[] = new Integer[1]; for (int i = 0; i < 7; ++i) { String result = pf.format(i); - assertEquals("value = " + i, targets[i], result); + assertEquals("PluralFormat.format(value " + i + ")", targets[i], result); + args[0] = i; + result = mf.format(args); + assertEquals("MessageFormat.format(value " + i + ")", targets[i], result); } // Try explicit values after keywords. -- 2.40.0