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