This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: java.text.MessageFormat


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,


I just commited the attached patch to merge fixes done by Ito 
Kazumitsu in classpath.


2004-07-10  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).
- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFA76/bWSOgCCdjSDsRAkETAJ0bgzLl5Hu3PAXML4gEiUEwryG2aQCbBE4w
NJEB/xt9yS3pMN4rIUhZm58=
=pB/Z
-----END PGP SIGNATURE-----
Index: java/text/MessageFormat.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/text/MessageFormat.java,v
retrieving revision 1.16
diff -u -b -B -r1.16 MessageFormat.java
--- java/text/MessageFormat.java	4 May 2004 22:05:25 -0000	1.16
+++ java/text/MessageFormat.java	10 Jul 2004 08:50:41 -0000
@@ -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 @@
      * 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 @@
 
     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,6 +428,10 @@
 	if (fp != null && i == fp.getField() && fp.getFieldAttribute() == Field.ARGUMENT)
 	  fp.setBeginIndex(appendBuf.length());
 
+	if (unavailable)
+	  appendBuf.append("{" + elements[i].argNumber + "}");
+	else
+	  {
 	if (elements[i].setFormat != null)
 	  formatter = elements[i].setFormat;
 	else if (elements[i].format != null)
@@ -441,6 +448,7 @@
 	  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 @@
   }
 
   /**
-   * 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);
   }
 
   /**

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]