diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-11-17 01:21:00 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-11-17 01:21:00 -0800 |
commit | 08cf048f2a8ed0fa096f2c82e147b61ffc480e2a (patch) | |
tree | 80493ca241c9172e21df76cedb98312af6de8113 /014literal_string.cc | |
parent | 21c277062ef151ad86e2003ad0e2bfb09f3d4c2d (diff) | |
download | mu-08cf048f2a8ed0fa096f2c82e147b61ffc480e2a.tar.gz |
2454
Another gotcha uncovered in the process of sorting out the previous commit: I keep using eof() but forgetting that there are two other states an istream can get into. Just never use eof().
Diffstat (limited to '014literal_string.cc')
-rw-r--r-- | 014literal_string.cc | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/014literal_string.cc b/014literal_string.cc index 1e7f7b0b..34655aa9 100644 --- a/014literal_string.cc +++ b/014literal_string.cc @@ -32,7 +32,7 @@ if (in.peek() == '[') { :(code) string slurp_quoted(istream& in) { ostringstream out; - assert(!in.eof()); assert(in.peek() == '['); out << static_cast<char>(in.get()); // slurp the '[' + assert(has_data(in)); assert(in.peek() == '['); out << static_cast<char>(in.get()); // slurp the '[' if (is_code_string(in, out)) slurp_quoted_comment_aware(in, out); else @@ -43,7 +43,7 @@ string slurp_quoted(istream& in) { // A string is a code string if it contains a newline before any non-whitespace // todo: support comments before the newline. But that gets messy. bool is_code_string(istream& in, ostream& out) { - while (!in.eof()) { + while (has_data(in)) { char c = in.get(); if (!isspace(c)) { in.putback(c); @@ -61,7 +61,7 @@ bool is_code_string(istream& in, ostream& out) { // strings. void slurp_quoted_comment_oblivious(istream& in, ostream& out) { int brace_depth = 1; - while (!in.eof()) { + while (has_data(in)) { char c = in.get(); if (c == '\\') { out << static_cast<char>(in.get()); @@ -72,7 +72,7 @@ void slurp_quoted_comment_oblivious(istream& in, ostream& out) { if (c == ']') --brace_depth; if (brace_depth == 0) break; } - if (in.eof() && brace_depth > 0) { + if (!has_data(in) && brace_depth > 0) { raise_error << "unbalanced '['\n" << end(); out.clear(); } @@ -88,7 +88,7 @@ void slurp_quoted_comment_aware(istream& in, ostream& out) { } if (c == '#') { out << c; - while (!in.eof() && in.peek() != '\n') out << static_cast<char>(in.get()); + while (has_data(in) && in.peek() != '\n') out << static_cast<char>(in.get()); continue; } if (c == '[') { |