Skip to content

Commit c76a3fa

Browse files
committed
added StdCharBufStream which reads from a buffer
1 parent ad9b49d commit c76a3fa

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

simplecpp.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,40 @@ 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(-1)
387+
{
388+
init();
389+
}
390+
391+
virtual int get() OVERRIDE {
392+
if (pos >= size)
393+
return EOF;
394+
return str[++pos];
395+
}
396+
virtual int peek() OVERRIDE {
397+
if ((pos+1) >= size)
398+
return EOF;
399+
return str[pos+1];
400+
}
401+
virtual void unget() OVERRIDE {
402+
--pos;
403+
}
404+
virtual bool good() OVERRIDE {
405+
return pos < size;
406+
}
407+
408+
private:
409+
const unsigned char *str;
410+
const int size;
411+
int pos;
412+
};
413+
380414
class FileStream : public simplecpp::TokenList::Stream {
381415
public:
382416
// cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members

0 commit comments

Comments
 (0)