Commit ad17a40d by Andrew Haley Committed by Andrew Haley

StreamTokenizer.java: Don't throw a NumberFormatException if a field is numeric as far as the...

2000-09-01  Andrew Haley  <aph@redhat.com>

        * java/io/StreamTokenizer.java: Don't throw a
        NumberFormatException if a field is numeric as far as the
        StreamTokenizer is concerned but not as far as Double.valueOf() is
        concerned: return a zero instead.

	For gcj/141.

From-SVN: r36100
parent 6324d2bb
2000-09-01 Andrew Haley <aph@redhat.com>
* java/io/StreamTokenizer.java: Don't throw a
NumberFormatException if a field is numeric as far as the
StreamTokenizer is concerned but not as far as Double.valueOf() is
concerned: return a zero instead.
2000-08-30 Tom Tromey <tromey@cygnus.com> 2000-08-30 Tom Tromey <tromey@cygnus.com>
* Makefile.in: Rebuilt. * Makefile.in: Rebuilt.
......
...@@ -293,17 +293,22 @@ public class StreamTokenizer ...@@ -293,17 +293,22 @@ public class StreamTokenizer
ttype = TT_EOF; ttype = TT_EOF;
else if (isNumeric(ch)) else if (isNumeric(ch))
{ {
boolean isNegative = false;
if (ch == '-') if (ch == '-')
{ {
// Read ahead to see if this is an ordinary '-' rather than numeric. // Read ahead to see if this is an ordinary '-' rather than numeric.
ch = in.read(); ch = in.read();
if (ch != TT_EOF)
in.unread(ch);
if (isNumeric(ch) && ch != '-') if (isNumeric(ch) && ch != '-')
ch = '-'; {
isNegative = true;
}
else else
{
if (ch != TT_EOF)
in.unread(ch);
return (ttype = '-'); return (ttype = '-');
} }
}
StringBuffer tokbuf = new StringBuffer(); StringBuffer tokbuf = new StringBuffer();
tokbuf.append((char) ch); tokbuf.append((char) ch);
...@@ -318,8 +323,17 @@ public class StreamTokenizer ...@@ -318,8 +323,17 @@ public class StreamTokenizer
if (ch != TT_EOF) if (ch != TT_EOF)
in.unread(ch); in.unread(ch);
ttype = TT_NUMBER; ttype = TT_NUMBER;
try
{
nval = Double.valueOf(tokbuf.toString()).doubleValue(); nval = Double.valueOf(tokbuf.toString()).doubleValue();
} }
catch (NumberFormatException _)
{
nval = 0.0;
}
if (isNegative)
nval = -nval;
}
else if (isAlphabetic(ch)) else if (isAlphabetic(ch))
{ {
StringBuffer tokbuf = new StringBuffer(); StringBuffer tokbuf = new StringBuffer();
......
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