Commit 2ce7461b by Jeff Sturm Committed by Tom Tromey

StreamTokenizer.java (nextToken): Avoid unread(TT_EOF).

2000-01-16  Jeff Sturm  <jsturm@sigma6.com>

	* java/io/StreamTokenizer.java (nextToken): Avoid unread(TT_EOF).

From-SVN: r31449
parent ed4c3661
2000-01-16 Jeff Sturm <jsturm@sigma6.com>
* java/io/StreamTokenizer.java (nextToken): Avoid unread(TT_EOF).
2000-01-13 Tom Tromey <tromey@cygnus.com> 2000-01-13 Tom Tromey <tromey@cygnus.com>
* java/lang/natClassLoader.cc (_Jv_FindClass): Register `loader', * java/lang/natClassLoader.cc (_Jv_FindClass): Register `loader',
......
...@@ -179,7 +179,10 @@ public class StreamTokenizer ...@@ -179,7 +179,10 @@ public class StreamTokenizer
// Throw away \n if in combination with \r. // Throw away \n if in combination with \r.
if (ch == '\r' && (ch = in.read()) != '\n') if (ch == '\r' && (ch = in.read()) != '\n')
in.unread(ch); {
if (ch != TT_EOF)
in.unread(ch);
}
if (eolSignificant) if (eolSignificant)
return (ttype = TT_EOL); return (ttype = TT_EOL);
} }
...@@ -192,7 +195,8 @@ public class StreamTokenizer ...@@ -192,7 +195,8 @@ public class StreamTokenizer
{ {
// 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();
in.unread(ch); if (ch != TT_EOF)
in.unread(ch);
if (isNumeric(ch) && ch != '-') if (isNumeric(ch) && ch != '-')
ch = '-'; ch = '-';
else else
...@@ -209,7 +213,8 @@ public class StreamTokenizer ...@@ -209,7 +213,8 @@ public class StreamTokenizer
else else
tokbuf.append((char) ch); tokbuf.append((char) ch);
in.unread(ch); if (ch != TT_EOF)
in.unread(ch);
ttype = TT_NUMBER; ttype = TT_NUMBER;
nval = Double.valueOf(tokbuf.toString()).doubleValue(); nval = Double.valueOf(tokbuf.toString()).doubleValue();
} }
...@@ -219,7 +224,8 @@ public class StreamTokenizer ...@@ -219,7 +224,8 @@ public class StreamTokenizer
tokbuf.append((char) ch); tokbuf.append((char) ch);
while (isAlphabetic(ch = in.read()) || isNumeric(ch)) while (isAlphabetic(ch = in.read()) || isNumeric(ch))
tokbuf.append((char) ch); tokbuf.append((char) ch);
in.unread(ch); if (ch != TT_EOF)
in.unread(ch);
ttype = TT_WORD; ttype = TT_WORD;
sval = tokbuf.toString(); sval = tokbuf.toString();
if (lowerCase) if (lowerCase)
...@@ -229,7 +235,8 @@ public class StreamTokenizer ...@@ -229,7 +235,8 @@ public class StreamTokenizer
{ {
while ((ch = in.read()) != '\n' && ch != '\r' && ch != TT_EOF) 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. return nextToken(); // Recursive, but not too deep in normal cases.
} }
else if (isQuote(ch)) else if (isQuote(ch))
...@@ -277,14 +284,15 @@ public class StreamTokenizer ...@@ -277,14 +284,15 @@ public class StreamTokenizer
} }
} }
in.unread(nextch); if (nextch != TT_EOF)
in.unread(nextch);
} }
tokbuf.append((char) ch); tokbuf.append((char) ch);
} }
// Throw away matching quote char. // Throw away matching quote char.
if (ch != ttype) if (ch != ttype && ch != TT_EOF)
in.unread(ch); in.unread(ch);
sval = tokbuf.toString(); sval = tokbuf.toString();
...@@ -296,7 +304,8 @@ public class StreamTokenizer ...@@ -296,7 +304,8 @@ public class StreamTokenizer
{ {
while ((ch = in.read()) != '\n' && ch != '\r' && ch != TT_EOF) 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 return nextToken(); // Recursive, but not too deep in normal cases
} }
else if (ch == '*' && slashStar) else if (ch == '*' && slashStar)
...@@ -305,19 +314,23 @@ public class StreamTokenizer ...@@ -305,19 +314,23 @@ public class StreamTokenizer
{ {
ch = in.read(); ch = in.read();
if (ch == '*') if (ch == '*')
if ((ch = in.read()) == '/') {
break; if ((ch = in.read()) == '/')
else break;
in.unread(ch); else if (ch != TT_EOF)
in.unread(ch);
}
else if (ch == '\n' || ch == '\r') else if (ch == '\n' || ch == '\r')
{ {
lineNumber++; lineNumber++;
if (ch == '\r' && (ch = in.read()) != '\n') if (ch == '\r' && (ch = in.read()) != '\n')
in.unread(ch); {
if (ch != TT_EOF)
in.unread(ch);
}
} }
else if (ch == TT_EOF) else if (ch == TT_EOF)
{ {
in.unread(ch);
break; break;
} }
} }
...@@ -325,7 +338,8 @@ public class StreamTokenizer ...@@ -325,7 +338,8 @@ public class StreamTokenizer
} }
else else
{ {
in.unread(ch); if (ch != TT_EOF)
in.unread(ch);
ch = '/'; ch = '/';
} }
......
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