File tree 1 file changed +14
-9
lines changed 1 file changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -383,31 +383,36 @@ class FileStream : public simplecpp::TokenList::Stream {
383
383
}
384
384
385
385
virtual int get () {
386
- lastCh = fgetc (file);
386
+ lastStatus = lastCh = fgetc (file);
387
387
return lastCh;
388
388
}
389
389
virtual int peek () {
390
- const int ch = get ();
391
- unget ();
390
+ // keep lastCh intact
391
+ const int ch = fgetc (file);
392
+ unget_internal (ch);
392
393
return ch;
393
394
}
394
395
virtual void unget () {
396
+ unget_internal (lastCh);
397
+ }
398
+ virtual bool good () {
399
+ return lastStatus != EOF;
400
+ }
401
+
402
+ private:
403
+ void unget_internal (int ch) {
395
404
if (isUtf16) {
396
405
// TODO: use ungetc() as well
397
406
// UTF-16 has subsequent unget() calls
398
407
fseek (file, -1 , SEEK_CUR);
399
408
}
400
409
else
401
- ungetc (lastCh, file);
402
-
403
- }
404
- virtual bool good () {
405
- return lastCh != EOF;
410
+ ungetc (ch, file);
406
411
}
407
412
408
- private:
409
413
FILE *file;
410
414
int lastCh;
415
+ int lastStatus;
411
416
};
412
417
413
418
simplecpp::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