Commit 0a56537c by Tom Tromey Committed by Tom Tromey

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.

From-SVN: r67633
parent 5f158b44
2003-06-07 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.
2003-06-08 Michael Koch <konqueror@gmx.de> 2003-06-08 Michael Koch <konqueror@gmx.de>
* java/net/Socket.java * java/net/Socket.java
......
/* DecimalFormat.java -- Formats and parses numbers /* 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. This file is part of GNU Classpath.
...@@ -693,8 +693,8 @@ public class DecimalFormat extends NumberFormat ...@@ -693,8 +693,8 @@ public class DecimalFormat extends NumberFormat
int index = pos.getIndex(); int index = pos.getIndex();
StringBuffer buf = new StringBuffer (); StringBuffer buf = new StringBuffer ();
// We have to check both prefixes, because one might be empty. // We have to check both prefixes, because one might be empty. We
// We want to pick the longest prefix that matches. // want to pick the longest prefix that matches.
boolean got_pos = str.startsWith(positivePrefix, index); boolean got_pos = str.startsWith(positivePrefix, index);
String np = (negativePrefix != null String np = (negativePrefix != null
? negativePrefix ? negativePrefix
...@@ -729,11 +729,14 @@ public class DecimalFormat extends NumberFormat ...@@ -729,11 +729,14 @@ public class DecimalFormat extends NumberFormat
// FIXME: handle Inf and NaN. // FIXME: handle Inf and NaN.
// FIXME: do we have to respect minimum/maxmimum digit stuff? // FIXME: do we have to respect minimum digits?
// What about leading zeros? What about multiplier? // What about leading zeros? What about multiplier?
int start_index = index; int start_index = index;
int max = str.length(); int max = str.length();
int last = index + maximumIntegerDigits;
if (last > 0 && max > last)
max = last;
char zero = symbols.getZeroDigit(); char zero = symbols.getZeroDigit();
int last_group = -1; int last_group = -1;
boolean int_part = true; boolean int_part = true;
......
...@@ -570,6 +570,14 @@ public class SimpleDateFormat extends DateFormat ...@@ -570,6 +570,14 @@ public class SimpleDateFormat extends DateFormat
while (++fmt_index < fmt_max && pattern.charAt(fmt_index) == ch) while (++fmt_index < fmt_max && pattern.charAt(fmt_index) == ch)
; ;
int fmt_count = fmt_index - first; 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; --fmt_index;
// We can handle most fields automatically: most either are // We can handle most fields automatically: most either are
...@@ -702,6 +710,8 @@ public class SimpleDateFormat extends DateFormat ...@@ -702,6 +710,8 @@ public class SimpleDateFormat extends DateFormat
if (is_numeric) if (is_numeric)
{ {
numberFormat.setMinimumIntegerDigits(fmt_count); numberFormat.setMinimumIntegerDigits(fmt_count);
if (limit_digits)
numberFormat.setMaximumIntegerDigits(fmt_count);
if (maybe2DigitYear) if (maybe2DigitYear)
index = pos.getIndex(); index = pos.getIndex();
Number n = numberFormat.parse(dateStr, pos); Number n = numberFormat.parse(dateStr, pos);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment