Skip to content

Commit 1696577

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

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

simplecpp.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
380416
class FileStream : public simplecpp::TokenList::Stream {
381417
public:
382418
// cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members

0 commit comments

Comments
 (0)