mirror of
https://github.com/corda/corda.git
synced 2025-01-04 04:04:27 +00:00
handle basic argument substitution in MessageFormat.format
Thanks to Remi for an initial version of this patch.
This commit is contained in:
parent
e2416ddb85
commit
e2ff771baa
@ -28,8 +28,14 @@ public class MessageFormat extends Format {
|
||||
public StringBuffer format(Object[] args, StringBuffer target,
|
||||
FieldPosition p)
|
||||
{
|
||||
// todo
|
||||
return target.append(pattern);
|
||||
// todo: handle other format substitutions and escapes, and make
|
||||
// this more efficient:
|
||||
String result = pattern;
|
||||
int length = args.length;
|
||||
for (int i = 0; i < length; i++) {
|
||||
result = result.replace("{" + i + "}", String.valueOf(args[i]));
|
||||
}
|
||||
return target.append(result);
|
||||
}
|
||||
|
||||
public StringBuffer format(Object args, StringBuffer target, FieldPosition p)
|
||||
|
@ -139,5 +139,12 @@ public class Strings {
|
||||
|
||||
testDecode(false);
|
||||
testDecode(true);
|
||||
|
||||
expect
|
||||
(java.text.MessageFormat.format
|
||||
("{0} enjoy {1} {2}. do {4}? {4} do?",
|
||||
"I", "grape", "nuts", "foobar",
|
||||
new Object() { public String toString() { return "you"; } })
|
||||
.equals("I enjoy grape nuts. do you? you do?"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user