mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 22:44:49 +00:00
ICU-11952 match whole select part string, not just prefix
X-SVN-Rev: 38456
This commit is contained in:
parent
f2e7352104
commit
54ca0ab18c
2 changed files with 24 additions and 2 deletions
|
@ -481,7 +481,7 @@ public final class MessagePattern implements Cloneable, Freezable<MessagePattern
|
|||
* @stable ICU 4.8
|
||||
*/
|
||||
public boolean partSubstringMatches(Part part, String s) {
|
||||
return msg.regionMatches(part.index, s, 0, part.length);
|
||||
return part.length == s.length() && msg.regionMatches(part.index, s, 0, part.length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
**********************************************************************
|
||||
* Copyright (c) 2004-2015, International Business Machines
|
||||
* Copyright (c) 2004-2016, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
* Author: Alan Liu
|
||||
|
@ -23,6 +23,7 @@ import java.util.Iterator;
|
|||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.ibm.icu.text.DateFormat;
|
||||
import com.ibm.icu.text.DecimalFormat;
|
||||
|
@ -1934,4 +1935,25 @@ public class TestMessageFormat extends com.ibm.icu.dev.test.TestFmwk {
|
|||
assertEquals("offset-decimals format(1)", "2.5 meters",
|
||||
m2.format(args, result, ignore).toString());
|
||||
}
|
||||
|
||||
public void TestArgIsPrefixOfAnother() {
|
||||
// Ticket #11952
|
||||
MessageFormat mf1 = new MessageFormat(
|
||||
"{0,select,a{A}ab{AB}abc{ABC}other{?}}", ULocale.ENGLISH);
|
||||
assertEquals("a", "A", mf1.format(new Object[] { "a" }));
|
||||
assertEquals("ab", "AB", mf1.format(new Object[] { "ab" }));
|
||||
assertEquals("abc", "ABC", mf1.format(new Object[] { "abc" }));
|
||||
|
||||
// Ticket #12172
|
||||
MessageFormat mf2 = new MessageFormat("{a} {aa} {aaa}", ULocale.ENGLISH);
|
||||
Map<String, Object> args = new TreeMap<String, Object>();
|
||||
args.put("a", "A");
|
||||
args.put("aa", "AB");
|
||||
args.put("aaa", "ABC");
|
||||
assertEquals("a aa aaa", "A AB ABC", mf2.format(args, new StringBuffer(), null).toString());
|
||||
|
||||
// Ticket #12172
|
||||
MessageFormat mf3 = new MessageFormat("{aa} {aaa}", ULocale.ENGLISH);
|
||||
assertEquals("aa aaa", "AB ABC", mf3.format(args, new StringBuffer(), null).toString());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue