@@ -351,121 +351,123 @@ class simplecpp::TokenList::Stream {
351351 bool isUtf16;
352352};
353353
354- class StdIStream : public simplecpp ::TokenList::Stream {
355- public:
356- // cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
357- explicit StdIStream (std::istream &istr)
358- : istr(istr) {
359- assert (istr.good ());
360- init ();
361- }
354+ namespace {
355+ class StdIStream : public simplecpp ::TokenList::Stream {
356+ public:
357+ // cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
358+ explicit StdIStream (std::istream &istr)
359+ : istr(istr) {
360+ assert (istr.good ());
361+ init ();
362+ }
362363
363- int get () override {
364- return istr.get ();
365- }
366- int peek () override {
367- return istr.peek ();
368- }
369- void unget () override {
370- istr.unget ();
371- }
372- bool good () override {
373- return istr.good ();
374- }
364+ int get () override {
365+ return istr.get ();
366+ }
367+ int peek () override {
368+ return istr.peek ();
369+ }
370+ void unget () override {
371+ istr.unget ();
372+ }
373+ bool good () override {
374+ return istr.good ();
375+ }
375376
376- private:
377- std::istream &istr;
378- };
377+ private:
378+ std::istream &istr;
379+ };
379380
380- class StdCharBufStream : public simplecpp ::TokenList::Stream {
381- public:
382- // cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
383- StdCharBufStream (const unsigned char * str, std::size_t size)
384- : str(str)
385- , size(size)
386- {
387- init ();
388- }
381+ class StdCharBufStream : public simplecpp ::TokenList::Stream {
382+ public:
383+ // cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
384+ StdCharBufStream (const unsigned char * str, std::size_t size)
385+ : str(str)
386+ , size(size)
387+ {
388+ init ();
389+ }
389390
390- int get () override {
391- if (pos >= size)
392- return lastStatus = EOF;
393- return str[pos++];
394- }
395- int peek () override {
396- if (pos >= size)
397- return lastStatus = EOF;
398- return str[pos];
399- }
400- void unget () override {
401- --pos;
402- }
403- bool good () override {
404- return lastStatus != EOF;
405- }
391+ int get () override {
392+ if (pos >= size)
393+ return lastStatus = EOF;
394+ return str[pos++];
395+ }
396+ int peek () override {
397+ if (pos >= size)
398+ return lastStatus = EOF;
399+ return str[pos];
400+ }
401+ void unget () override {
402+ --pos;
403+ }
404+ bool good () override {
405+ return lastStatus != EOF;
406+ }
406407
407- private:
408- const unsigned char *str;
409- const std::size_t size;
410- std::size_t pos{};
411- int lastStatus{};
412- };
408+ private:
409+ const unsigned char *str;
410+ const std::size_t size;
411+ std::size_t pos{};
412+ int lastStatus{};
413+ };
413414
414- class FileStream : public simplecpp ::TokenList::Stream {
415- public:
416- /* *
417- * @throws simplecpp::Output thrown if file is not found
418- */
419- // cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
420- explicit FileStream (const std::string &filename, std::vector<std::string> &files)
421- : file(fopen(filename.c_str(), "rb"))
422- {
423- if (!file) {
424- files.push_back (filename);
425- throw simplecpp::Output (simplecpp::Output::FILE_NOT_FOUND, {}, " File is missing: " + filename);
415+ class FileStream : public simplecpp ::TokenList::Stream {
416+ public:
417+ /* *
418+ * @throws simplecpp::Output thrown if file is not found
419+ */
420+ // cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
421+ explicit FileStream (const std::string &filename, std::vector<std::string> &files)
422+ : file(fopen(filename.c_str(), "rb"))
423+ {
424+ if (!file) {
425+ files.push_back (filename);
426+ throw simplecpp::Output (simplecpp::Output::FILE_NOT_FOUND, {}, " File is missing: " + filename);
427+ }
428+ init ();
426429 }
427- init ();
428- }
429430
430- FileStream (const FileStream&) = delete ;
431- FileStream &operator =(const FileStream&) = delete ;
431+ FileStream (const FileStream&) = delete ;
432+ FileStream &operator =(const FileStream&) = delete ;
432433
433- ~FileStream () override {
434- fclose (file);
435- file = nullptr ;
436- }
434+ ~FileStream () override {
435+ fclose (file);
436+ file = nullptr ;
437+ }
437438
438- int get () override {
439- lastStatus = lastCh = fgetc (file);
440- return lastCh;
441- }
442- int peek () override {
443- // keep lastCh intact
444- const int ch = fgetc (file);
445- unget_internal (ch);
446- return ch;
447- }
448- void unget () override {
449- unget_internal (lastCh);
450- }
451- bool good () override {
452- return lastStatus != EOF;
453- }
439+ int get () override {
440+ lastStatus = lastCh = fgetc (file);
441+ return lastCh;
442+ }
443+ int peek () override {
444+ // keep lastCh intact
445+ const int ch = fgetc (file);
446+ unget_internal (ch);
447+ return ch;
448+ }
449+ void unget () override {
450+ unget_internal (lastCh);
451+ }
452+ bool good () override {
453+ return lastStatus != EOF;
454+ }
454455
455- private:
456- void unget_internal (int ch) {
457- if (isUtf16) {
458- // TODO: use ungetc() as well
459- // UTF-16 has subsequent unget() calls
460- fseek (file, -1 , SEEK_CUR);
461- } else
462- ungetc (ch, file);
463- }
456+ private:
457+ void unget_internal (int ch) {
458+ if (isUtf16) {
459+ // TODO: use ungetc() as well
460+ // UTF-16 has subsequent unget() calls
461+ fseek (file, -1 , SEEK_CUR);
462+ } else
463+ ungetc (ch, file);
464+ }
464465
465- FILE *file;
466- int lastCh{};
467- int lastStatus{};
468- };
466+ FILE *file;
467+ int lastCh{};
468+ int lastStatus{};
469+ };
470+ }
469471
470472simplecpp::TokenList::TokenList (std::vector<std::string> &filenames) : frontToken(nullptr ), backToken(nullptr ), files(filenames) {}
471473
0 commit comments