PR141

Andrew Haley aph@cygnus.co.uk
Thu Aug 24 08:55:00 GMT 2000


2000年08月23日 Andrew Haley <aph@cygnus.co.uk>
 * 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.
Index: StreamTokenizer.java
===================================================================
RCS file: /cvs/cvsfiles/devo/libjava/java/io/StreamTokenizer.java,v
retrieving revision 1.9.8.1
diff -c -1 -0 -p -r1.9.8.1 StreamTokenizer.java
*** StreamTokenizer.java	2000年07月24日 19:37:45	1.9.8.1
--- StreamTokenizer.java	2000年08月24日 15:54:57
*************** public class StreamTokenizer
*** 286,331 ****
 		in.unread(ch);
 	 }
 	 if (eolSignificant)
 	 return (ttype = TT_EOL);
 	}
 
 if (ch == TT_EOF)
 ttype = TT_EOF;
 else if (isNumeric(ch))
 {
 	if (ch == '-')
 	 {
 	 // Read ahead to see if this is an ordinary '-' rather than numeric.
 	 ch = in.read();
- 	 if (ch != TT_EOF)
- 	 in.unread(ch);
 	 if (isNumeric(ch) && ch != '-')
! 	 ch = '-';
 	 else
! 	 return (ttype = '-');
 	 }
 
 	StringBuffer tokbuf = new StringBuffer();
 	tokbuf.append((char) ch);
 
 	int decCount = 0;
 	while (isNumeric(ch = in.read()) && ch != '-')
 	 if (ch == '.' && decCount++ > 0)
 	 break;
 	 else
 	 tokbuf.append((char) ch);
 
 	if (ch != TT_EOF)
 	 in.unread(ch);
 	ttype = TT_NUMBER;
! 	nval = Double.valueOf(tokbuf.toString()).doubleValue();
 }
 else if (isAlphabetic(ch))
 {
 	StringBuffer tokbuf = new StringBuffer();
 	tokbuf.append((char) ch);
 	while (isAlphabetic(ch = in.read()) || isNumeric(ch))
 	 tokbuf.append((char) ch);
 	if (ch != TT_EOF)
 	 in.unread(ch);
 	ttype = TT_WORD;
--- 286,345 ----
 		in.unread(ch);
 	 }
 	 if (eolSignificant)
 	 return (ttype = TT_EOL);
 	}
 
 if (ch == TT_EOF)
 ttype = TT_EOF;
 else if (isNumeric(ch))
 {
+ 	boolean isNegative = false;
 	if (ch == '-')
 	 {
 	 // Read ahead to see if this is an ordinary '-' rather than numeric.
 	 ch = in.read();
 	 if (isNumeric(ch) && ch != '-')
! 	 {
! 		isNegative = true;
! 	 }
 	 else
! 	 {
! 		if (ch != TT_EOF)
! 		 in.unread(ch);
! 		return (ttype = '-');
! 	 }
 	 }
 
 	StringBuffer tokbuf = new StringBuffer();
 	tokbuf.append((char) ch);
 
 	int decCount = 0;
 	while (isNumeric(ch = in.read()) && ch != '-')
 	 if (ch == '.' && decCount++ > 0)
 	 break;
 	 else
 	 tokbuf.append((char) ch);
 
 	if (ch != TT_EOF)
 	 in.unread(ch);
 	ttype = TT_NUMBER;
! 	try
! 	 {
! 	 nval = Double.valueOf(tokbuf.toString()).doubleValue();
! 	 }
! 	catch (NumberFormatException _)
! 	 {
! 	 nval = 0.0;
! 	 }
! 	if (isNegative)
! 	 nval = -nval;
 }
 else if (isAlphabetic(ch))
 {
 	StringBuffer tokbuf = new StringBuffer();
 	tokbuf.append((char) ch);
 	while (isAlphabetic(ch = in.read()) || isNumeric(ch))
 	 tokbuf.append((char) ch);
 	if (ch != TT_EOF)
 	 in.unread(ch);
 	ttype = TT_WORD;


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /