@@ -377,6 +377,42 @@ class StdIStream : public simplecpp::TokenList::Stream {
377377 std::istream &istr;
378378};
379379
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+ , pos(0 )
387+ , lastStatus(0 )
388+ {
389+ init ();
390+ }
391+
392+ virtual int get () OVERRIDE {
393+ if (pos >= size)
394+ return lastStatus = EOF;
395+ return str[pos++];
396+ }
397+ virtual int peek () OVERRIDE {
398+ if (pos >= size)
399+ return lastStatus = EOF;
400+ return str[pos];
401+ }
402+ virtual void unget () OVERRIDE {
403+ --pos;
404+ }
405+ virtual bool good () OVERRIDE {
406+ return lastStatus != EOF;
407+ }
408+
409+ private:
410+ const unsigned char *str;
411+ const std::size_t size;
412+ std::size_t pos;
413+ int lastStatus;
414+ };
415+
380416class FileStream : public simplecpp ::TokenList::Stream {
381417public:
382418 // cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
@@ -442,6 +478,20 @@ simplecpp::TokenList::TokenList(std::istream &istr, std::vector<std::string> &fi
442478 readfile (stream,filename,outputList);
443479}
444480
481+ simplecpp::TokenList::TokenList (const unsigned char * data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename, OutputList *outputList)
482+ : frontToken(nullptr ), backToken(nullptr ), files(filenames)
483+ {
484+ StdCharBufStream stream (data, size);
485+ readfile (stream,filename,outputList);
486+ }
487+
488+ simplecpp::TokenList::TokenList (const char * data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename, OutputList *outputList)
489+ : frontToken(nullptr ), backToken(nullptr ), files(filenames)
490+ {
491+ StdCharBufStream stream (reinterpret_cast <const unsigned char *>(data), size);
492+ readfile (stream,filename,outputList);
493+ }
494+
445495simplecpp::TokenList::TokenList (const std::string &filename, std::vector<std::string> &filenames, OutputList *outputList)
446496 : frontToken(nullptr ), backToken(nullptr ), files(filenames)
447497{
@@ -1447,8 +1497,7 @@ namespace simplecpp {
14471497
14481498 Macro (const std::string &name, const std::string &value, std::vector<std::string> &f) : nameTokDef(nullptr ), files(f), tokenListDefine(f), valueDefinedInCode_(false ) {
14491499 const std::string def (name + ' ' + value);
1450- std::istringstream istr (def);
1451- StdIStream stream (istr);
1500+ StdCharBufStream stream (reinterpret_cast <const unsigned char *>(def.data ()), def.size ());
14521501 tokenListDefine.readfile (stream);
14531502 if (!parseDefine (tokenListDefine.cfront ()))
14541503 throw std::runtime_error (" bad macro syntax. macroname=" + name + " value=" + value);
0 commit comments