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
This commit is contained in:
Jeff Sturm 2000-01-16 21:33:46 +00:00 committed by Tom Tromey
parent ed4c3661d5
commit 2ce7461bd0
2 changed files with 33 additions and 15 deletions

View file

@ -1,3 +1,7 @@
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',

View file

@ -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')
{
if (ch != TT_EOF)
in.unread(ch); in.unread(ch);
}
if (eolSignificant) if (eolSignificant)
return (ttype = TT_EOL); return (ttype = TT_EOL);
} }
@ -192,6 +195,7 @@ 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();
if (ch != TT_EOF)
in.unread(ch); in.unread(ch);
if (isNumeric(ch) && ch != '-') if (isNumeric(ch) && ch != '-')
ch = '-'; ch = '-';
@ -209,6 +213,7 @@ public class StreamTokenizer
else else
tokbuf.append((char) ch); tokbuf.append((char) ch);
if (ch != TT_EOF)
in.unread(ch); in.unread(ch);
ttype = TT_NUMBER; ttype = TT_NUMBER;
nval = Double.valueOf(tokbuf.toString()).doubleValue(); nval = Double.valueOf(tokbuf.toString()).doubleValue();
@ -219,6 +224,7 @@ 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);
if (ch != TT_EOF)
in.unread(ch); in.unread(ch);
ttype = TT_WORD; ttype = TT_WORD;
sval = tokbuf.toString(); sval = tokbuf.toString();
@ -229,6 +235,7 @@ public class StreamTokenizer
{ {
while ((ch = in.read()) != '\n' && ch != '\r' && ch != TT_EOF) while ((ch = in.read()) != '\n' && ch != '\r' && ch != TT_EOF)
; ;
if (ch != TT_EOF)
in.unread(ch); in.unread(ch);
return nextToken(); // Recursive, but not too deep in normal cases. return nextToken(); // Recursive, but not too deep in normal cases.
} }
@ -277,6 +284,7 @@ public class StreamTokenizer
} }
} }
if (nextch != TT_EOF)
in.unread(nextch); in.unread(nextch);
} }
@ -284,7 +292,7 @@ public class StreamTokenizer
} }
// 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,6 +304,7 @@ public class StreamTokenizer
{ {
while ((ch = in.read()) != '\n' && ch != '\r' && ch != TT_EOF) while ((ch = in.read()) != '\n' && ch != '\r' && ch != TT_EOF)
; ;
if (ch != TT_EOF)
in.unread(ch); in.unread(ch);
return nextToken(); // Recursive, but not too deep in normal cases return nextToken(); // Recursive, but not too deep in normal cases
} }
@ -305,19 +314,23 @@ public class StreamTokenizer
{ {
ch = in.read(); ch = in.read();
if (ch == '*') if (ch == '*')
{
if ((ch = in.read()) == '/') if ((ch = in.read()) == '/')
break; break;
else else if (ch != TT_EOF)
in.unread(ch); 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')
{
if (ch != TT_EOF)
in.unread(ch); in.unread(ch);
} }
}
else if (ch == TT_EOF) else if (ch == TT_EOF)
{ {
in.unread(ch);
break; break;
} }
} }
@ -325,6 +338,7 @@ public class StreamTokenizer
} }
else else
{ {
if (ch != TT_EOF)
in.unread(ch); in.unread(ch);
ch = '/'; ch = '/';
} }