Patch: FYI: java.text fixlet

Tom Tromey tromey@redhat.com
Sun Jun 8 18:59:00 GMT 2003


I'm checking this in on the trunk.

This fixes a couple bugs found while looking at PR 11085.  I didn't
attempt to fix the bigger problem in PR 11085, namely that
SimpleDateFormat doesn't handle the "Z" format.

Perhaps I'll put this in 3.3 as well.

Tom

Index: libjava/ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	For PR libgcj/11085:
	* java/text/SimpleDateFormat.java (parse(String,ParsePosition)):
	Limit number of characters in numeric field when required.
	* java/text/DecimalFormat.java (parse(String,ParsePosition)):
	Respect maximumIntegerDigits.

Index: libjava/java/text/DecimalFormat.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/text/DecimalFormat.java,v
retrieving revision 1.9
diff -u -r1.9 DecimalFormat.java
--- libjava/java/text/DecimalFormat.java 22 Jan 2002 22:40:37 -0000 1.9
+++ libjava/java/text/DecimalFormat.java 8 Jun 2003 05:21:46 -0000
@@ -1,5 +1,5 @@
 /* DecimalFormat.java -- Formats and parses numbers
-   Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -693,8 +693,8 @@
     int index = pos.getIndex();
     StringBuffer buf = new StringBuffer ();
 
-      // We have to check both prefixes, because one might be empty.
-      // We want to pick the longest prefix that matches.
+    // We have to check both prefixes, because one might be empty.  We
+    // want to pick the longest prefix that matches.
     boolean got_pos = str.startsWith(positivePrefix, index);
     String np = (negativePrefix != null
 		 ? negativePrefix
@@ -729,11 +729,14 @@
 
     // FIXME: handle Inf and NaN.
 
-      // FIXME: do we have to respect minimum/maxmimum digit stuff?
-      // What about leading zeros?  What about multiplier?
+    // FIXME: do we have to respect minimum digits?
+    // What about leading zeros?  What about multiplier?
 
     int start_index = index;
     int max = str.length();
+    int last = index + maximumIntegerDigits;
+    if (last > 0 && max > last)
+      max = last;
     char zero = symbols.getZeroDigit();
     int last_group = -1;
     boolean int_part = true;
Index: libjava/java/text/SimpleDateFormat.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/text/SimpleDateFormat.java,v
retrieving revision 1.16
diff -u -r1.16 SimpleDateFormat.java
--- libjava/java/text/SimpleDateFormat.java 5 Jun 2003 17:57:31 -0000 1.16
+++ libjava/java/text/SimpleDateFormat.java 8 Jun 2003 05:21:46 -0000
@@ -570,6 +570,14 @@
 	while (++fmt_index < fmt_max && pattern.charAt(fmt_index) == ch)
 	  ;
 	int fmt_count = fmt_index - first;
+
+	// We might need to limit the number of digits to parse in
+	// some cases.  We look to the next pattern character to
+	// decide.
+	boolean limit_digits = false;
+	if (fmt_index < fmt_max
+	    && standardChars.indexOf(pattern.charAt(fmt_index)) >= 0)
+	  limit_digits = true;
 	--fmt_index;
 
 	// We can handle most fields automatically: most either are
@@ -702,6 +710,8 @@
 	if (is_numeric)
 	  {
 	    numberFormat.setMinimumIntegerDigits(fmt_count);
+	    if (limit_digits)
+	      numberFormat.setMaximumIntegerDigits(fmt_count);
 	    if (maybe2DigitYear)
 	      index = pos.getIndex();
 	    Number n = numberFormat.parse(dateStr, pos);



More information about the Java-patches mailing list