File tree Expand file tree Collapse file tree 1 file changed +14
-9
lines changed
Expand file tree Collapse file tree 1 file changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -382,31 +382,36 @@ class FileStream : public simplecpp::TokenList::Stream {
382382 }
383383
384384 virtual int get () {
385- lastCh = fgetc (file);
385+ lastStatus = lastCh = fgetc (file);
386386 return lastCh;
387387 }
388388 virtual int peek () {
389- const int ch = get ();
390- unget ();
389+ // keep lastCh intact
390+ const int ch = fgetc (file);
391+ unget_internal (ch);
391392 return ch;
392393 }
393394 virtual void unget () {
395+ unget_internal (lastCh);
396+ }
397+ virtual bool good () {
398+ return lastStatus != EOF;
399+ }
400+
401+ private:
402+ void unget_internal (int ch) {
394403 if (isUtf16) {
395404 // TODO: use ungetc() as well
396405 // UTF-16 has subsequent unget() calls
397406 fseek (file, -1 , SEEK_CUR);
398407 }
399408 else
400- ungetc (lastCh, file);
401-
402- }
403- virtual bool good () {
404- return lastCh != EOF;
409+ ungetc (ch, file);
405410 }
406411
407- private:
408412 FILE *file;
409413 int lastCh;
414+ int lastStatus;
410415};
411416
412417simplecpp::TokenList::TokenList (std::vector<std::string> &filenames) : frontToken(nullptr ), backToken(nullptr ), files(filenames) {}
You can’t perform that action at this time.
0 commit comments