aboutsummaryrefslogtreecommitdiff
path: root/libjava/java
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2003-06-08 19:00:02 +0000
committerTom Tromey <tromey@gcc.gnu.org>2003-06-08 19:00:02 +0000
commit0a56537c161e85a9f1410f657c6be20ab0b3f750 (patch)
tree026cb63867f77b3c8c89feae341d8dc461663425 /libjava/java
parent5f158b4400a84d31b7180fbc96b1419264843328 (diff)
downloadgcc-0a56537c161e85a9f1410f657c6be20ab0b3f750.zip
gcc-0a56537c161e85a9f1410f657c6be20ab0b3f750.tar.gz
gcc-0a56537c161e85a9f1410f657c6be20ab0b3f750.tar.bz2
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
Diffstat (limited to 'libjava/java')
-rw-r--r--libjava/java/text/DecimalFormat.java13
-rw-r--r--libjava/java/text/SimpleDateFormat.java10
2 files changed, 18 insertions, 5 deletions
diff --git a/libjava/java/text/DecimalFormat.java b/libjava/java/text/DecimalFormat.java
index 2dfdd27..7f94617 100644
--- a/libjava/java/text/DecimalFormat.java
+++ b/libjava/java/text/DecimalFormat.java
@@ -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 @@ public class DecimalFormat extends NumberFormat
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 @@ public class DecimalFormat extends NumberFormat
// 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;
diff --git a/libjava/java/text/SimpleDateFormat.java b/libjava/java/text/SimpleDateFormat.java
index 06ab66f..7b282f3 100644
--- a/libjava/java/text/SimpleDateFormat.java
+++ b/libjava/java/text/SimpleDateFormat.java
@@ -570,6 +570,14 @@ public class SimpleDateFormat extends DateFormat
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 @@ public class SimpleDateFormat extends DateFormat
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);