This is the mail archive of the java-patches@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Patches for java.io.StreamTokenizer




On Sat, 15 Jan 2000, Tom Tromey wrote:
> My only problems with this patch are coding style bugs:

OK... here's my 2nd take:

2000-01-16  Jeff Sturm  <jsturm@sigma6.com>
	* java/io/StreamTokenizer.java (nextToken): Avoid unread(TT_EOF).

Index: StreamTokenizer.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/io/StreamTokenizer.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 StreamTokenizer.java
--- StreamTokenizer.java	1999/04/07 14:52:36	1.1.1.1
+++ StreamTokenizer.java	2000/01/16 17:18:37
@@ -179,7 +179,10 @@
 
 	  // Throw away \n if in combination with \r.
 	  if (ch == '\r' && (ch = in.read()) != '\n')
-	    in.unread(ch);
+	    {
+	      if (ch != TT_EOF)
+		in.unread(ch);
+	    }
 	  if (eolSignificant)
 	    return (ttype = TT_EOL);
 	}
@@ -192,7 +195,8 @@
 	  {
 	    // Read ahead to see if this is an ordinary '-' rather than numeric.
 	    ch = in.read();
-	    in.unread(ch);
+	    if (ch != TT_EOF)
+	      in.unread(ch);
 	    if (isNumeric(ch) && ch != '-')
 	      ch = '-';
 	    else
@@ -209,7 +213,8 @@
 	  else
 	    tokbuf.append((char) ch);
 
-	in.unread(ch);
+	if (ch != TT_EOF)
+	  in.unread(ch);
 	ttype = TT_NUMBER;
 	nval = Double.valueOf(tokbuf.toString()).doubleValue();
       }
@@ -219,7 +224,8 @@
 	tokbuf.append((char) ch);
 	while (isAlphabetic(ch = in.read()) || isNumeric(ch))
 	  tokbuf.append((char) ch);
-	in.unread(ch);
+	if (ch != TT_EOF)
+	  in.unread(ch);
 	ttype = TT_WORD;
 	sval = tokbuf.toString();
 	if (lowerCase)
@@ -229,7 +235,8 @@
       {
 	while ((ch = in.read()) != '\n' && ch != '\r' && ch != TT_EOF)
 	  ;
-	in.unread(ch);
+	if (ch != TT_EOF)
+	  in.unread(ch);
 	return nextToken();	// Recursive, but not too deep in normal cases.
       }
     else if (isQuote(ch))
@@ -277,14 +284,15 @@
 			  }
 		      }
 
-		    in.unread(nextch);
+		    if (nextch != TT_EOF)
+		      in.unread(nextch);
 		}
 
 	    tokbuf.append((char) ch);
 	  }
 
 	// Throw away matching quote char.
-	if (ch != ttype)
+	if (ch != ttype && ch != TT_EOF)
 	  in.unread(ch);
 
 	sval = tokbuf.toString();
@@ -296,7 +304,8 @@
 	    {
 	      while ((ch = in.read()) != '\n' && ch != '\r' && ch != TT_EOF)
 		;
-	      in.unread(ch);
+	      if (ch != TT_EOF)
+		in.unread(ch);
 	      return nextToken(); // Recursive, but not too deep in normal cases
 	    }
 	  else if (ch == '*' && slashStar) 
@@ -305,19 +314,23 @@
 		{
 	          ch = in.read();
 		  if (ch == '*')
-		    if ((ch = in.read()) == '/')
-		      break;
-		    else
-		      in.unread(ch);
+		    {
+		      if ((ch = in.read()) == '/')
+			break;
+		      else if (ch != TT_EOF)
+			in.unread(ch);
+		    }
 		  else if (ch == '\n' || ch == '\r')
 		    {
 		      lineNumber++;
 		      if (ch == '\r' && (ch = in.read()) != '\n')
-			in.unread(ch);
+			{
+		          if (ch != TT_EOF)
+			    in.unread(ch);
+			}
 		    }
 		  else if (ch == TT_EOF)
 		    {
-		      in.unread(ch);
 		      break;
 		    }
 		}
@@ -325,7 +338,8 @@
 	    }
 	  else
 	    {
-	      in.unread(ch);
+	      if (ch != TT_EOF)
+		in.unread(ch);
 	      ch = '/';
 	    }
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]