@@ -411,6 +411,40 @@ class StdStringStream : public simplecpp::TokenList::Stream {
411411 int pos;
412412};
413413
414+ class StdCharBufStream : public simplecpp ::TokenList::Stream {
415+ public:
416+ // cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
417+ EXPLICIT StdCharBufStream (const char * str, int size)
418+ : str(str)
419+ , size(size)
420+ , pos(-1 )
421+ {
422+ init ();
423+ }
424+
425+ virtual int get () OVERRIDE {
426+ if (pos >= size)
427+ return EOF;
428+ return str[++pos];
429+ }
430+ virtual int peek () OVERRIDE {
431+ if ((pos+1 ) >= size)
432+ return EOF;
433+ return str[pos+1 ];
434+ }
435+ virtual void unget () OVERRIDE {
436+ --pos;
437+ }
438+ virtual bool good () OVERRIDE {
439+ return pos < size;
440+ }
441+
442+ private:
443+ const char *str;
444+ const int size;
445+ int pos;
446+ };
447+
414448class FileStream : public simplecpp ::TokenList::Stream {
415449public:
416450 // cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
@@ -483,6 +517,13 @@ simplecpp::TokenList::TokenList(const std::string &str, std::vector<std::string>
483517 readfile (stream,filename,outputList);
484518}
485519
520+ simplecpp::TokenList::TokenList (const char * str, int size, std::vector<std::string> &filenames, const std::string &filename, OutputList *outputList)
521+ : frontToken(nullptr ), backToken(nullptr ), files(filenames)
522+ {
523+ StdCharBufStream stream (str, size);
524+ readfile (stream,filename,outputList);
525+ }
526+
486527simplecpp::TokenList::TokenList (const std::string &filename, std::vector<std::string> &filenames, OutputList *outputList)
487528 : frontToken(nullptr ), backToken(nullptr ), files(filenames)
488529{
0 commit comments