summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2004-07-08 10:30:33 +0000
committerMark Wielaard <mark@klomp.org>2004-07-08 10:30:33 +0000
commit11c259e3045d490f05c432a9f95eeb434649abef (patch)
tree20840970dacf5154430ff8141bf4a1d253047a3e
parent3f1e2f2bdd0c96cedda17fedadc3d8cfae4f354e (diff)
downloadclasspath-11c259e3045d490f05c432a9f95eeb434649abef.tar.gz
2004-07-08 Ito Kazumitsu <kaz@maczuka.gcd.org>
* java/text/MessageFormat.java (formatInternal): Append "{n}" if argument n is unavailable. (format(Object, StringBuffer, FieldPosition)): This should be equivalent to format(Object[], StringBuffer, FieldPosition).
-rw-r--r--ChangeLog14
-rw-r--r--java/text/MessageFormat.java69
2 files changed, 44 insertions, 39 deletions
diff --git a/ChangeLog b/ChangeLog
index 5988ddbfe..30f4552e4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2004-07-08 Ito Kazumitsu <kaz@maczuka.gcd.org>
+
+ * java/text/MessageFormat.java
+ (formatInternal): Append "{n}" if argument n is unavailable.
+ (format(Object, StringBuffer, FieldPosition)): This
+ should be equivalent to format(Object[], StringBuffer, FieldPosition).
+
2004-07-07 Guilhem Lavaux <guilhem@kaffe.org>
* include/jni.h: Fixed compilation in C++ mode.
@@ -143,7 +150,7 @@
2003-06-27 Dalibor Topic <robilad@kaffe.org>
- * java/text/DateFormat.java (parse):
+ * java/text/DateFormat.java (parse):
Improved javadoc. Improved exception message.
2003-06-27 Dalibor Topic <robilad@kaffe.org>
@@ -2434,6 +2441,7 @@
* doc/www.gnu.org/news.wml: show first 9999 entries
2004-05-25 Patrik Reali <reali@acm.org>
+
* doc/www.gnu.org/news.wml, doc/www.gnu.org/home.wml,
doc/www.gnu.org/include/layout.wml: added page with all newsitems,
newsitems on home limited to 8
@@ -2535,9 +2543,9 @@
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c
(requestFocus): Re-add function.
-
+
2004-05-20 Guilhem Lavaux <guilhem@kaffe.org>
-
+
* java/text/CollationElementIterator.java
(nextBlock, previousBlock): Use text_indexes to compute
textIndex.
diff --git a/java/text/MessageFormat.java b/java/text/MessageFormat.java
index 2e1786da9..b12341255 100644
--- a/java/text/MessageFormat.java
+++ b/java/text/MessageFormat.java
@@ -1,5 +1,5 @@
/* MessageFormat.java - Localized message formatting.
- Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2001, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -157,7 +157,7 @@ public class MessageFormat extends Format
* This is the attribute set for all characters produced
* by MessageFormat during a formatting.
*/
- public static final MessageFormat.Field ARGUMENT = new Field("argument");
+ public static final MessageFormat.Field ARGUMENT = new MessageFormat.Field("argument");
// For deserialization
private Field()
@@ -414,10 +414,13 @@ public class MessageFormat extends Format
for (int i = 0; i < elements.length; ++i)
{
- if (elements[i].argNumber >= arguments.length)
- throw new IllegalArgumentException("Not enough arguments given");
+ Object thisArg = null;
+ boolean unavailable = false;
+ if (arguments == null || elements[i].argNumber >= arguments.length)
+ unavailable = true;
+ else
+ thisArg = arguments[elements[i].argNumber];
- Object thisArg = arguments[elements[i].argNumber];
AttributedCharacterIterator iterator = null;
Format formatter = null;
@@ -425,22 +428,27 @@ public class MessageFormat extends Format
if (fp != null && i == fp.getField() && fp.getFieldAttribute() == Field.ARGUMENT)
fp.setBeginIndex(appendBuf.length());
- if (elements[i].setFormat != null)
- formatter = elements[i].setFormat;
- else if (elements[i].format != null)
+ if (unavailable)
+ appendBuf.append("{" + elements[i].argNumber + "}");
+ else
{
- if (elements[i].formatClass != null
- && ! elements[i].formatClass.isInstance(thisArg))
- throw new IllegalArgumentException("Wrong format class");
+ if (elements[i].setFormat != null)
+ formatter = elements[i].setFormat;
+ else if (elements[i].format != null)
+ {
+ if (elements[i].formatClass != null
+ && ! elements[i].formatClass.isInstance(thisArg))
+ throw new IllegalArgumentException("Wrong format class");
- formatter = elements[i].format;
+ formatter = elements[i].format;
+ }
+ else if (thisArg instanceof Number)
+ formatter = NumberFormat.getInstance(locale);
+ else if (thisArg instanceof Date)
+ formatter = DateFormat.getTimeInstance(DateFormat.DEFAULT, locale);
+ else
+ appendBuf.append(thisArg);
}
- else if (thisArg instanceof Number)
- formatter = NumberFormat.getInstance(locale);
- else if (thisArg instanceof Date)
- formatter = DateFormat.getTimeInstance(DateFormat.DEFAULT, locale);
- else
- appendBuf.append(thisArg);
if (fp != null && fp.getField() == i && fp.getFieldAttribute() == Field.ARGUMENT)
fp.setEndIndex(appendBuf.length());
@@ -496,29 +504,18 @@ public class MessageFormat extends Format
}
/**
- * Returns the pattern with the formatted objects.
+ * Returns the pattern with the formatted objects. The first argument
+ * must be a array of Objects.
+ * This is equivalent to format((Object[]) objectArray, appendBuf, fpos)
*
- * @param source The object to be formatted.
- * @param result The StringBuffer where the text is appened.
+ * @param objectArray The object array to be formatted.
+ * @param appendBuf The StringBuffer where the text is appened.
* @param fpos A FieldPosition object (it is ignored).
*/
- public final StringBuffer format (Object singleArg, StringBuffer appendBuf,
+ public final StringBuffer format (Object objectArray, StringBuffer appendBuf,
FieldPosition fpos)
{
- Object[] args;
-
- if (singleArg instanceof Object[])
- {
- // This isn't specified in any manual, but it follows the
- // JDK implementation.
- args = (Object[]) singleArg;
- }
- else
- {
- args = new Object[1];
- args[0] = singleArg;
- }
- return format (args, appendBuf, fpos);
+ return format ((Object[])objectArray, appendBuf, fpos);
}
/**