Commit eb92bed5 authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[2369] Distinguish between EOF and failures in getChar()

parent 5ac6e8b5
......@@ -70,10 +70,16 @@ InputSource::getChar() {
// Have we reached EOF now? If so, set at_eof_ and return early,
// but don't modify buffer_pos_ (which should still be equal to
// the size of buffer_).
if (!input_.good()) {
if (input_.eof()) {
at_eof_ = true;
return (END_OF_STREAM);
// This has to come after the .eof() check as some
// implementations seem to check the eofbit also in .fail().
if ( {
"Error reading from the input stream: " << getName());
......@@ -79,11 +79,22 @@ public:
/// \brief Exception thrown when we fail to read from the input
/// stream or file.
struct ReadError : public Unexpected {
ReadError(const char* file, size_t line, const char* what) :
Unexpected(file, line, what)
/// \brief Returned by getChar() when end of stream is reached.
static const int END_OF_STREAM;
/// \brief Returns a single character from the input source. If end
/// of file is reached, \c END_OF_STREAM is returned.
/// \throws ReadError when reading from the input stream or file
/// fails.
int getChar();
/// \brief Skips backward a single character in the input
Supports Markdown
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